mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
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)
This commit is contained in:
parent
3a304b2382
commit
641e48c224
@ -1985,7 +1985,7 @@ split( {expr} [, {pat} [, {keepempty}]])
|
|||||||
sqrt( {expr}) Float square root of {expr}
|
sqrt( {expr}) Float square root of {expr}
|
||||||
str2float( {expr}) Float convert String to Float
|
str2float( {expr}) Float convert String to Float
|
||||||
str2nr( {expr} [, {base}]) Number convert String to Number
|
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}
|
strdisplaywidth( {expr} [, {col}]) Number display length of the String {expr}
|
||||||
strftime( {format}[, {time}]) String time in specified format
|
strftime( {format}[, {time}]) String time in specified format
|
||||||
stridx( {haystack}, {needle}[, {start}])
|
stridx( {haystack}, {needle}[, {start}])
|
||||||
@ -5913,15 +5913,11 @@ string({expr}) Return {expr} converted to a String. If {expr} is a Number,
|
|||||||
*strlen()*
|
*strlen()*
|
||||||
strlen({expr}) The result is a Number, which is the length of the String
|
strlen({expr}) The result is a Number, which is the length of the String
|
||||||
{expr} in bytes.
|
{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.
|
If the argument is a Number it is first converted to a String.
|
||||||
For other types an error is given.
|
For other types an error is given.
|
||||||
Also see |len()|, |strchars()|, |strdisplaywidth()| and
|
If you want to count the number of multi-byte characters use
|
||||||
|strwidth()|.
|
|strchars()|.
|
||||||
|
Also see |len()|, |strdisplaywidth()| and |strwidth()|.
|
||||||
|
|
||||||
strpart({src}, {start}[, {len}]) *strpart()*
|
strpart({src}, {start}[, {len}]) *strpart()*
|
||||||
The result is a String, which is part of {src}, starting from
|
The result is a String, which is part of {src}, starting from
|
||||||
|
34
src/eval.c
34
src/eval.c
@ -3810,7 +3810,7 @@ do_lock_var(lp, name_end, deep, lock)
|
|||||||
/* (un)lock a List item. */
|
/* (un)lock a List item. */
|
||||||
item_lock(&lp->ll_li->li_tv, deep, lock);
|
item_lock(&lp->ll_li->li_tv, deep, lock);
|
||||||
else
|
else
|
||||||
/* un(lock) a Dictionary item. */
|
/* (un)lock a Dictionary item. */
|
||||||
item_lock(&lp->ll_di->di_tv, deep, lock);
|
item_lock(&lp->ll_di->di_tv, deep, lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -8309,7 +8309,7 @@ static struct fst
|
|||||||
{"str2float", 1, 1, f_str2float},
|
{"str2float", 1, 1, f_str2float},
|
||||||
#endif
|
#endif
|
||||||
{"str2nr", 1, 2, f_str2nr},
|
{"str2nr", 1, 2, f_str2nr},
|
||||||
{"strchars", 1, 1, f_strchars},
|
{"strchars", 1, 2, f_strchars},
|
||||||
{"strdisplaywidth", 1, 2, f_strdisplaywidth},
|
{"strdisplaywidth", 1, 2, f_strdisplaywidth},
|
||||||
#ifdef HAVE_STRFTIME
|
#ifdef HAVE_STRFTIME
|
||||||
{"strftime", 1, 2, f_strftime},
|
{"strftime", 1, 2, f_strftime},
|
||||||
@ -18372,18 +18372,30 @@ f_strchars(argvars, rettv)
|
|||||||
typval_T *rettv;
|
typval_T *rettv;
|
||||||
{
|
{
|
||||||
char_u *s = get_tv_string(&argvars[0]);
|
char_u *s = get_tv_string(&argvars[0]);
|
||||||
|
int skipcc = 0;
|
||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
varnumber_T len = 0;
|
varnumber_T len = 0;
|
||||||
|
int (*func_mb_ptr2char_adv)(char_u **pp);
|
||||||
while (*s != NUL)
|
|
||||||
{
|
|
||||||
mb_cptr2char_adv(&s);
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
rettv->vval.v_number = len;
|
|
||||||
#else
|
|
||||||
rettv->vval.v_number = (varnumber_T)(STRLEN(s));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (argvars[1].v_type != VAR_UNKNOWN)
|
||||||
|
skipcc = get_tv_number_chk(&argvars[1], NULL);
|
||||||
|
if (skipcc < 0 || skipcc > 1)
|
||||||
|
EMSG(_(e_invarg));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#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));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -11,6 +11,12 @@ STARTTEST
|
|||||||
:
|
:
|
||||||
:bwipeout!
|
:bwipeout!
|
||||||
:$put=r
|
:$put=r
|
||||||
|
:" Test for built-in function strchars()
|
||||||
|
:for str in ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
|
||||||
|
: $put=strchars(str)
|
||||||
|
: $put=strchars(str, 0)
|
||||||
|
: $put=strchars(str, 1)
|
||||||
|
:endfor
|
||||||
:call garbagecollect(1)
|
:call garbagecollect(1)
|
||||||
:/^start:/,$wq! test.out
|
:/^start:/,$wq! test.out
|
||||||
ENDTEST
|
ENDTEST
|
||||||
|
@ -2,3 +2,18 @@ start:
|
|||||||
axaa
|
axaa
|
||||||
xあああ
|
xあああ
|
||||||
bxbb
|
bxbb
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
3
|
||||||
|
3
|
||||||
|
3
|
||||||
|
2
|
||||||
|
2
|
||||||
|
1
|
||||||
|
3
|
||||||
|
3
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
@ -741,6 +741,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
755,
|
||||||
/**/
|
/**/
|
||||||
754,
|
754,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user