diff options
| author | Kenichi Handa | 2005-02-01 23:49:46 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2005-02-01 23:49:46 +0000 |
| commit | f98a8aa964088ab816829eacd5812b413330e20c (patch) | |
| tree | a195904426e3e93537ad7ee20a523b27b9ee1c27 /src | |
| parent | 7077904e6b5f65c6758d9b7b1d092fc5579d4317 (diff) | |
| download | emacs-f98a8aa964088ab816829eacd5812b413330e20c.tar.gz emacs-f98a8aa964088ab816829eacd5812b413330e20c.zip | |
(casify_object): Enable changing characters of
different byte length.
(casify_region): Fix loop condition, args to replace_range_2, and
update opoint_byte.
Diffstat (limited to 'src')
| -rw-r--r-- | src/casefiddle.c | 86 |
1 files changed, 28 insertions, 58 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c index ae4888088bd..4505f477c90 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* GNU Emacs case conversion functions. | 1 | /* GNU Emacs case conversion functions. |
| 2 | Copyright (C) 1985,94,97,98,99, 2001, 2002, 2004 | 2 | Copyright (C) 1985,94,97,98,99, 2001, 2002, 2004, 2005 |
| 3 | Free Software Foundation, Inc. | 3 | Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| @@ -73,71 +73,38 @@ casify_object (flag, obj) | |||
| 73 | if (STRINGP (obj)) | 73 | if (STRINGP (obj)) |
| 74 | { | 74 | { |
| 75 | int multibyte = STRING_MULTIBYTE (obj); | 75 | int multibyte = STRING_MULTIBYTE (obj); |
| 76 | int n; | ||
| 76 | 77 | ||
| 77 | obj = Fcopy_sequence (obj); | 78 | obj = Fcopy_sequence (obj); |
| 78 | len = SBYTES (obj); | 79 | len = SBYTES (obj); |
| 79 | 80 | ||
| 80 | /* Scan all single-byte characters from start of string. */ | 81 | /* I counts bytes, and N counts chars. */ |
| 81 | for (i = 0; i < len;) | 82 | for (i = n = 0; i < len; n++) |
| 82 | { | 83 | { |
| 84 | int from_len = 1, to_len = 1; | ||
| 85 | |||
| 83 | c = SREF (obj, i); | 86 | c = SREF (obj, i); |
| 84 | 87 | ||
| 85 | if (multibyte && c >= 0x80) | 88 | if (multibyte && c >= 0x80) |
| 86 | /* A multibyte character can't be handled in this | 89 | c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i, len -i, from_len); |
| 87 | simple loop. */ | ||
| 88 | break; | ||
| 89 | if (inword && flag != CASE_CAPITALIZE_UP) | 90 | if (inword && flag != CASE_CAPITALIZE_UP) |
| 90 | c = DOWNCASE (c); | 91 | c = DOWNCASE (c); |
| 91 | else if (!UPPERCASEP (c) | 92 | else if (!UPPERCASEP (c) |
| 92 | && (!inword || flag != CASE_CAPITALIZE_UP)) | 93 | && (!inword || flag != CASE_CAPITALIZE_UP)) |
| 93 | c = UPCASE1 (c); | 94 | c = UPCASE1 (c); |
| 94 | /* If this char won't fit in a single-byte string. | 95 | if (ASCII_BYTE_P (c) || (! multibyte && SINGLE_BYTE_CHAR_P (c))) |
| 95 | fall out to the multibyte case. */ | 96 | SSET (obj, i, c); |
| 96 | if (multibyte ? ! ASCII_BYTE_P (c) | 97 | else |
| 97 | : ! SINGLE_BYTE_CHAR_P (c)) | ||
| 98 | break; | ||
| 99 | |||
| 100 | SSET (obj, i, c); | ||
| 101 | if ((int) flag >= (int) CASE_CAPITALIZE) | ||
| 102 | inword = SYNTAX (c) == Sword; | ||
| 103 | i++; | ||
| 104 | } | ||
| 105 | |||
| 106 | /* If we didn't do the whole string as single-byte, | ||
| 107 | scan the rest in a more complex way. */ | ||
| 108 | if (i < len) | ||
| 109 | { | ||
| 110 | /* The work is not yet finished because of a multibyte | ||
| 111 | character just encountered. */ | ||
| 112 | int fromlen, j_byte = i; | ||
| 113 | char *buf; | ||
| 114 | int bufsize; | ||
| 115 | USE_SAFE_ALLOCA; | ||
| 116 | |||
| 117 | bufsize = (len - i) * MAX_MULTIBYTE_LENGTH + i; | ||
| 118 | SAFE_ALLOCA (buf, char *, bufsize); | ||
| 119 | |||
| 120 | /* Copy data already handled. */ | ||
| 121 | bcopy (SDATA (obj), buf, i); | ||
| 122 | |||
| 123 | /* From now on, I counts bytes. */ | ||
| 124 | while (i < len) | ||
| 125 | { | 98 | { |
| 126 | c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i, | 99 | to_len = CHAR_BYTES (c); |
| 127 | len - i, fromlen); | 100 | if (from_len == to_len) |
| 128 | if (inword && flag != CASE_CAPITALIZE_UP) | 101 | CHAR_STRING (c, SDATA (obj) + i); |
| 129 | c = DOWNCASE (c); | 102 | else |
| 130 | else if (!UPPERCASEP (c) | 103 | Faset (obj, make_number (n), make_number (c)); |
| 131 | && (!inword || flag != CASE_CAPITALIZE_UP)) | ||
| 132 | c = UPCASE1 (c); | ||
| 133 | i += fromlen; | ||
| 134 | j_byte += CHAR_STRING (c, buf + j_byte); | ||
| 135 | if ((int) flag >= (int) CASE_CAPITALIZE) | ||
| 136 | inword = SYNTAX (c) == Sword; | ||
| 137 | } | 104 | } |
| 138 | obj = make_multibyte_string (buf, SCHARS (obj), | 105 | if ((int) flag >= (int) CASE_CAPITALIZE) |
| 139 | j_byte); | 106 | inword = SYNTAX (c) == Sword; |
| 140 | SAFE_FREE (); | 107 | i += to_len; |
| 141 | } | 108 | } |
| 142 | return obj; | 109 | return obj; |
| 143 | } | 110 | } |
| @@ -253,7 +220,7 @@ casify_region (flag, b, e) | |||
| 253 | int opoint_byte = PT_BYTE; | 220 | int opoint_byte = PT_BYTE; |
| 254 | int c2; | 221 | int c2; |
| 255 | 222 | ||
| 256 | while (i < end_byte) | 223 | while (start < end) |
| 257 | { | 224 | { |
| 258 | if ((c = FETCH_BYTE (i)) >= 0x80) | 225 | if ((c = FETCH_BYTE (i)) >= 0x80) |
| 259 | c = FETCH_MULTIBYTE_CHAR (i); | 226 | c = FETCH_MULTIBYTE_CHAR (i); |
| @@ -281,12 +248,15 @@ casify_region (flag, b, e) | |||
| 281 | FETCH_BYTE (i + j) = str[j]; | 248 | FETCH_BYTE (i + j) = str[j]; |
| 282 | } | 249 | } |
| 283 | else | 250 | else |
| 284 | /* Replace one character with the other, | 251 | { |
| 285 | keeping text properties the same. */ | 252 | /* Replace one character with the other, |
| 286 | replace_range_2 (start + 1, i + tolen, | 253 | keeping text properties the same. */ |
| 287 | start + 2, i + tolen + fromlen, | 254 | replace_range_2 (start, i, |
| 288 | str, 1, tolen, | 255 | start + 1, i + fromlen, |
| 289 | 0); | 256 | str, 1, tolen, |
| 257 | 1); | ||
| 258 | opoint_byte += tolen - fromlen; | ||
| 259 | } | ||
| 290 | } | 260 | } |
| 291 | if ((int) flag >= (int) CASE_CAPITALIZE) | 261 | if ((int) flag >= (int) CASE_CAPITALIZE) |
| 292 | inword = SYNTAX (c2) == Sword; | 262 | inword = SYNTAX (c2) == Sword; |