Karsten Hopp 3a67c1
To: vim_dev@googlegroups.com
Karsten Hopp 3a67c1
Subject: Patch 7.4.045
Karsten Hopp 3a67c1
Fcc: outbox
Karsten Hopp 3a67c1
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 3a67c1
Mime-Version: 1.0
Karsten Hopp 3a67c1
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 3a67c1
Content-Transfer-Encoding: 8bit
Karsten Hopp 3a67c1
------------
Karsten Hopp 3a67c1
Karsten Hopp 3a67c1
Patch 7.4.045
Karsten Hopp 3a67c1
Problem:    substitute() does not work properly when the pattern starts with
Karsten Hopp 3a67c1
	    "\ze".
Karsten Hopp 3a67c1
Solution:   Detect an empty match. (Christian Brabandt)
Karsten Hopp 3a67c1
Files:	    src/eval.c, src/testdir/test80.in, src/testdir/test80.ok
Karsten Hopp 3a67c1
Karsten Hopp 3a67c1
Karsten Hopp 3a67c1
*** ../vim-7.4.044/src/eval.c	2013-09-25 21:00:24.000000000 +0200
Karsten Hopp 3a67c1
--- src/eval.c	2013-09-29 21:03:22.000000000 +0200
Karsten Hopp 3a67c1
***************
Karsten Hopp 3a67c1
*** 24301,24306 ****
Karsten Hopp 3a67c1
--- 24301,24307 ----
Karsten Hopp 3a67c1
      garray_T	ga;
Karsten Hopp 3a67c1
      char_u	*ret;
Karsten Hopp 3a67c1
      char_u	*save_cpo;
Karsten Hopp 3a67c1
+     int		zero_width;
Karsten Hopp 3a67c1
  
Karsten Hopp 3a67c1
      /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
Karsten Hopp 3a67c1
      save_cpo = p_cpo;
Karsten Hopp 3a67c1
***************
Karsten Hopp 3a67c1
*** 24339,24358 ****
Karsten Hopp 3a67c1
  	    (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
Karsten Hopp 3a67c1
  					  + ga.ga_len + i, TRUE, TRUE, FALSE);
Karsten Hopp 3a67c1
  	    ga.ga_len += i + sublen - 1;
Karsten Hopp 3a67c1
! 	    /* avoid getting stuck on a match with an empty string */
Karsten Hopp 3a67c1
! 	    if (tail == regmatch.endp[0])
Karsten Hopp 3a67c1
  	    {
Karsten Hopp 3a67c1
! 		if (*tail == NUL)
Karsten Hopp 3a67c1
! 		    break;
Karsten Hopp 3a67c1
  		*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
Karsten Hopp 3a67c1
  		++ga.ga_len;
Karsten Hopp 3a67c1
  	    }
Karsten Hopp 3a67c1
- 	    else
Karsten Hopp 3a67c1
- 	    {
Karsten Hopp 3a67c1
- 		tail = regmatch.endp[0];
Karsten Hopp 3a67c1
- 		if (*tail == NUL)
Karsten Hopp 3a67c1
- 		    break;
Karsten Hopp 3a67c1
- 	    }
Karsten Hopp 3a67c1
  	    if (!do_all)
Karsten Hopp 3a67c1
  		break;
Karsten Hopp 3a67c1
  	}
Karsten Hopp 3a67c1
--- 24340,24356 ----
Karsten Hopp 3a67c1
  	    (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
Karsten Hopp 3a67c1
  					  + ga.ga_len + i, TRUE, TRUE, FALSE);
Karsten Hopp 3a67c1
  	    ga.ga_len += i + sublen - 1;
Karsten Hopp 3a67c1
! 	    zero_width = (tail == regmatch.endp[0]
Karsten Hopp 3a67c1
! 				    || regmatch.startp[0] == regmatch.endp[0]);
Karsten Hopp 3a67c1
! 	    tail = regmatch.endp[0];
Karsten Hopp 3a67c1
! 	    if (*tail == NUL)
Karsten Hopp 3a67c1
! 		break;
Karsten Hopp 3a67c1
! 	    if (zero_width)
Karsten Hopp 3a67c1
  	    {
Karsten Hopp 3a67c1
! 		/* avoid getting stuck on a match with an empty string */
Karsten Hopp 3a67c1
  		*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
Karsten Hopp 3a67c1
  		++ga.ga_len;
Karsten Hopp 3a67c1
  	    }
Karsten Hopp 3a67c1
  	    if (!do_all)
Karsten Hopp 3a67c1
  		break;
Karsten Hopp 3a67c1
  	}
Karsten Hopp 3a67c1
*** ../vim-7.4.044/src/testdir/test80.in	2013-03-19 17:30:51.000000000 +0100
Karsten Hopp 3a67c1
--- src/testdir/test80.in	2013-09-29 20:59:00.000000000 +0200
Karsten Hopp 3a67c1
***************
Karsten Hopp 3a67c1
*** 142,147 ****
Karsten Hopp 3a67c1
--- 142,149 ----
Karsten Hopp 3a67c1
  :$put =\"\n\nTEST_7:\"
Karsten Hopp 3a67c1
  :$put =substitute('A?
A', 'A.', '\=submatch(0)', '')
Karsten Hopp 3a67c1
  :$put =substitute(\"B\nB\", 'B.', '\=submatch(0)', '')
Karsten Hopp 3a67c1
+ :$put =substitute('-bb', '\zeb', 'a', 'g')
Karsten Hopp 3a67c1
+ :$put =substitute('-bb', '\ze', 'c', 'g')
Karsten Hopp 3a67c1
  /^TEST_8
Karsten Hopp 3a67c1
  ENDTEST
Karsten Hopp 3a67c1
  
Karsten Hopp 3a67c1
*** ../vim-7.4.044/src/testdir/test80.ok	2013-03-19 17:31:45.000000000 +0100
Karsten Hopp 3a67c1
--- src/testdir/test80.ok	2013-09-29 20:59:35.000000000 +0200
Karsten Hopp 3a67c1
***************
Karsten Hopp 3a67c1
*** 103,108 ****
Karsten Hopp 3a67c1
--- 103,110 ----
Karsten Hopp 3a67c1
  A
A
Karsten Hopp 3a67c1
  B
Karsten Hopp 3a67c1
  B
Karsten Hopp 3a67c1
+ -abab
Karsten Hopp 3a67c1
+ c-cbcbc
Karsten Hopp 3a67c1
  
Karsten Hopp 3a67c1
  
Karsten Hopp 3a67c1
  TEST_8:
Karsten Hopp 3a67c1
*** ../vim-7.4.044/src/version.c	2013-09-29 19:05:17.000000000 +0200
Karsten Hopp 3a67c1
--- src/version.c	2013-09-29 21:04:50.000000000 +0200
Karsten Hopp 3a67c1
***************
Karsten Hopp 3a67c1
*** 740,741 ****
Karsten Hopp 3a67c1
--- 740,743 ----
Karsten Hopp 3a67c1
  {   /* Add new patch number below this line */
Karsten Hopp 3a67c1
+ /**/
Karsten Hopp 3a67c1
+     45,
Karsten Hopp 3a67c1
  /**/
Karsten Hopp 3a67c1
Karsten Hopp 3a67c1
-- 
Karsten Hopp 3a67c1
Just think of all the things we haven't thought of yet.
Karsten Hopp 3a67c1
Karsten Hopp 3a67c1
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 3a67c1
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 3a67c1
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 3a67c1
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///