| To: vim_dev@googlegroups.com |
| Subject: Patch 7.4.158 |
| Fcc: outbox |
| From: Bram Moolenaar <Bram@moolenaar.net> |
| Mime-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| |
| Patch 7.4.158 (after 7.4.045) |
| Problem: Pattern containing \zs is not handled correctly by substitute(). |
| Solution: Change how an empty match is skipped. (Yukihiro Nakadaira) |
| Files: src/eval.c, src/testdir/test80.in, src/testdir/test80.ok |
| |
| |
| |
| |
| |
| *** 24365,24371 **** |
| 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; |
| --- 24365,24371 ---- |
| garray_T ga; |
| char_u *ret; |
| char_u *save_cpo; |
| ! char_u *zero_width = NULL; |
| |
| /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */ |
| save_cpo = p_cpo; |
| |
| *** 24382,24387 **** |
| --- 24382,24400 ---- |
| 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: |
| |
| *** 24404,24420 **** |
| (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; |
| } |
| --- 24417,24425 ---- |
| |
| |
| |
| *** 176,181 **** |
| --- 176,198 ---- |
| 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 |
| |
| |
| |
| |
| *** 115,117 **** |
| --- 115,128 ---- |
| |
| TEST_9: |
| XXx |
| + |
| + |
| + TEST_10: |
| + a1a2a3a |
| + aaa |
| + 1a2a3a |
| + a1a2a3a |
| + a1a2a3 |
| + aaa |
| + aa2a3a |
| + 1aaa |
| |
| |
| |
| *** 740,741 **** |
| --- 740,743 ---- |
| { /* Add new patch number below this line */ |
| + /**/ |
| + 158, |
| /**/ |
| |
| -- |
| $ echo pizza > /dev/oven |
| |
| /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ |
| /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ |
| \\\ an exciting new programming language -- http://www.Zimbu.org /// |
| \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |