mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
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)
This commit is contained in:
parent
da5b3dcf06
commit
fca6600305
@ -19764,7 +19764,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
|
|||||||
if (nchar > 0)
|
if (nchar > 0)
|
||||||
while (nchar > 0 && nbyte < slen)
|
while (nchar > 0 && nbyte < slen)
|
||||||
{
|
{
|
||||||
nbyte += mb_char2len(p[nbyte]);
|
nbyte += mb_cptr2len(p + nbyte);
|
||||||
--nchar;
|
--nchar;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -19779,7 +19779,7 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
|
|||||||
if (off < 0)
|
if (off < 0)
|
||||||
len += 1;
|
len += 1;
|
||||||
else
|
else
|
||||||
len += mb_char2len(p[off]);
|
len += mb_cptr2len(p + off);
|
||||||
--charlen;
|
--charlen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,16 @@ func Test_strcharpart()
|
|||||||
call assert_equal('á', strcharpart('áxb', 0, 1))
|
call assert_equal('á', strcharpart('áxb', 0, 1))
|
||||||
call assert_equal('x', strcharpart('áxb', 1, 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('a', strcharpart('àxb', 0, 1))
|
||||||
call assert_equal('̀', strcharpart('àxb', 1, 1))
|
call assert_equal('̀', strcharpart('àxb', 1, 1))
|
||||||
call assert_equal('x', strcharpart('àxb', 2, 1))
|
call assert_equal('x', strcharpart('àxb', 2, 1))
|
||||||
|
@ -753,6 +753,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 */
|
||||||
|
/**/
|
||||||
|
1782,
|
||||||
/**/
|
/**/
|
||||||
1781,
|
1781,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user