summaryrefslogtreecommitdiffstats
path: root/patches/source/vim/patches/7.4.158
blob: d5291d3ee5eb15d30a969db336634ecf09088cc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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


*** ../vim-7.4.157/src/eval.c	2014-01-14 19:44:30.000000000 +0100
--- src/eval.c	2014-01-23 19:25:23.199796533 +0100
***************
*** 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(&regmatch, 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(&regmatch, 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 ----
*** ../vim-7.4.157/src/testdir/test80.in	2013-09-29 21:11:00.000000000 +0200
--- src/testdir/test80.in	2014-01-23 19:24:30.487795084 +0100
***************
*** 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
  
*** ../vim-7.4.157/src/testdir/test80.ok	2013-09-29 21:11:00.000000000 +0200
--- src/testdir/test80.ok	2014-01-23 19:24:35.691795227 +0100
***************
*** 115,117 ****
--- 115,128 ----
  
  TEST_9:
  XXx
+ 
+ 
+ TEST_10:
+ a1a2a3a
+ aaa
+ 1a2a3a
+ a1a2a3a
+ a1a2a3
+ aaa
+ aa2a3a
+ 1aaa
*** ../vim-7.4.157/src/version.c	2014-01-23 18:12:44.695676751 +0100
--- src/version.c	2014-01-23 19:27:21.611799787 +0100
***************
*** 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    ///