Skip to content

Commit fca6600

Browse files
committed
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)
1 parent da5b3dc commit fca6600

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/eval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19764,7 +19764,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
1976419764
if (nchar > 0)
1976519765
while (nchar > 0 && nbyte < slen)
1976619766
{
19767-
nbyte += mb_char2len(p[nbyte]);
19767+
nbyte += mb_cptr2len(p + nbyte);
1976819768
--nchar;
1976919769
}
1977019770
else
@@ -19779,7 +19779,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
1977919779
if (off < 0)
1978019780
len += 1;
1978119781
else
19782-
len += mb_char2len(p[off]);
19782+
len += mb_cptr2len(p + off);
1978319783
--charlen;
1978419784
}
1978519785
}

src/testdir/test_expr_utf8.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ func Test_strcharpart()
2323
call assert_equal('á', strcharpart('áxb', 0, 1))
2424
call assert_equal('x', strcharpart('áxb', 1, 1))
2525

26+
call assert_equal('いうeお', strcharpart('あいうeお', 1))
27+
call assert_equal('', strcharpart('あいうeお', 1, 1))
28+
call assert_equal('いう', strcharpart('あいうeお', 1, 2))
29+
call assert_equal('いうe', strcharpart('あいうeお', 1, 3))
30+
call assert_equal('いうeお', strcharpart('あいうeお', 1, 4))
31+
call assert_equal('eお', strcharpart('あいうeお', 3))
32+
call assert_equal('e', strcharpart('あいうeお', 3, 1))
33+
34+
call assert_equal('', strcharpart('あいうeお', -3, 4))
35+
2636
call assert_equal('a', strcharpart('àxb', 0, 1))
2737
call assert_equal('̀', strcharpart('àxb', 1, 1))
2838
call assert_equal('x', strcharpart('àxb', 2, 1))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ static char *(features[]) =
753753

754754
static int included_patches[] =
755755
{ /* Add new patch number below this line */
756+
/**/
757+
1782,
756758
/**/
757759
1781,
758760
/**/

0 commit comments

Comments
 (0)