comparison src/search.c @ 22533:6eae236a4f01

(Freplace_match): Work by chars, not by bytes, for scanning the old text, and for inserting new string in buffer.
author Karl Heuer <kwzh@gnu.org>
date Sat, 20 Jun 1998 22:28:28 +0000
parents 239a4b800303
children 929ad308aba6
comparison
equal deleted inserted replaced
22532:5a83f0f3b29d 22533:6eae236a4f01
2185 since only regular expressions have distinguished subexpressions.") 2185 since only regular expressions have distinguished subexpressions.")
2186 (newtext, fixedcase, literal, string, subexp) 2186 (newtext, fixedcase, literal, string, subexp)
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;
2194 int some_nonuppercase_initial; 2194 int some_nonuppercase_initial;
2195 register int c, prevc; 2195 register int c, prevc;
2235 make_number (search_regs.end[sub])); 2235 make_number (search_regs.end[sub]));
2236 } 2236 }
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
2243 pos = search_regs.start[sub];
2244 last = search_regs.end[sub];
2242 2245
2243 if (NILP (string)) 2246 if (NILP (string))
2244 last = CHAR_TO_BYTE (search_regs.end[sub]); 2247 pos_byte = CHAR_TO_BYTE (pos);
2245 else 2248 else
2246 last = search_regs.end[sub]; 2249 pos_byte = string_char_to_byte (string, pos);
2247
2248 if (NILP (string))
2249 beg = CHAR_TO_BYTE (search_regs.start[sub]);
2250 else
2251 beg = search_regs.start[sub];
2252 2250
2253 prevc = '\n'; 2251 prevc = '\n';
2254 case_action = all_caps; 2252 case_action = all_caps;
2255 2253
2256 /* some_multiletter_word is set nonzero if any original word 2254 /* some_multiletter_word is set nonzero if any original word
2258 some_multiletter_word = 0; 2256 some_multiletter_word = 0;
2259 some_lowercase = 0; 2257 some_lowercase = 0;
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 {
2272 /* Cannot be all caps if any original char is lower case */ 2273 /* Cannot be all caps if any original char is lower case */
2273 2274
2327 int lastpos = 0; 2328 int lastpos = 0;
2328 int lastpos_byte = 0; 2329 int lastpos_byte = 0;
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;
2340 int delbackslash = 0; 2341 int delbackslash = 0;
2341 2342
2423 if (!NILP (literal)) 2424 if (!NILP (literal))
2424 Finsert_and_inherit (1, &newtext); 2425 Finsert_and_inherit (1, &newtext);
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 (),
2441 make_number (search_regs.start[sub] + offset), 2445 make_number (search_regs.start[sub] + offset),
2442 make_number (search_regs.end[sub] + offset)); 2446 make_number (search_regs.end[sub] + offset));