diff options
author | Jurica Bradaric <jbradaric@gmail.com> | 2016-01-30 17:42:22 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-02-09 01:36:29 -0500 |
commit | a9a25fda42abdec267e89bf607f35e60806ec092 (patch) | |
tree | 91ff2f022e3a79ef13886b44c5479ff16a9944ba /src/nvim/eval.c | |
parent | 31aa060bca0084d19eac382408727c5f3b190af3 (diff) | |
download | rneovim-a9a25fda42abdec267e89bf607f35e60806ec092.tar.gz rneovim-a9a25fda42abdec267e89bf607f35e60806ec092.tar.bz2 rneovim-a9a25fda42abdec267e89bf607f35e60806ec092.zip |
vim-patch:7.4.755
Problem: It is not easy to count the number of characters.
Solution: Add the skipcc argument to strchars(). (Hirohito Higashi, Ken
Takata)
https://github.com/vim/vim/commit/641e48c2248ccb3c25a5cdaa3709f16152d8c77d
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a9af7d94c1..969a03fce3 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3045,12 +3045,13 @@ static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock) li = li->li_next; ++lp->ll_n1; } - } else if (lp->ll_list != NULL) - /* (un)lock a List item. */ + } else if (lp->ll_list != NULL) { + // (un)lock a List item. item_lock(&lp->ll_li->li_tv, deep, lock); - else - /* un(lock) a Dictionary item. */ + } else { + // (un)lock a Dictionary item. item_lock(&lp->ll_di->di_tv, deep, lock); + } return ret; } @@ -7337,7 +7338,7 @@ static struct fst { { "sqrt", 1, 1, f_sqrt }, { "str2float", 1, 1, f_str2float }, { "str2nr", 1, 2, f_str2nr }, - { "strchars", 1, 1, f_strchars }, + { "strchars", 1, 2, f_strchars }, { "strdisplaywidth", 1, 2, f_strdisplaywidth }, { "strftime", 1, 2, f_strftime }, { "stridx", 2, 3, f_stridx }, @@ -16213,13 +16214,23 @@ static void f_strlen(typval_T *argvars, typval_T *rettv) static void f_strchars(typval_T *argvars, typval_T *rettv) { char_u *s = get_tv_string(&argvars[0]); + int skipcc = 0; varnumber_T len = 0; + int (*func_mb_ptr2char_adv)(char_u **pp); - while (*s != NUL) { - mb_cptr2char_adv(&s); - ++len; + if (argvars[1].v_type != VAR_UNKNOWN) { + skipcc = get_tv_number_chk(&argvars[1], NULL); + } + if (skipcc < 0 || skipcc > 1) { + EMSG(_(e_invarg)); + } else { + func_mb_ptr2char_adv = skipcc ? mb_ptr2char_adv : mb_cptr2char_adv; + while (*s != NUL) { + func_mb_ptr2char_adv(&s); + ++len; + } + rettv->vval.v_number = len; } - rettv->vval.v_number = len; } /* |