From 733eafd8ed4bb3f97193f26e855ed4bf40bc9c23 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 8 Nov 1997 03:05:44 +0000 Subject: [PATCH] (find_charset_in_str): Handle the case that STR contains invalid multibyte-form. --- src/charset.c | 74 +++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/charset.c b/src/charset.c index 56dc15e78da..3241d9b7194 100644 --- a/src/charset.c +++ b/src/charset.c @@ -545,9 +545,7 @@ find_charset_in_str (str, len, charsets, table) int len, *charsets; Lisp_Object table; { - int num = 0; - int cmpcharp = 0; - unsigned char str_work[4], *str_tmp; + register int num = 0, c; if (! CHAR_TABLE_P (table)) table = Qnil; @@ -555,46 +553,52 @@ find_charset_in_str (str, len, charsets, table) while (len > 0) { int bytes, charset; + c = *str; - if (*str == LEADING_CODE_COMPOSITION) + if (c == LEADING_CODE_COMPOSITION) { - str++; - len--; - cmpcharp = 1; - } - else if (CHAR_HEAD_P (str)) - cmpcharp = 0; + int cmpchar_id = str_cmpchar_id (str, len); + GLYPH *glyph; - if (cmpcharp) - { - if (*str == 0xA0) - { - str++; - len--; - str_work[0] = *str & 0x7F; - } - else + if (cmpchar_id > 0) { - bcopy (str, str_work, min (4, len)); - str_work[0] -= 0x20; + struct cmpchar_info *cmpcharp = cmpchar_table[cmpchar_id]; + int i; + + for (i = 0; i < cmpcharp->glyph_len; i++) + { + c = cmpcharp->glyph[i]; + if (!NILP (table)) + { + if ((c = unify_char (table, c, 0, 0, 0)) < 0) + c = cmpcharp->glyph[i]; + } + if ((charset = CHAR_CHARSET (c)) < 0) + charset = CHARSET_ASCII; + if (!charsets[charset]) + { + charsets[charset] = 1; + num += 1; + } + } + str += cmpcharp->len; + len -= cmpcharp->len; + continue; } - str_tmp = str_work; - } - else - str_tmp = str; - - bytes = BYTES_BY_CHAR_HEAD (*str_tmp); - if (NILP (table)) - charset = CHARSET_AT (str_tmp); + charset = CHARSET_ASCII; + bytes = 1; + } else { - int c; - unsigned char c1, c2; - - SPLIT_STRING(str_tmp, bytes, charset, c1, c2); - if ((c = unify_char (table, -1, charset, c1, c2)) >= 0) - charset = CHAR_CHARSET (c); + c = STRING_CHAR_AND_LENGTH (str, len, bytes); + if (! NILP (table)) + { + int c1 = unify_char (table, c, 0, 0, 0); + if (c1 >= 0) + c = c1; + } + charset = CHAR_CHARSET (c); } if (!charsets[charset]) -- 2.39.2