aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1998-06-20 22:28:28 +0000
committerKarl Heuer1998-06-20 22:28:28 +0000
commitac3b28b1940043dec8e2e77ecb0a0956783403a5 (patch)
tree4990bd1568b759ff92f122558f10d6fdf61b89ee /src
parenta9155e8732d3ce369769311946ac932b589a3749 (diff)
downloademacs-ac3b28b1940043dec8e2e77ecb0a0956783403a5.tar.gz
emacs-ac3b28b1940043dec8e2e77ecb0a0956783403a5.zip
(Freplace_match): Work by chars, not by bytes,
for scanning the old text, and for inserting new string in buffer.
Diffstat (limited to 'src')
-rw-r--r--src/search.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/search.c b/src/search.c
index d9d445afad0..d7068547434 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2187,7 +2187,7 @@ since only regular expressions have distinguished subexpressions.")
2187 Lisp_Object newtext, fixedcase, literal, string, subexp; 2187 Lisp_Object newtext, fixedcase, literal, string, subexp;
2188{ 2188{
2189 enum { nochange, all_caps, cap_initial } case_action; 2189 enum { nochange, all_caps, cap_initial } case_action;
2190 register int pos, last; 2190 register int pos, pos_byte;
2191 int some_multiletter_word; 2191 int some_multiletter_word;
2192 int some_lowercase; 2192 int some_lowercase;
2193 int some_uppercase; 2193 int some_uppercase;
@@ -2237,18 +2237,16 @@ since only regular expressions have distinguished subexpressions.")
2237 2237
2238 if (NILP (fixedcase)) 2238 if (NILP (fixedcase))
2239 { 2239 {
2240 int beg;
2241 /* Decide how to casify by examining the matched text. */ 2240 /* Decide how to casify by examining the matched text. */
2241 int last;
2242 2242
2243 if (NILP (string)) 2243 pos = search_regs.start[sub];
2244 last = CHAR_TO_BYTE (search_regs.end[sub]); 2244 last = search_regs.end[sub];
2245 else
2246 last = search_regs.end[sub];
2247 2245
2248 if (NILP (string)) 2246 if (NILP (string))
2249 beg = CHAR_TO_BYTE (search_regs.start[sub]); 2247 pos_byte = CHAR_TO_BYTE (pos);
2250 else 2248 else
2251 beg = search_regs.start[sub]; 2249 pos_byte = string_char_to_byte (string, pos);
2252 2250
2253 prevc = '\n'; 2251 prevc = '\n';
2254 case_action = all_caps; 2252 case_action = all_caps;
@@ -2260,12 +2258,15 @@ since only regular expressions have distinguished subexpressions.")
2260 some_nonuppercase_initial = 0; 2258 some_nonuppercase_initial = 0;
2261 some_uppercase = 0; 2259 some_uppercase = 0;
2262 2260
2263 for (pos = beg; pos < last; pos++) 2261 while (pos < last)
2264 { 2262 {
2265 if (NILP (string)) 2263 if (NILP (string))
2266 c = FETCH_BYTE (pos); 2264 {
2265 c = FETCH_CHAR (pos_byte);
2266 INC_BOTH (pos, pos_byte);
2267 }
2267 else 2268 else
2268 c = XSTRING (string)->data[pos]; 2269 FETCH_STRING_CHAR_ADVANCE (c, string, pos, pos_byte);
2269 2270
2270 if (LOWERCASEP (c)) 2271 if (LOWERCASEP (c))
2271 { 2272 {
@@ -2329,11 +2330,11 @@ since only regular expressions have distinguished subexpressions.")
2329 /* We build up the substituted string in ACCUM. */ 2330 /* We build up the substituted string in ACCUM. */
2330 Lisp_Object accum; 2331 Lisp_Object accum;
2331 Lisp_Object middle; 2332 Lisp_Object middle;
2332 int pos_byte; 2333 int length = STRING_BYTES (XSTRING (newtext));
2333 2334
2334 accum = Qnil; 2335 accum = Qnil;
2335 2336
2336 for (pos_byte = 0, pos = 0; pos_byte < STRING_BYTES (XSTRING (newtext));) 2337 for (pos_byte = 0, pos = 0; pos_byte < length;)
2337 { 2338 {
2338 int substart = -1; 2339 int substart = -1;
2339 int subend; 2340 int subend;
@@ -2425,16 +2426,19 @@ since only regular expressions have distinguished subexpressions.")
2425 else 2426 else
2426 { 2427 {
2427 struct gcpro gcpro1; 2428 struct gcpro gcpro1;
2429 int length = STRING_BYTES (XSTRING (newtext));
2430
2428 GCPRO1 (newtext); 2431 GCPRO1 (newtext);
2429 2432
2430 for (pos = 0; pos < XSTRING (newtext)->size; pos++) 2433 for (pos_byte = 0, pos = 0; pos_byte < length;)
2431 { 2434 {
2432 int offset = PT - search_regs.start[sub]; 2435 int offset = PT - search_regs.start[sub];
2433 2436
2434 c = XSTRING (newtext)->data[pos]; 2437 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
2438
2435 if (c == '\\') 2439 if (c == '\\')
2436 { 2440 {
2437 c = XSTRING (newtext)->data[++pos]; 2441 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
2438 if (c == '&') 2442 if (c == '&')
2439 Finsert_buffer_substring 2443 Finsert_buffer_substring
2440 (Fcurrent_buffer (), 2444 (Fcurrent_buffer (),