Mercurial > vim
diff src/evalfunc.c @ 32570:5d8cff99a027 v9.0.1617
patch 9.0.1617: charidx() result is not consistent with byteidx()
Commit: https://github.com/vim/vim/commit/577922b917e48285a7a312daf7b5bbc6e272939c
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Jun 8 17:09:45 2023 +0100
patch 9.0.1617: charidx() result is not consistent with byteidx()
Problem: charidx() and utf16idx() result is not consistent with byteidx().
Solution: When the index is equal to the length of the text return the
lenght of the text instead of -1. (Yegappan Lakshmanan,
closes #12503)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Jun 2023 18:15:04 +0200 |
parents | aa64fdad1f60 |
children | 53c85eab46b9 |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -1099,6 +1099,7 @@ static argcheck_T arg3_string_string_num static argcheck_T arg4_number_number_string_any[] = {arg_number, arg_number, arg_string, NULL}; static argcheck_T arg4_string_string_any_string[] = {arg_string, arg_string, NULL, arg_string}; static argcheck_T arg4_string_string_number_string[] = {arg_string, arg_string, arg_number, arg_string}; +static argcheck_T arg4_string_number_bool_bool[] = {arg_string, arg_number, arg_bool, arg_bool}; /* Function specific argument types (not covered by the above) */ static argcheck_T arg15_assert_fails[] = {arg_string_or_nr, arg_string_or_list_any, NULL, arg_number, arg_string}; static argcheck_T arg34_assert_inrange[] = {arg_float_or_nr, arg_float_or_nr, arg_float_or_nr, arg_string}; @@ -1814,7 +1815,7 @@ static funcentry_T global_functions[] = ret_number, f_charclass}, {"charcol", 1, 2, FEARG_1, arg2_string_or_list_number, ret_number, f_charcol}, - {"charidx", 2, 4, FEARG_1, arg3_string_number_bool, + {"charidx", 2, 4, FEARG_1, arg4_string_number_bool_bool, ret_number, f_charidx}, {"chdir", 1, 1, FEARG_1, arg1_string, ret_string, f_chdir}, @@ -2798,7 +2799,7 @@ static funcentry_T global_functions[] = ret_dict_any, f_undotree}, {"uniq", 1, 3, FEARG_1, arg13_sortuniq, ret_first_arg, f_uniq}, - {"utf16idx", 2, 4, FEARG_1, arg3_string_number_bool, + {"utf16idx", 2, 4, FEARG_1, arg4_string_number_bool_bool, ret_number, f_utf16idx}, {"values", 1, 1, FEARG_1, arg1_dict_any, ret_list_member, f_values}, @@ -3630,7 +3631,7 @@ f_copy(typval_T *argvars, typval_T *rett /* * Set the cursor position. - * If 'charcol' is TRUE, then use the column number as a character offset. + * If "charcol" is TRUE, then use the column number as a character offset. * Otherwise use the column number as a byte offset. */ static void