sqrt( {expr}) Float square root of {expr}
str2float( {expr}) Float convert String to Float
str2nr( {expr} [, {base}]) Number convert String to Number
-strchars( {expr}) Number character length of the String {expr}
+strchars( {expr} [, {skipcc}]) Number character length of the String {expr}
strdisplaywidth( {expr} [, {col}]) Number display length of the String {expr}
strftime( {format}[, {time}]) String time in specified format
stridx( {haystack}, {needle}[, {start}])
*strlen()*
strlen({expr}) The result is a Number, which is the length of the String
{expr} in bytes.
- If you want to count the number of multi-byte characters (not
- counting composing characters) use something like this: >
-
- :let len = strlen(substitute(str, ".", "x", "g"))
-<
If the argument is a Number it is first converted to a String.
For other types an error is given.
- Also see |len()|, |strchars()|, |strdisplaywidth()| and
- |strwidth()|.
+ If you want to count the number of multi-byte characters use
+ |strchars()|.
+ Also see |len()|, |strdisplaywidth()| and |strwidth()|.
strpart({src}, {start}[, {len}]) *strpart()*
The result is a String, which is part of {src}, starting from
/* (un)lock a List item. */
item_lock(&lp->ll_li->li_tv, deep, lock);
else
- /* un(lock) a Dictionary item. */
+ /* (un)lock a Dictionary item. */
item_lock(&lp->ll_di->di_tv, deep, lock);
return ret;
{"str2float", 1, 1, f_str2float},
#endif
{"str2nr", 1, 2, f_str2nr},
- {"strchars", 1, 1, f_strchars},
+ {"strchars", 1, 2, f_strchars},
{"strdisplaywidth", 1, 2, f_strdisplaywidth},
#ifdef HAVE_STRFTIME
{"strftime", 1, 2, f_strftime},
typval_T *rettv;
{
char_u *s = get_tv_string(&argvars[0]);
+ int skipcc = 0;
#ifdef FEAT_MBYTE
varnumber_T len = 0;
+ int (*func_mb_ptr2char_adv)(char_u **pp);
+#endif
- while (*s != NUL)
+ if (argvars[1].v_type != VAR_UNKNOWN)
+ skipcc = get_tv_number_chk(&argvars[1], NULL);
+ if (skipcc < 0 || skipcc > 1)
+ EMSG(_(e_invarg));
+ else
{
- mb_cptr2char_adv(&s);
- ++len;
- }
- rettv->vval.v_number = len;
+#ifdef FEAT_MBYTE
+ 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;
#else
- rettv->vval.v_number = (varnumber_T)(STRLEN(s));
+ rettv->vval.v_number = (varnumber_T)(STRLEN(s));
#endif
+ }
}
/*