diff options
| author | Richard M. Stallman | 1998-01-09 22:58:16 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-01-09 22:58:16 +0000 |
| commit | 5245463a5c37189f5517caca8574ee127ec2e1f4 (patch) | |
| tree | f1c56847038443d7922ac611ac7bded945857d9a /src | |
| parent | 7b935f718bbe58889413f2ca55107c92a7bb2038 (diff) | |
| download | emacs-5245463a5c37189f5517caca8574ee127ec2e1f4.tar.gz emacs-5245463a5c37189f5517caca8574ee127ec2e1f4.zip | |
(casify_object): Scan string by bytes and chars.
Use make_multibyte_string.
Diffstat (limited to 'src')
| -rw-r--r-- | src/casefiddle.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c index 2ca61ab51ec..8768ad1fd8a 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c | |||
| @@ -57,15 +57,19 @@ casify_object (flag, obj) | |||
| 57 | } | 57 | } |
| 58 | return obj; | 58 | return obj; |
| 59 | } | 59 | } |
| 60 | |||
| 60 | if (STRINGP (obj)) | 61 | if (STRINGP (obj)) |
| 61 | { | 62 | { |
| 62 | int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 63 | int multibyte = STRING_MULTIBYTE (obj); |
| 63 | 64 | ||
| 64 | obj = Fcopy_sequence (obj); | 65 | obj = Fcopy_sequence (obj); |
| 65 | len = XSTRING (obj)->size; | 66 | len = XSTRING (obj)->size_byte; |
| 66 | for (i = 0; i < len; i++) | 67 | |
| 68 | /* Scan all single-byte characters from start of string. */ | ||
| 69 | for (i = 0; i < len;) | ||
| 67 | { | 70 | { |
| 68 | c = XSTRING (obj)->data[i]; | 71 | c = XSTRING (obj)->data[i]; |
| 72 | |||
| 69 | if (multibyte && c >= 0x80) | 73 | if (multibyte && c >= 0x80) |
| 70 | /* A multibyte character can't be handled in this | 74 | /* A multibyte character can't be handled in this |
| 71 | simple loop. */ | 75 | simple loop. */ |
| @@ -75,15 +79,25 @@ casify_object (flag, obj) | |||
| 75 | else if (!UPPERCASEP (c) | 79 | else if (!UPPERCASEP (c) |
| 76 | && (!inword || flag != CASE_CAPITALIZE_UP)) | 80 | && (!inword || flag != CASE_CAPITALIZE_UP)) |
| 77 | c = UPCASE1 (c); | 81 | c = UPCASE1 (c); |
| 82 | /* If this char won't fit in a single-byte string. | ||
| 83 | fall out to the multibyte case. */ | ||
| 84 | if (multibyte ? ! ASCII_BYTE_P (c) | ||
| 85 | : ! SINGLE_BYTE_CHAR_P (c)) | ||
| 86 | break; | ||
| 87 | |||
| 78 | XSTRING (obj)->data[i] = c; | 88 | XSTRING (obj)->data[i] = c; |
| 79 | if ((int) flag >= (int) CASE_CAPITALIZE) | 89 | if ((int) flag >= (int) CASE_CAPITALIZE) |
| 80 | inword = SYNTAX (c) == Sword; | 90 | inword = SYNTAX (c) == Sword; |
| 91 | i++; | ||
| 81 | } | 92 | } |
| 93 | |||
| 94 | /* If we didn't do the whole string as single-byte, | ||
| 95 | scan the rest in a more complex way. */ | ||
| 82 | if (i < len) | 96 | if (i < len) |
| 83 | { | 97 | { |
| 84 | /* The work is not yet finished because of a multibyte | 98 | /* The work is not yet finished because of a multibyte |
| 85 | character just encountered. */ | 99 | character just encountered. */ |
| 86 | int fromlen, tolen, j = i; | 100 | int fromlen, tolen, j = i, j_byte = i; |
| 87 | char *buf | 101 | char *buf |
| 88 | = (char *) alloca ((len - i) * MAX_LENGTH_OF_MULTI_BYTE_FORM | 102 | = (char *) alloca ((len - i) * MAX_LENGTH_OF_MULTI_BYTE_FORM |
| 89 | + i); | 103 | + i); |
| @@ -92,6 +106,7 @@ casify_object (flag, obj) | |||
| 92 | /* Copy data already handled. */ | 106 | /* Copy data already handled. */ |
| 93 | bcopy (XSTRING (obj)->data, buf, i); | 107 | bcopy (XSTRING (obj)->data, buf, i); |
| 94 | 108 | ||
| 109 | /* From now on, I counts bytes. */ | ||
| 95 | while (i < len) | 110 | while (i < len) |
| 96 | { | 111 | { |
| 97 | c = STRING_CHAR_AND_LENGTH (XSTRING (obj)->data + i, | 112 | c = STRING_CHAR_AND_LENGTH (XSTRING (obj)->data + i, |
| @@ -102,13 +117,14 @@ casify_object (flag, obj) | |||
| 102 | && (!inword || flag != CASE_CAPITALIZE_UP)) | 117 | && (!inword || flag != CASE_CAPITALIZE_UP)) |
| 103 | c = UPCASE1 (c); | 118 | c = UPCASE1 (c); |
| 104 | tolen = CHAR_STRING (c, workbuf, str); | 119 | tolen = CHAR_STRING (c, workbuf, str); |
| 105 | bcopy (str, buf + j, tolen); | 120 | bcopy (str, buf + j_byte, tolen); |
| 106 | i += fromlen; | 121 | i += fromlen; |
| 107 | j += tolen; | 122 | j++; |
| 123 | j_byte += tolen; | ||
| 108 | if ((int) flag >= (int) CASE_CAPITALIZE) | 124 | if ((int) flag >= (int) CASE_CAPITALIZE) |
| 109 | inword = SYNTAX (c) == Sword; | 125 | inword = SYNTAX (c) == Sword; |
| 110 | } | 126 | } |
| 111 | obj = make_string (buf, j); | 127 | obj = make_multibyte_string (buf, j, j_byte); |
| 112 | } | 128 | } |
| 113 | return obj; | 129 | return obj; |
| 114 | } | 130 | } |