diff src/eval.c @ 5388:8ced827b2e8b v7.4.045

updated for version 7.4.045 Problem: substitute() does not work properly when the pattern starts with "\ze". Solution: Detect an empty match. (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Sun, 29 Sep 2013 21:11:05 +0200
parents 8336fd924e05
children c21b2f52f1dd
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -24301,6 +24301,7 @@ do_string_sub(str, pat, sub, flags)
     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;
@@ -24339,20 +24340,17 @@ do_string_sub(str, pat, sub, flags)
 	    (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
 					  + ga.ga_len + i, TRUE, TRUE, FALSE);
 	    ga.ga_len += i + sublen - 1;
-	    /* avoid getting stuck on a match with an empty string */
-	    if (tail == regmatch.endp[0])
-	    {
-		if (*tail == NUL)
-		    break;
+	    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;
 	    }
-	    else
-	    {
-		tail = regmatch.endp[0];
-		if (*tail == NUL)
-		    break;
-	    }
 	    if (!do_all)
 		break;
 	}