Mercurial > emacs
comparison src/search.c @ 21988:8cf3bbc89c3c
(Freplace_match): Fix the loop for copying text
from a string, in handling lastpos and pos.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 07 May 1998 23:15:14 +0000 |
parents | bda081af77e7 |
children | 84bcdbc46d71 |
comparison
equal
deleted
inserted
replaced
21987:cd7ff97f3b05 | 21988:8cf3bbc89c3c |
---|---|
2298 | 2298 |
2299 /* Substitute parts of the match into NEWTEXT | 2299 /* Substitute parts of the match into NEWTEXT |
2300 if desired. */ | 2300 if desired. */ |
2301 if (NILP (literal)) | 2301 if (NILP (literal)) |
2302 { | 2302 { |
2303 int lastpos = -1; | 2303 int lastpos = 0; |
2304 int lastpos_byte = -1; | 2304 int lastpos_byte = 0; |
2305 /* We build up the substituted string in ACCUM. */ | 2305 /* We build up the substituted string in ACCUM. */ |
2306 Lisp_Object accum; | 2306 Lisp_Object accum; |
2307 Lisp_Object middle; | 2307 Lisp_Object middle; |
2308 int pos_byte; | 2308 int pos_byte; |
2309 | 2309 |
2338 else | 2338 else |
2339 error ("Invalid use of `\\' in replacement text"); | 2339 error ("Invalid use of `\\' in replacement text"); |
2340 } | 2340 } |
2341 if (substart >= 0) | 2341 if (substart >= 0) |
2342 { | 2342 { |
2343 if (pos - 1 != lastpos + 1) | 2343 if (pos - 2 != lastpos) |
2344 middle = substring_both (newtext, lastpos + 1, | 2344 middle = substring_both (newtext, lastpos, |
2345 lastpos_byte + 1, | 2345 lastpos_byte, |
2346 pos - 1, pos_byte - 1); | 2346 pos - 2, pos_byte - 2); |
2347 else | 2347 else |
2348 middle = Qnil; | 2348 middle = Qnil; |
2349 accum = concat3 (accum, middle, | 2349 accum = concat3 (accum, middle, |
2350 Fsubstring (string, | 2350 Fsubstring (string, |
2351 make_number (substart), | 2351 make_number (substart), |
2353 lastpos = pos; | 2353 lastpos = pos; |
2354 lastpos_byte = pos_byte; | 2354 lastpos_byte = pos_byte; |
2355 } | 2355 } |
2356 else if (delbackslash) | 2356 else if (delbackslash) |
2357 { | 2357 { |
2358 middle = substring_both (newtext, lastpos + 1, | 2358 middle = substring_both (newtext, lastpos, |
2359 lastpos_byte + 1, | 2359 lastpos_byte, |
2360 pos, pos_byte); | 2360 pos - 1, pos_byte - 1); |
2361 | 2361 |
2362 accum = concat2 (accum, middle); | 2362 accum = concat2 (accum, middle); |
2363 lastpos = pos; | 2363 lastpos = pos; |
2364 lastpos_byte = pos_byte; | 2364 lastpos_byte = pos_byte; |
2365 } | 2365 } |
2366 } | 2366 } |
2367 | 2367 |
2368 if (pos != lastpos + 1) | 2368 if (pos != lastpos) |
2369 middle = substring_both (newtext, lastpos + 1, | 2369 middle = substring_both (newtext, lastpos, |
2370 lastpos_byte + 1, | 2370 lastpos_byte, |
2371 pos, pos_byte); | 2371 pos, pos_byte); |
2372 else | 2372 else |
2373 middle = Qnil; | 2373 middle = Qnil; |
2374 | 2374 |
2375 newtext = concat2 (accum, middle); | 2375 newtext = concat2 (accum, middle); |