0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

updated for version 7.4.158

Problem:    Pattern containing \zs is not handled correctly by substitute().
Solution:   Change how an empty match is skipped. (Yukihiro Nakadaira)
This commit is contained in:
Bram Moolenaar
2014-01-23 20:09:34 +01:00
parent b4d587cbd9
commit 8af269186c
4 changed files with 44 additions and 9 deletions

View File

@@ -24365,7 +24365,7 @@ do_string_sub(str, pat, sub, flags)
garray_T ga; garray_T ga;
char_u *ret; char_u *ret;
char_u *save_cpo; char_u *save_cpo;
int zero_width; char_u *zero_width = NULL;
/* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */ /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
save_cpo = p_cpo; save_cpo = p_cpo;
@@ -24382,6 +24382,19 @@ do_string_sub(str, pat, sub, flags)
tail = str; tail = str;
while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str))) while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
{ {
/* Skip empty match except for first match. */
if (regmatch.startp[0] == regmatch.endp[0])
{
if (zero_width == regmatch.startp[0])
{
/* avoid getting stuck on a match with an empty string */
*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
++ga.ga_len;
continue;
}
zero_width = regmatch.startp[0];
}
/* /*
* Get some space for a temporary buffer to do the substitution * Get some space for a temporary buffer to do the substitution
* into. It will contain: * into. It will contain:
@@ -24404,17 +24417,9 @@ do_string_sub(str, pat, sub, flags)
(void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
+ ga.ga_len + i, TRUE, TRUE, FALSE); + ga.ga_len + i, TRUE, TRUE, FALSE);
ga.ga_len += i + sublen - 1; ga.ga_len += i + sublen - 1;
zero_width = (tail == regmatch.endp[0]
|| regmatch.startp[0] == regmatch.endp[0]);
tail = regmatch.endp[0]; tail = regmatch.endp[0];
if (*tail == NUL) if (*tail == NUL)
break; break;
if (zero_width)
{
/* avoid getting stuck on a match with an empty string */
*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
++ga.ga_len;
}
if (!do_all) if (!do_all)
break; break;
} }

View File

@@ -175,6 +175,23 @@ ENDTEST
TEST_9: TEST_9:
STARTTEST
:set magic&
:set cpo&
:$put =\"\n\nTEST_9:\"
:$put ='xxx'
:s/x/X/gc
yyq/^TEST_10:
ENDTEST
TEST_10:
STARTTEST
:set magic&
:set cpo&
:$put =\"\n\nTEST_10:\"
:let y = substitute('123', '\zs', 'a', 'g') | $put =y
:let y = substitute('123', '\zs.', 'a', 'g') | $put =y
:let y = substitute('123', '.\zs', 'a', 'g') | $put =y :let y = substitute('123', '.\zs', 'a', 'g') | $put =y
:let y = substitute('123', '\ze', 'a', 'g') | $put =y :let y = substitute('123', '\ze', 'a', 'g') | $put =y
:let y = substitute('123', '\ze.', 'a', 'g') | $put =y :let y = substitute('123', '\ze.', 'a', 'g') | $put =y

View File

@@ -115,3 +115,14 @@ N,,NZ
c c
% %
TEST_7:
A
A
B
B
-abab
c-cbcbc
TEST_8:

View File

@@ -738,6 +738,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 */
/**/
158,
/**/ /**/
157, 157,
/**/ /**/