mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
vim-patch:7.4.323 #967
Problem: Substitute() with zero width pattern breaks multi-byte character. Solution: Take multi-byte character size into account. (Yukihiro Nakadaira) https://code.google.com/p/vim/source/detail?r=238f5027830cad22e17a970483af9b160869cdf3
This commit is contained in:

committed by
Justin M. Keyes

parent
69497ad10a
commit
cb809069a8
@@ -18996,8 +18996,10 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
|
|||||||
if (regmatch.startp[0] == regmatch.endp[0]) {
|
if (regmatch.startp[0] == regmatch.endp[0]) {
|
||||||
if (zero_width == regmatch.startp[0]) {
|
if (zero_width == regmatch.startp[0]) {
|
||||||
/* avoid getting stuck on a match with an empty string */
|
/* avoid getting stuck on a match with an empty string */
|
||||||
*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
|
int i = MB_PTR2LEN(tail);
|
||||||
++ga.ga_len;
|
memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i);
|
||||||
|
ga.ga_len += i;
|
||||||
|
tail += i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
zero_width = regmatch.startp[0];
|
zero_width = regmatch.startp[0];
|
||||||
|
@@ -179,6 +179,13 @@ ENDTEST
|
|||||||
byteidx
|
byteidx
|
||||||
byteidxcomp
|
byteidxcomp
|
||||||
|
|
||||||
|
STARTTEST
|
||||||
|
/^substitute
|
||||||
|
:let y = substitute('123', '\zs', 'a', 'g') | put =y
|
||||||
|
ENDTEST
|
||||||
|
|
||||||
|
substitute
|
||||||
|
|
||||||
STARTTEST
|
STARTTEST
|
||||||
:g/^STARTTEST/.,/^ENDTEST/d
|
:g/^STARTTEST/.,/^ENDTEST/d
|
||||||
:1;/^Results/,$wq! test.out
|
:1;/^Results/,$wq! test.out
|
||||||
|
@@ -160,3 +160,7 @@ byteidxcomp
|
|||||||
[0, 1, 3, 4, -1]
|
[0, 1, 3, 4, -1]
|
||||||
[0, 1, 2, 4, 5, -1]
|
[0, 1, 2, 4, 5, -1]
|
||||||
|
|
||||||
|
|
||||||
|
substitute
|
||||||
|
a1a2a3a
|
||||||
|
|
||||||
|
@@ -226,7 +226,7 @@ static int included_patches[] = {
|
|||||||
//326,
|
//326,
|
||||||
//325,
|
//325,
|
||||||
//324,
|
//324,
|
||||||
//323,
|
323,
|
||||||
//322,
|
//322,
|
||||||
//321,
|
//321,
|
||||||
//320,
|
//320,
|
||||||
|
Reference in New Issue
Block a user