[vim] 99/139: patch 7.4.1782 Problem: strcharpart() does not work properly with some multi-byte characters. Solution: Use mb_cptr2len() instead of mb_char2len(). (Hirohito Higashi)

James McCoy jamessan at debian.org
Fri May 6 04:00:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch debian/sid
in repository vim.

commit fca66003053f8c0da5161d1fe4b75b3a389934b5
Author: Bram Moolenaar <Bram at vim.org>
Date:   Sat Apr 23 15:30:09 2016 +0200

    patch 7.4.1782
    Problem:    strcharpart() does not work properly with some multi-byte
                characters.
    Solution:   Use mb_cptr2len() instead of mb_char2len(). (Hirohito Higashi)
---
 src/eval.c                     |  4 ++--
 src/testdir/test_expr_utf8.vim | 10 ++++++++++
 src/version.c                  |  2 ++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/eval.c b/src/eval.c
index b3ebbd7..63ff2a0 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -19764,7 +19764,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
 	if (nchar > 0)
 	    while (nchar > 0 && nbyte < slen)
 	    {
-		nbyte += mb_char2len(p[nbyte]);
+		nbyte += mb_cptr2len(p + nbyte);
 		--nchar;
 	    }
 	else
@@ -19779,7 +19779,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
 		if (off < 0)
 		    len += 1;
 		else
-		    len += mb_char2len(p[off]);
+		    len += mb_cptr2len(p + off);
 		--charlen;
 	    }
 	}
diff --git a/src/testdir/test_expr_utf8.vim b/src/testdir/test_expr_utf8.vim
index c512ddf..e8246ef 100644
--- a/src/testdir/test_expr_utf8.vim
+++ b/src/testdir/test_expr_utf8.vim
@@ -23,6 +23,16 @@ func Test_strcharpart()
   call assert_equal('á', strcharpart('áxb', 0, 1))
   call assert_equal('x', strcharpart('áxb', 1, 1))
 
+  call assert_equal('いうeお', strcharpart('あいうeお', 1))
+  call assert_equal('い', strcharpart('あいうeお', 1, 1))
+  call assert_equal('いう', strcharpart('あいうeお', 1, 2))
+  call assert_equal('いうe', strcharpart('あいうeお', 1, 3))
+  call assert_equal('いうeお', strcharpart('あいうeお', 1, 4))
+  call assert_equal('eお', strcharpart('あいうeお', 3))
+  call assert_equal('e', strcharpart('あいうeお', 3, 1))
+
+  call assert_equal('あ', strcharpart('あいうeお', -3, 4))
+
   call assert_equal('a', strcharpart('àxb', 0, 1))
   call assert_equal('̀', strcharpart('àxb', 1, 1))
   call assert_equal('x', strcharpart('àxb', 2, 1))
diff --git a/src/version.c b/src/version.c
index 2ae156c..09372ef 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1782,
+/**/
     1781,
 /**/
     1780,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vim/vim.git



More information about the pkg-vim-maintainers mailing list