|
Karsten Hopp |
67b4e0 |
To: vim_dev@googlegroups.com
|
|
Karsten Hopp |
67b4e0 |
Subject: Patch 7.4.755
|
|
Karsten Hopp |
67b4e0 |
Fcc: outbox
|
|
Karsten Hopp |
67b4e0 |
From: Bram Moolenaar <Bram@moolenaar.net>
|
|
Karsten Hopp |
67b4e0 |
Mime-Version: 1.0
|
|
Karsten Hopp |
67b4e0 |
Content-Type: text/plain; charset=UTF-8
|
|
Karsten Hopp |
67b4e0 |
Content-Transfer-Encoding: 8bit
|
|
Karsten Hopp |
67b4e0 |
------------
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
Patch 7.4.755
|
|
Karsten Hopp |
67b4e0 |
Problem: It is not easy to count the number of characters.
|
|
Karsten Hopp |
67b4e0 |
Solution: Add the skipcc argument to strchars(). (Hirohito Higashi, Ken
|
|
Karsten Hopp |
67b4e0 |
Takata)
|
|
Karsten Hopp |
67b4e0 |
Files: runtime/doc/eval.txt, src/eval.c, src/testdir/test_utf8.in,
|
|
Karsten Hopp |
67b4e0 |
src/testdir/test_utf8.ok
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
*** ../vim-7.4.754/runtime/doc/eval.txt 2015-03-20 17:36:38.618949214 +0100
|
|
Karsten Hopp |
67b4e0 |
--- runtime/doc/eval.txt 2015-06-25 15:59:53.104434430 +0200
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 1984,1990 ****
|
|
Karsten Hopp |
67b4e0 |
sqrt( {expr}) Float square root of {expr}
|
|
Karsten Hopp |
67b4e0 |
str2float( {expr}) Float convert String to Float
|
|
Karsten Hopp |
67b4e0 |
str2nr( {expr} [, {base}]) Number convert String to Number
|
|
Karsten Hopp |
67b4e0 |
! strchars( {expr}) Number character length of the String {expr}
|
|
Karsten Hopp |
67b4e0 |
strdisplaywidth( {expr} [, {col}]) Number display length of the String {expr}
|
|
Karsten Hopp |
67b4e0 |
strftime( {format}[, {time}]) String time in specified format
|
|
Karsten Hopp |
67b4e0 |
stridx( {haystack}, {needle}[, {start}])
|
|
Karsten Hopp |
67b4e0 |
--- 1985,1991 ----
|
|
Karsten Hopp |
67b4e0 |
sqrt( {expr}) Float square root of {expr}
|
|
Karsten Hopp |
67b4e0 |
str2float( {expr}) Float convert String to Float
|
|
Karsten Hopp |
67b4e0 |
str2nr( {expr} [, {base}]) Number convert String to Number
|
|
Karsten Hopp |
67b4e0 |
! strchars( {expr} [, {skipcc}]) Number character length of the String {expr}
|
|
Karsten Hopp |
67b4e0 |
strdisplaywidth( {expr} [, {col}]) Number display length of the String {expr}
|
|
Karsten Hopp |
67b4e0 |
strftime( {format}[, {time}]) String time in specified format
|
|
Karsten Hopp |
67b4e0 |
stridx( {haystack}, {needle}[, {start}])
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 5792,5806 ****
|
|
Karsten Hopp |
67b4e0 |
Text after the number is silently ignored.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
! strchars({expr}) *strchars()*
|
|
Karsten Hopp |
67b4e0 |
The result is a Number, which is the number of characters
|
|
Karsten Hopp |
67b4e0 |
! String {expr} occupies. Composing characters are counted
|
|
Karsten Hopp |
67b4e0 |
! separately.
|
|
Karsten Hopp |
67b4e0 |
Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
strdisplaywidth({expr}[, {col}]) *strdisplaywidth()*
|
|
Karsten Hopp |
67b4e0 |
The result is a Number, which is the number of display cells
|
|
Karsten Hopp |
67b4e0 |
! String {expr} occupies on the screen.
|
|
Karsten Hopp |
67b4e0 |
When {col} is omitted zero is used. Otherwise it is the
|
|
Karsten Hopp |
67b4e0 |
screen column where to start. This matters for Tab
|
|
Karsten Hopp |
67b4e0 |
characters.
|
|
Karsten Hopp |
67b4e0 |
--- 5839,5855 ----
|
|
Karsten Hopp |
67b4e0 |
Text after the number is silently ignored.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
! strchars({expr} [, {skipcc}]) *strchars()*
|
|
Karsten Hopp |
67b4e0 |
The result is a Number, which is the number of characters
|
|
Karsten Hopp |
67b4e0 |
! in String {expr}.
|
|
Karsten Hopp |
67b4e0 |
! When {skipcc} is omitted or zero, composing characters are
|
|
Karsten Hopp |
67b4e0 |
! counted separately.
|
|
Karsten Hopp |
67b4e0 |
! When {skipcc} set to 1, Composing characters are ignored.
|
|
Karsten Hopp |
67b4e0 |
Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
strdisplaywidth({expr}[, {col}]) *strdisplaywidth()*
|
|
Karsten Hopp |
67b4e0 |
The result is a Number, which is the number of display cells
|
|
Karsten Hopp |
67b4e0 |
! String {expr} occupies on the screen when it starts a {col}.
|
|
Karsten Hopp |
67b4e0 |
When {col} is omitted zero is used. Otherwise it is the
|
|
Karsten Hopp |
67b4e0 |
screen column where to start. This matters for Tab
|
|
Karsten Hopp |
67b4e0 |
characters.
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 5866,5880 ****
|
|
Karsten Hopp |
67b4e0 |
*strlen()*
|
|
Karsten Hopp |
67b4e0 |
strlen({expr}) The result is a Number, which is the length of the String
|
|
Karsten Hopp |
67b4e0 |
{expr} in bytes.
|
|
Karsten Hopp |
67b4e0 |
- If you want to count the number of multi-byte characters (not
|
|
Karsten Hopp |
67b4e0 |
- counting composing characters) use something like this: >
|
|
Karsten Hopp |
67b4e0 |
-
|
|
Karsten Hopp |
67b4e0 |
- :let len = strlen(substitute(str, ".", "x", "g"))
|
|
Karsten Hopp |
67b4e0 |
- <
|
|
Karsten Hopp |
67b4e0 |
If the argument is a Number it is first converted to a String.
|
|
Karsten Hopp |
67b4e0 |
For other types an error is given.
|
|
Karsten Hopp |
67b4e0 |
! Also see |len()|, |strchars()|, |strdisplaywidth()| and
|
|
Karsten Hopp |
67b4e0 |
! |strwidth()|.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
strpart({src}, {start}[, {len}]) *strpart()*
|
|
Karsten Hopp |
67b4e0 |
The result is a String, which is part of {src}, starting from
|
|
Karsten Hopp |
67b4e0 |
--- 5915,5925 ----
|
|
Karsten Hopp |
67b4e0 |
*strlen()*
|
|
Karsten Hopp |
67b4e0 |
strlen({expr}) The result is a Number, which is the length of the String
|
|
Karsten Hopp |
67b4e0 |
{expr} in bytes.
|
|
Karsten Hopp |
67b4e0 |
If the argument is a Number it is first converted to a String.
|
|
Karsten Hopp |
67b4e0 |
For other types an error is given.
|
|
Karsten Hopp |
67b4e0 |
! If you want to count the number of multi-byte characters use
|
|
Karsten Hopp |
67b4e0 |
! |strchars()|.
|
|
Karsten Hopp |
67b4e0 |
! Also see |len()|, |strdisplaywidth()| and |strwidth()|.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
strpart({src}, {start}[, {len}]) *strpart()*
|
|
Karsten Hopp |
67b4e0 |
The result is a String, which is part of {src}, starting from
|
|
Karsten Hopp |
67b4e0 |
*** ../vim-7.4.754/src/eval.c 2015-06-19 21:06:04.664521324 +0200
|
|
Karsten Hopp |
67b4e0 |
--- src/eval.c 2015-06-25 15:53:55.992189567 +0200
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 3810,3816 ****
|
|
Karsten Hopp |
67b4e0 |
/* (un)lock a List item. */
|
|
Karsten Hopp |
67b4e0 |
item_lock(&lp->ll_li->li_tv, deep, lock);
|
|
Karsten Hopp |
67b4e0 |
else
|
|
Karsten Hopp |
67b4e0 |
! /* un(lock) a Dictionary item. */
|
|
Karsten Hopp |
67b4e0 |
item_lock(&lp->ll_di->di_tv, deep, lock);
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
return ret;
|
|
Karsten Hopp |
67b4e0 |
--- 3810,3816 ----
|
|
Karsten Hopp |
67b4e0 |
/* (un)lock a List item. */
|
|
Karsten Hopp |
67b4e0 |
item_lock(&lp->ll_li->li_tv, deep, lock);
|
|
Karsten Hopp |
67b4e0 |
else
|
|
Karsten Hopp |
67b4e0 |
! /* (un)lock a Dictionary item. */
|
|
Karsten Hopp |
67b4e0 |
item_lock(&lp->ll_di->di_tv, deep, lock);
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
return ret;
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 8309,8315 ****
|
|
Karsten Hopp |
67b4e0 |
{"str2float", 1, 1, f_str2float},
|
|
Karsten Hopp |
67b4e0 |
#endif
|
|
Karsten Hopp |
67b4e0 |
{"str2nr", 1, 2, f_str2nr},
|
|
Karsten Hopp |
67b4e0 |
! {"strchars", 1, 1, f_strchars},
|
|
Karsten Hopp |
67b4e0 |
{"strdisplaywidth", 1, 2, f_strdisplaywidth},
|
|
Karsten Hopp |
67b4e0 |
#ifdef HAVE_STRFTIME
|
|
Karsten Hopp |
67b4e0 |
{"strftime", 1, 2, f_strftime},
|
|
Karsten Hopp |
67b4e0 |
--- 8309,8315 ----
|
|
Karsten Hopp |
67b4e0 |
{"str2float", 1, 1, f_str2float},
|
|
Karsten Hopp |
67b4e0 |
#endif
|
|
Karsten Hopp |
67b4e0 |
{"str2nr", 1, 2, f_str2nr},
|
|
Karsten Hopp |
67b4e0 |
! {"strchars", 1, 2, f_strchars},
|
|
Karsten Hopp |
67b4e0 |
{"strdisplaywidth", 1, 2, f_strdisplaywidth},
|
|
Karsten Hopp |
67b4e0 |
#ifdef HAVE_STRFTIME
|
|
Karsten Hopp |
67b4e0 |
{"strftime", 1, 2, f_strftime},
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 18372,18389 ****
|
|
Karsten Hopp |
67b4e0 |
typval_T *rettv;
|
|
Karsten Hopp |
67b4e0 |
{
|
|
Karsten Hopp |
67b4e0 |
char_u *s = get_tv_string(&argvars[0]);
|
|
Karsten Hopp |
67b4e0 |
#ifdef FEAT_MBYTE
|
|
Karsten Hopp |
67b4e0 |
varnumber_T len = 0;
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
! while (*s != NUL)
|
|
Karsten Hopp |
67b4e0 |
{
|
|
Karsten Hopp |
67b4e0 |
! mb_cptr2char_adv(&s);
|
|
Karsten Hopp |
67b4e0 |
! ++len;
|
|
Karsten Hopp |
67b4e0 |
! }
|
|
Karsten Hopp |
67b4e0 |
! rettv->vval.v_number = len;
|
|
Karsten Hopp |
67b4e0 |
#else
|
|
Karsten Hopp |
67b4e0 |
! rettv->vval.v_number = (varnumber_T)(STRLEN(s));
|
|
Karsten Hopp |
67b4e0 |
#endif
|
|
Karsten Hopp |
67b4e0 |
}
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
/*
|
|
Karsten Hopp |
67b4e0 |
--- 18372,18401 ----
|
|
Karsten Hopp |
67b4e0 |
typval_T *rettv;
|
|
Karsten Hopp |
67b4e0 |
{
|
|
Karsten Hopp |
67b4e0 |
char_u *s = get_tv_string(&argvars[0]);
|
|
Karsten Hopp |
67b4e0 |
+ int skipcc = 0;
|
|
Karsten Hopp |
67b4e0 |
#ifdef FEAT_MBYTE
|
|
Karsten Hopp |
67b4e0 |
varnumber_T len = 0;
|
|
Karsten Hopp |
67b4e0 |
+ int (*func_mb_ptr2char_adv)(char_u **pp);
|
|
Karsten Hopp |
67b4e0 |
+ #endif
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
! if (argvars[1].v_type != VAR_UNKNOWN)
|
|
Karsten Hopp |
67b4e0 |
! skipcc = get_tv_number_chk(&argvars[1], NULL);
|
|
Karsten Hopp |
67b4e0 |
! if (skipcc < 0 || skipcc > 1)
|
|
Karsten Hopp |
67b4e0 |
! EMSG(_(e_invarg));
|
|
Karsten Hopp |
67b4e0 |
! else
|
|
Karsten Hopp |
67b4e0 |
{
|
|
Karsten Hopp |
67b4e0 |
! #ifdef FEAT_MBYTE
|
|
Karsten Hopp |
67b4e0 |
! func_mb_ptr2char_adv = skipcc ? mb_ptr2char_adv : mb_cptr2char_adv;
|
|
Karsten Hopp |
67b4e0 |
! while (*s != NUL)
|
|
Karsten Hopp |
67b4e0 |
! {
|
|
Karsten Hopp |
67b4e0 |
! func_mb_ptr2char_adv(&s);
|
|
Karsten Hopp |
67b4e0 |
! ++len;
|
|
Karsten Hopp |
67b4e0 |
! }
|
|
Karsten Hopp |
67b4e0 |
! rettv->vval.v_number = len;
|
|
Karsten Hopp |
67b4e0 |
#else
|
|
Karsten Hopp |
67b4e0 |
! rettv->vval.v_number = (varnumber_T)(STRLEN(s));
|
|
Karsten Hopp |
67b4e0 |
#endif
|
|
Karsten Hopp |
67b4e0 |
+ }
|
|
Karsten Hopp |
67b4e0 |
}
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
/*
|
|
Karsten Hopp |
67b4e0 |
*** ../vim-7.4.754/src/testdir/test_utf8.in 2014-08-16 18:36:38.593993280 +0200
|
|
Karsten Hopp |
67b4e0 |
--- src/testdir/test_utf8.in 2015-06-25 15:53:55.992189567 +0200
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 11,16 ****
|
|
Karsten Hopp |
67b4e0 |
--- 11,22 ----
|
|
Karsten Hopp |
67b4e0 |
:
|
|
Karsten Hopp |
67b4e0 |
:bwipeout!
|
|
Karsten Hopp |
67b4e0 |
:$put=r
|
|
Karsten Hopp |
67b4e0 |
+ :" Test for built-in function strchars()
|
|
Karsten Hopp |
67b4e0 |
+ :for str in ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
|
|
Karsten Hopp |
67b4e0 |
+ : $put=strchars(str)
|
|
Karsten Hopp |
67b4e0 |
+ : $put=strchars(str, 0)
|
|
Karsten Hopp |
67b4e0 |
+ : $put=strchars(str, 1)
|
|
Karsten Hopp |
67b4e0 |
+ :endfor
|
|
Karsten Hopp |
67b4e0 |
:call garbagecollect(1)
|
|
Karsten Hopp |
67b4e0 |
:/^start:/,$wq! test.out
|
|
Karsten Hopp |
67b4e0 |
ENDTEST
|
|
Karsten Hopp |
67b4e0 |
*** ../vim-7.4.754/src/testdir/test_utf8.ok 2014-08-16 18:36:38.593993280 +0200
|
|
Karsten Hopp |
67b4e0 |
--- src/testdir/test_utf8.ok 2015-06-25 15:53:55.992189567 +0200
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 2,4 ****
|
|
Karsten Hopp |
67b4e0 |
--- 2,19 ----
|
|
Karsten Hopp |
67b4e0 |
axaa
|
|
Karsten Hopp |
67b4e0 |
xあああ
|
|
Karsten Hopp |
67b4e0 |
bxbb
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 3
|
|
Karsten Hopp |
67b4e0 |
+ 3
|
|
Karsten Hopp |
67b4e0 |
+ 3
|
|
Karsten Hopp |
67b4e0 |
+ 2
|
|
Karsten Hopp |
67b4e0 |
+ 2
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 3
|
|
Karsten Hopp |
67b4e0 |
+ 3
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
+ 1
|
|
Karsten Hopp |
67b4e0 |
*** ../vim-7.4.754/src/version.c 2015-06-25 13:57:20.033431073 +0200
|
|
Karsten Hopp |
67b4e0 |
--- src/version.c 2015-06-25 15:55:26.071242187 +0200
|
|
Karsten Hopp |
67b4e0 |
***************
|
|
Karsten Hopp |
67b4e0 |
*** 743,744 ****
|
|
Karsten Hopp |
67b4e0 |
--- 743,746 ----
|
|
Karsten Hopp |
67b4e0 |
{ /* Add new patch number below this line */
|
|
Karsten Hopp |
67b4e0 |
+ /**/
|
|
Karsten Hopp |
67b4e0 |
+ 755,
|
|
Karsten Hopp |
67b4e0 |
/**/
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
--
|
|
Karsten Hopp |
67b4e0 |
hundred-and-one symptoms of being an internet addict:
|
|
Karsten Hopp |
67b4e0 |
145. You e-mail your boss, informing him you'll be late.
|
|
Karsten Hopp |
67b4e0 |
|
|
Karsten Hopp |
67b4e0 |
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
|
|
Karsten Hopp |
67b4e0 |
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
|
|
Karsten Hopp |
67b4e0 |
\\\ an exciting new programming language -- http://www.Zimbu.org ///
|
|
Karsten Hopp |
67b4e0 |
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|