# HG changeset patch # User Kenichi Handa # Date 1102318916 0 # Node ID 73c7169fe4fffd04a960b6183535843f9b2687fb # Parent d42c7860cd330d984ff210ada142ac6f819cfce8 (casify_region): Handle changes in byte-length using replace_range_2 (sync to HEAD). diff -r d42c7860cd33 -r 73c7169fe4ff src/casefiddle.c --- a/src/casefiddle.c Wed Nov 24 00:45:25 2004 +0000 +++ b/src/casefiddle.c Mon Dec 06 07:41:56 2004 +0000 @@ -236,21 +236,29 @@ } else if (ASCII_CHAR_P (c2) && ASCII_CHAR_P (c)) FETCH_BYTE (start_byte) = c; - else if (len == CHAR_BYTES (c)) + else { + int tolen = CHAR_BYTES (c); int j; unsigned char str[MAX_MULTIBYTE_LENGTH]; CHAR_STRING (c, str); - for (j = 0; j < len; ++j) - FETCH_BYTE (start_byte + j) = str[j]; - } - else - { - TEMP_SET_PT_BOTH (start, start_byte); - del_range_2 (start, start_byte, start + 1, start_byte + len, 0); - insert_char (c); - len = CHAR_BYTES (c); + if (len == tolen) + { + /* Length is unchanged. */ + for (j = 0; j < len; ++j) + FETCH_BYTE (start_byte + j) = str[j]; + } + else + { + /* Replace one character with the other, + keeping text properties the same. */ + replace_range_2 (start, start_byte, + start + 1, start_byte + len, + str, 1, tolen, + 0); + len = tolen; + } } } start++;