mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
updated for version 7.4.045
Problem: substitute() does not work properly when the pattern starts with "\ze". Solution: Detect an empty match. (Christian Brabandt)
This commit is contained in:
18
src/eval.c
18
src/eval.c
@@ -24301,6 +24301,7 @@ do_string_sub(str, pat, sub, flags)
|
||||
garray_T ga;
|
||||
char_u *ret;
|
||||
char_u *save_cpo;
|
||||
int zero_width;
|
||||
|
||||
/* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
|
||||
save_cpo = p_cpo;
|
||||
@@ -24339,19 +24340,16 @@ do_string_sub(str, pat, sub, flags)
|
||||
(void)vim_regsub(®match, sub, (char_u *)ga.ga_data
|
||||
+ ga.ga_len + i, TRUE, TRUE, FALSE);
|
||||
ga.ga_len += i + sublen - 1;
|
||||
/* avoid getting stuck on a match with an empty string */
|
||||
if (tail == regmatch.endp[0])
|
||||
{
|
||||
if (*tail == NUL)
|
||||
break;
|
||||
*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
|
||||
++ga.ga_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
zero_width = (tail == regmatch.endp[0]
|
||||
|| regmatch.startp[0] == regmatch.endp[0]);
|
||||
tail = regmatch.endp[0];
|
||||
if (*tail == NUL)
|
||||
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)
|
||||
break;
|
||||
|
@@ -142,6 +142,8 @@ STARTTEST
|
||||
:$put =substitute('C', 'C', 'c', '')
|
||||
:$put =substitute('D', 'D', '%', '')
|
||||
/^TEST_7
|
||||
ENDTEST
|
||||
|
||||
TEST_7:
|
||||
|
||||
STARTTEST
|
||||
|
@@ -103,6 +103,8 @@ TEST_7:
|
||||
k
|
||||
l
|
||||
l
|
||||
|
||||
|
||||
TEST_5:
|
||||
A123456789987654321
|
||||
|
||||
|
@@ -738,6 +738,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
45,
|
||||
/**/
|
||||
44,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user