comparison src/eval.c @ 5623:d59544f3022b v7.4.158

updated for version 7.4.158 Problem: Pattern containing \zs is not handled correctly by substitute(). Solution: Change how an empty match is skipped. (Yukihiro Nakadaira)
author Bram Moolenaar <bram@vim.org>
date Thu, 23 Jan 2014 20:09:34 +0100
parents 71837ace77df
children 5d03c3747121
comparison
equal deleted inserted replaced
5622:cae8fca838ab 5623:d59544f3022b
24363 int do_all; 24363 int do_all;
24364 char_u *tail; 24364 char_u *tail;
24365 garray_T ga; 24365 garray_T ga;
24366 char_u *ret; 24366 char_u *ret;
24367 char_u *save_cpo; 24367 char_u *save_cpo;
24368 int zero_width; 24368 char_u *zero_width = NULL;
24369 24369
24370 /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */ 24370 /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */
24371 save_cpo = p_cpo; 24371 save_cpo = p_cpo;
24372 p_cpo = empty_option; 24372 p_cpo = empty_option;
24373 24373
24380 if (regmatch.regprog != NULL) 24380 if (regmatch.regprog != NULL)
24381 { 24381 {
24382 tail = str; 24382 tail = str;
24383 while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str))) 24383 while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
24384 { 24384 {
24385 /* Skip empty match except for first match. */
24386 if (regmatch.startp[0] == regmatch.endp[0])
24387 {
24388 if (zero_width == regmatch.startp[0])
24389 {
24390 /* avoid getting stuck on a match with an empty string */
24391 *((char_u *)ga.ga_data + ga.ga_len) = *tail++;
24392 ++ga.ga_len;
24393 continue;
24394 }
24395 zero_width = regmatch.startp[0];
24396 }
24397
24385 /* 24398 /*
24386 * Get some space for a temporary buffer to do the substitution 24399 * Get some space for a temporary buffer to do the substitution
24387 * into. It will contain: 24400 * into. It will contain:
24388 * - The text up to where the match is. 24401 * - The text up to where the match is.
24389 * - The substituted text. 24402 * - The substituted text.
24402 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); 24415 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i);
24403 /* add the substituted text */ 24416 /* add the substituted text */
24404 (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data 24417 (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
24405 + ga.ga_len + i, TRUE, TRUE, FALSE); 24418 + ga.ga_len + i, TRUE, TRUE, FALSE);
24406 ga.ga_len += i + sublen - 1; 24419 ga.ga_len += i + sublen - 1;
24407 zero_width = (tail == regmatch.endp[0]
24408 || regmatch.startp[0] == regmatch.endp[0]);
24409 tail = regmatch.endp[0]; 24420 tail = regmatch.endp[0];
24410 if (*tail == NUL) 24421 if (*tail == NUL)
24411 break; 24422 break;
24412 if (zero_width)
24413 {
24414 /* avoid getting stuck on a match with an empty string */
24415 *((char_u *)ga.ga_data + ga.ga_len) = *tail++;
24416 ++ga.ga_len;
24417 }
24418 if (!do_all) 24423 if (!do_all)
24419 break; 24424 break;
24420 } 24425 }
24421 24426
24422 if (ga.ga_data != NULL) 24427 if (ga.ga_data != NULL)