On Tue, Dec 31, 2013 at 6:54 PM, Bram Moolenaar <[email protected]> wrote:

>
> Yukihiro Nakadaira wrote:
>
> > After patch 7.4.045, substitute('xxx', 'x\zs', 'y', 'g') returns "xyxxy".
> > "xyxyxy" is expected.
>
> Thanks for reporting the problem. I'll add it in the todo list.


I think that this problem can be fixed with attached patch.
Please check it.

However, I found another problem, inconsistency between substitute() and :s.

let y = substitute('aaa', '\ze', 'x', 'g') | $put =y        " => xaxaxax
$put ='aaa' | s/\ze/x/g                                     " => xaxaxa

let y = substitute('abc', 'a\|\ze', 'x', 'g') | $put =y     " => xxbxcx
$put ='abc' | s/a\|\ze/x/g                                  " => xbxc

-- 
Yukihiro Nakadaira - [email protected]

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -r 339a410f525a src/eval.c
--- a/src/eval.c        Tue Jan 14 15:24:39 2014 +0100
+++ b/src/eval.c        Wed Jan 15 22:58:08 2014 +0900
@@ -24355,7 +24355,7 @@
     garray_T   ga;
     char_u     *ret;
     char_u     *save_cpo;
-    int                zero_width;
+    char_u     *zero_width = NULL;
 
     /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
     save_cpo = p_cpo;
@@ -24372,6 +24372,14 @@
        tail = str;
        while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
        {
+           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;
+           }
+
            /*
             * Get some space for a temporary buffer to do the substitution
             * into.  It will contain:
@@ -24394,19 +24402,13 @@
            (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
                                          + ga.ga_len + i, TRUE, TRUE, FALSE);
            ga.ga_len += i + sublen - 1;
-           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;
+           if (regmatch.startp[0] == regmatch.endp[0])
+               zero_width = regmatch.endp[0];
        }
 
        if (ga.ga_data != NULL)
diff -r 339a410f525a src/testdir/test80.in
--- a/src/testdir/test80.in     Tue Jan 14 15:24:39 2014 +0100
+++ b/src/testdir/test80.in     Wed Jan 15 22:58:08 2014 +0900
@@ -176,6 +176,21 @@
 TEST_10:
 
 STARTTEST
+:set magic&
+:set cpo&
+:$put =\"\n\nTEST_10:\"
+:$put =substitute('123', '\zs', 'a', 'g')
+:$put =substitute('123', '\zs.', 'a', 'g')
+:$put =substitute('123', '.\zs', 'a', 'g')
+:$put =substitute('123', '\ze', 'a', 'g')
+:$put =substitute('123', '\ze.', 'a', 'g')
+:$put =substitute('123', '.\ze', 'a', 'g')
+/^TEST_11
+ENDTEST
+
+TEST_11:
+
+STARTTEST
 :/^Results/,$wq! test.out
 ENDTEST
 
diff -r 339a410f525a src/testdir/test80.ok
--- a/src/testdir/test80.ok     Tue Jan 14 15:24:39 2014 +0100
+++ b/src/testdir/test80.ok     Wed Jan 15 22:58:08 2014 +0900
@@ -115,3 +115,12 @@
 
 TEST_9:
 XXx
+
+
+TEST_10:
+a1a2a3a
+aaa
+1a2a3a
+a1a2a3a
+a1a2a3
+aaa

Raspunde prin e-mail lui