Karsten Hopp d44f37
To: vim_dev@googlegroups.com
Karsten Hopp d44f37
Subject: Patch 7.4.158
Karsten Hopp d44f37
Fcc: outbox
Karsten Hopp d44f37
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp d44f37
Mime-Version: 1.0
Karsten Hopp d44f37
Content-Type: text/plain; charset=UTF-8
Karsten Hopp d44f37
Content-Transfer-Encoding: 8bit
Karsten Hopp d44f37
------------
Karsten Hopp d44f37
Karsten Hopp d44f37
Patch 7.4.158 (after 7.4.045)
Karsten Hopp d44f37
Problem:    Pattern containing \zs is not handled correctly by substitute().
Karsten Hopp d44f37
Solution:   Change how an empty match is skipped. (Yukihiro Nakadaira)
Karsten Hopp d44f37
Files:	    src/eval.c, src/testdir/test80.in, src/testdir/test80.ok
Karsten Hopp d44f37
Karsten Hopp d44f37
Karsten Hopp d44f37
*** ../vim-7.4.157/src/eval.c	2014-01-14 19:44:30.000000000 +0100
Karsten Hopp d44f37
--- src/eval.c	2014-01-23 19:25:23.199796533 +0100
Karsten Hopp d44f37
***************
Karsten Hopp d44f37
*** 24365,24371 ****
Karsten Hopp d44f37
      garray_T	ga;
Karsten Hopp d44f37
      char_u	*ret;
Karsten Hopp d44f37
      char_u	*save_cpo;
Karsten Hopp d44f37
!     int		zero_width;
Karsten Hopp d44f37
  
Karsten Hopp d44f37
      /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
Karsten Hopp d44f37
      save_cpo = p_cpo;
Karsten Hopp d44f37
--- 24365,24371 ----
Karsten Hopp d44f37
      garray_T	ga;
Karsten Hopp d44f37
      char_u	*ret;
Karsten Hopp d44f37
      char_u	*save_cpo;
Karsten Hopp d44f37
!     char_u	*zero_width = NULL;
Karsten Hopp d44f37
  
Karsten Hopp d44f37
      /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
Karsten Hopp d44f37
      save_cpo = p_cpo;
Karsten Hopp d44f37
***************
Karsten Hopp d44f37
*** 24382,24387 ****
Karsten Hopp d44f37
--- 24382,24400 ----
Karsten Hopp d44f37
  	tail = str;
Karsten Hopp d44f37
  	while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
Karsten Hopp d44f37
  	{
Karsten Hopp d44f37
+ 	    /* Skip empty match except for first match. */
Karsten Hopp d44f37
+ 	    if (regmatch.startp[0] == regmatch.endp[0])
Karsten Hopp d44f37
+ 	    {
Karsten Hopp d44f37
+ 		if (zero_width == regmatch.startp[0])
Karsten Hopp d44f37
+ 		{
Karsten Hopp d44f37
+ 		    /* avoid getting stuck on a match with an empty string */
Karsten Hopp d44f37
+ 		    *((char_u *)ga.ga_data + ga.ga_len) = *tail++;
Karsten Hopp d44f37
+ 		    ++ga.ga_len;
Karsten Hopp d44f37
+ 		    continue;
Karsten Hopp d44f37
+ 		}
Karsten Hopp d44f37
+ 		zero_width = regmatch.startp[0];
Karsten Hopp d44f37
+ 	    }
Karsten Hopp d44f37
+ 
Karsten Hopp d44f37
  	    /*
Karsten Hopp d44f37
  	     * Get some space for a temporary buffer to do the substitution
Karsten Hopp d44f37
  	     * into.  It will contain:
Karsten Hopp d44f37
***************
Karsten Hopp d44f37
*** 24404,24420 ****
Karsten Hopp d44f37
  	    (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
Karsten Hopp d44f37
  					  + ga.ga_len + i, TRUE, TRUE, FALSE);
Karsten Hopp d44f37
  	    ga.ga_len += i + sublen - 1;
Karsten Hopp d44f37
- 	    zero_width = (tail == regmatch.endp[0]
Karsten Hopp d44f37
- 				    || regmatch.startp[0] == regmatch.endp[0]);
Karsten Hopp d44f37
  	    tail = regmatch.endp[0];
Karsten Hopp d44f37
  	    if (*tail == NUL)
Karsten Hopp d44f37
  		break;
Karsten Hopp d44f37
- 	    if (zero_width)
Karsten Hopp d44f37
- 	    {
Karsten Hopp d44f37
- 		/* avoid getting stuck on a match with an empty string */
Karsten Hopp d44f37
- 		*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
Karsten Hopp d44f37
- 		++ga.ga_len;
Karsten Hopp d44f37
- 	    }
Karsten Hopp d44f37
  	    if (!do_all)
Karsten Hopp d44f37
  		break;
Karsten Hopp d44f37
  	}
Karsten Hopp d44f37
--- 24417,24425 ----
Karsten Hopp d44f37
*** ../vim-7.4.157/src/testdir/test80.in	2013-09-29 21:11:00.000000000 +0200
Karsten Hopp d44f37
--- src/testdir/test80.in	2014-01-23 19:24:30.487795084 +0100
Karsten Hopp d44f37
***************
Karsten Hopp d44f37
*** 176,181 ****
Karsten Hopp d44f37
--- 176,198 ----
Karsten Hopp d44f37
  TEST_10:
Karsten Hopp d44f37
  
Karsten Hopp d44f37
  STARTTEST
Karsten Hopp d44f37
+ :set magic&
Karsten Hopp d44f37
+ :set cpo&
Karsten Hopp d44f37
+ :$put =\"\n\nTEST_10:\"
Karsten Hopp d44f37
+ :let y = substitute('123', '\zs', 'a', 'g')             | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '\zs.', 'a', 'g')            | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '.\zs', 'a', 'g')            | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '\ze', 'a', 'g')             | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '\ze.', 'a', 'g')            | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '.\ze', 'a', 'g')            | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '1\|\ze', 'a', 'g')          | $put =y
Karsten Hopp d44f37
+ :let y = substitute('123', '1\zs\|[23]', 'a', 'g')      | $put =y
Karsten Hopp d44f37
+ /^TEST_11
Karsten Hopp d44f37
+ ENDTEST
Karsten Hopp d44f37
+ 
Karsten Hopp d44f37
+ TEST_11:
Karsten Hopp d44f37
+ 
Karsten Hopp d44f37
+ STARTTEST
Karsten Hopp d44f37
  :/^Results/,$wq! test.out
Karsten Hopp d44f37
  ENDTEST
Karsten Hopp d44f37
  
Karsten Hopp d44f37
*** ../vim-7.4.157/src/testdir/test80.ok	2013-09-29 21:11:00.000000000 +0200
Karsten Hopp d44f37
--- src/testdir/test80.ok	2014-01-23 19:24:35.691795227 +0100
Karsten Hopp d44f37
***************
Karsten Hopp d44f37
*** 115,117 ****
Karsten Hopp d44f37
--- 115,128 ----
Karsten Hopp d44f37
  
Karsten Hopp d44f37
  TEST_9:
Karsten Hopp d44f37
  XXx
Karsten Hopp d44f37
+ 
Karsten Hopp d44f37
+ 
Karsten Hopp d44f37
+ TEST_10:
Karsten Hopp d44f37
+ a1a2a3a
Karsten Hopp d44f37
+ aaa
Karsten Hopp d44f37
+ 1a2a3a
Karsten Hopp d44f37
+ a1a2a3a
Karsten Hopp d44f37
+ a1a2a3
Karsten Hopp d44f37
+ aaa
Karsten Hopp d44f37
+ aa2a3a
Karsten Hopp d44f37
+ 1aaa
Karsten Hopp d44f37
*** ../vim-7.4.157/src/version.c	2014-01-23 18:12:44.695676751 +0100
Karsten Hopp d44f37
--- src/version.c	2014-01-23 19:27:21.611799787 +0100
Karsten Hopp d44f37
***************
Karsten Hopp d44f37
*** 740,741 ****
Karsten Hopp d44f37
--- 740,743 ----
Karsten Hopp d44f37
  {   /* Add new patch number below this line */
Karsten Hopp d44f37
+ /**/
Karsten Hopp d44f37
+     158,
Karsten Hopp d44f37
  /**/
Karsten Hopp d44f37
Karsten Hopp d44f37
-- 
Karsten Hopp d44f37
$ echo pizza > /dev/oven
Karsten Hopp d44f37
Karsten Hopp d44f37
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp d44f37
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp d44f37
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp d44f37
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///