diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-03-14 19:46:45 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-03-14 19:46:45 +0100 |
commit | 02b4d9b18a03549b68e364e428392b7a62766c74 (patch) | |
tree | e017eaa4d4531b7bccb612679b50848c94d9e5b3 /src/evalfunc.c | |
parent | 70ce8a1561c5396e4c4381f76a005cbb97646f80 (diff) |
patch 8.2.2607: strcharpart() cannot include composing charactersv8.2.2607
Problem: strcharpart() cannot include composing characters.
Solution: Add the {skipcc} argument.
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r-- | src/evalfunc.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 34369d77ad..8fcdedbc00 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -1575,7 +1575,7 @@ static funcentry_T global_functions[] = ret_number, f_str2nr}, {"strcharlen", 1, 1, FEARG_1, NULL, ret_number, f_strcharlen}, - {"strcharpart", 2, 3, FEARG_1, NULL, + {"strcharpart", 2, 4, FEARG_1, NULL, ret_string, f_strcharpart}, {"strchars", 1, 2, FEARG_1, NULL, ret_number, f_strchars}, @@ -9316,6 +9316,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv) int nchar; int nbyte = 0; int charlen; + int skipcc = FALSE; int len = 0; int slen; int error = FALSE; @@ -9326,10 +9327,24 @@ f_strcharpart(typval_T *argvars, typval_T *rettv) nchar = (int)tv_get_number_chk(&argvars[1], &error); if (!error) { + if (argvars[2].v_type != VAR_UNKNOWN + && argvars[3].v_type != VAR_UNKNOWN) + { + skipcc = tv_get_bool(&argvars[3]); + if (skipcc < 0 || skipcc > 1) + { + semsg(_(e_using_number_as_bool_nr), skipcc); + return; + } + } + if (nchar > 0) while (nchar > 0 && nbyte < slen) { - nbyte += MB_CPTR2LEN(p + nbyte); + if (skipcc) + nbyte += mb_ptr2len(p + nbyte); + else + nbyte += MB_CPTR2LEN(p + nbyte); --nchar; } else @@ -9344,7 +9359,12 @@ f_strcharpart(typval_T *argvars, typval_T *rettv) if (off < 0) len += 1; else - len += MB_CPTR2LEN(p + off); + { + if (skipcc) + len += mb_ptr2len(p + off); + else + len += MB_CPTR2LEN(p + off); + } --charlen; } } |