On Thu, Jan 16, 2014 at 5:58 AM, Bram Moolenaar <b...@moolenaar.net> wrote:
> > Yukihiro Nakadaira wrote: > > > On Tue, Dec 31, 2013 at 6:54 PM, Bram Moolenaar <b...@moolenaar.net> > 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 > > Nice to see a patch for this problem. I have updated patch. :echo substitute('123', '1\zs\|[23]', 'a', 'g') old: 1a2a new: 1aaa -- Yukihiro Nakadaira - yukihiro.nakada...@gmail.com -- -- 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 vim_dev+unsubscr...@googlegroups.com. 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 Thu Jan 16 18:54:52 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,19 @@ tail = str; while (vim_regexec_nl(®match, 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 * into. It will contain: @@ -24394,17 +24407,9 @@ (void)vim_regsub(®match, 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; } 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 Thu Jan 16 18:54:52 2014 +0900 @@ -176,6 +176,23 @@ 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', '\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', '1\|\ze', 'a', 'g') | $put =y +:let y = substitute('123', '1\zs\|[23]', 'a', 'g') | $put =y +/^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 Thu Jan 16 18:54:52 2014 +0900 @@ -115,3 +115,14 @@ TEST_9: XXx + + +TEST_10: +a1a2a3a +aaa +1a2a3a +a1a2a3a +a1a2a3 +aaa +aa2a3a +1aaa