diff options
| author | Kenichi Handa | 2000-03-29 11:31:23 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2000-03-29 11:31:23 +0000 |
| commit | 3bc25e5289d9ef72ed9a8189a3685424d1f9b6ce (patch) | |
| tree | a17d0fb3e1f6eb0c68d1b3f352093e585958254f /src | |
| parent | fdce64ff6db71952454b65c461f26c4d71351870 (diff) | |
| download | emacs-3bc25e5289d9ef72ed9a8189a3685424d1f9b6ce.tar.gz emacs-3bc25e5289d9ef72ed9a8189a3685424d1f9b6ce.zip | |
(Freplace_match): Adjust multibyteness of the current
buffer and NEWTEXT. Free allocated memory before signaling an
error.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/search.c b/src/search.c index 4c877517a5e..eda4199915a 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2434,12 +2434,22 @@ since only regular expressions have distinguished subexpressions.") | |||
| 2434 | int length = STRING_BYTES (XSTRING (newtext)); | 2434 | int length = STRING_BYTES (XSTRING (newtext)); |
| 2435 | unsigned char *substed; | 2435 | unsigned char *substed; |
| 2436 | int substed_alloc_size, substed_len; | 2436 | int substed_alloc_size, substed_len; |
| 2437 | int buf_multibyte = !NILP (current_buffer->enable_multibyte_characters); | ||
| 2438 | int str_multibyte = STRING_MULTIBYTE (newtext); | ||
| 2439 | Lisp_Object rev_tbl; | ||
| 2440 | |||
| 2441 | rev_tbl= (!buf_multibyte && CHAR_TABLE_P (Vnonascii_translation_table) | ||
| 2442 | ? Fchar_table_extra_slot (Vnonascii_translation_table, | ||
| 2443 | make_number (0)) | ||
| 2444 | : Qnil); | ||
| 2437 | 2445 | ||
| 2438 | substed_alloc_size = length * 2 + 100; | 2446 | substed_alloc_size = length * 2 + 100; |
| 2439 | substed = (unsigned char *) xmalloc (substed_alloc_size + 1); | 2447 | substed = (unsigned char *) xmalloc (substed_alloc_size + 1); |
| 2440 | substed_len = 0; | 2448 | substed_len = 0; |
| 2441 | 2449 | ||
| 2442 | /* Go thru NEWTEXT, producing the actual text to insert in SUBSTED. */ | 2450 | /* Go thru NEWTEXT, producing the actual text to insert in |
| 2451 | SUBSTED while adjusting multibyteness to that of the current | ||
| 2452 | buffer. */ | ||
| 2443 | 2453 | ||
| 2444 | for (pos_byte = 0, pos = 0; pos_byte < length;) | 2454 | for (pos_byte = 0, pos = 0; pos_byte < length;) |
| 2445 | { | 2455 | { |
| @@ -2448,7 +2458,19 @@ since only regular expressions have distinguished subexpressions.") | |||
| 2448 | int add_len; | 2458 | int add_len; |
| 2449 | int idx = -1; | 2459 | int idx = -1; |
| 2450 | 2460 | ||
| 2451 | FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | 2461 | if (str_multibyte) |
| 2462 | { | ||
| 2463 | FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | ||
| 2464 | if (!buf_multibyte) | ||
| 2465 | c = multibyte_char_to_unibyte (c, rev_tbl); | ||
| 2466 | } | ||
| 2467 | else | ||
| 2468 | { | ||
| 2469 | /* Note that we don't have to increment POS. */ | ||
| 2470 | c = XSTRING (newtext)->data[pos_byte++]; | ||
| 2471 | if (buf_multibyte) | ||
| 2472 | c = unibyte_char_to_multibyte (c); | ||
| 2473 | } | ||
| 2452 | 2474 | ||
| 2453 | /* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED, | 2475 | /* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED, |
| 2454 | or set IDX to a match index, which means put that part | 2476 | or set IDX to a match index, which means put that part |
| @@ -2456,7 +2478,19 @@ since only regular expressions have distinguished subexpressions.") | |||
| 2456 | 2478 | ||
| 2457 | if (c == '\\') | 2479 | if (c == '\\') |
| 2458 | { | 2480 | { |
| 2459 | FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | 2481 | if (str_multibyte) |
| 2482 | { | ||
| 2483 | FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | ||
| 2484 | if (!buf_multibyte && !SINGLE_BYTE_CHAR_P (c)) | ||
| 2485 | c = multibyte_char_to_unibyte (c, rev_tbl); | ||
| 2486 | } | ||
| 2487 | else | ||
| 2488 | { | ||
| 2489 | c = XSTRING (newtext)->data[pos_byte++]; | ||
| 2490 | if (buf_multibyte) | ||
| 2491 | c = unibyte_char_to_multibyte (c); | ||
| 2492 | } | ||
| 2493 | |||
| 2460 | if (c == '&') | 2494 | if (c == '&') |
| 2461 | idx = sub; | 2495 | idx = sub; |
| 2462 | else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') | 2496 | else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') |
| @@ -2467,7 +2501,10 @@ since only regular expressions have distinguished subexpressions.") | |||
| 2467 | else if (c == '\\') | 2501 | else if (c == '\\') |
| 2468 | add_len = 1, add_stuff = "\\"; | 2502 | add_len = 1, add_stuff = "\\"; |
| 2469 | else | 2503 | else |
| 2470 | error ("Invalid use of `\\' in replacement text"); | 2504 | { |
| 2505 | xfree (substed); | ||
| 2506 | error ("Invalid use of `\\' in replacement text"); | ||
| 2507 | } | ||
| 2471 | } | 2508 | } |
| 2472 | else | 2509 | else |
| 2473 | { | 2510 | { |