Mercurial > vim
diff src/vim9execute.c @ 21823:b1f3d8a44ab6 v8.2.1461
patch 8.2.1461: Vim9: string indexes are counted in bytes
Commit: https://github.com/vim/vim/commit/e3c37d8ebf9dbbf210fde4a5fb28eb1f2a492a34
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 15 18:39:05 2020 +0200
patch 8.2.1461: Vim9: string indexes are counted in bytes
Problem: Vim9: string indexes are counted in bytes.
Solution: Use character indexes. (closes https://github.com/vim/vim/issues/6574)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Aug 2020 18:45:04 +0200 |
parents | 0deb6f96a5a3 |
children | ccad66ac6c3e |
line wrap: on
line diff
--- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2233,7 +2233,6 @@ call_def_function( case ISN_STRINDEX: { - char_u *s; varnumber_T n; char_u *res; @@ -2245,7 +2244,6 @@ call_def_function( emsg(_(e_stringreq)); goto on_error; } - s = tv->vval.v_string; tv = STACK_TV_BOT(-1); if (tv->v_type != VAR_NUMBER) @@ -2259,12 +2257,9 @@ call_def_function( // The resulting variable is a string of a single // character. If the index is too big or negative the // result is empty. - if (n < 0 || n >= (varnumber_T)STRLEN(s)) - res = NULL; - else - res = vim_strnsave(s + n, 1); --ectx.ec_stack.ga_len; tv = STACK_TV_BOT(-1); + res = char_from_string(tv->vval.v_string, n); vim_free(tv->vval.v_string); tv->vval.v_string = res; }