diff options
author | Kenichi Handa <handa@m17n.org> | 1999-09-03 01:28:42 +0000 |
---|---|---|
committer | Kenichi Handa <handa@m17n.org> | 1999-09-03 01:28:42 +0000 |
commit | e50d9192e8e44fcb053934347636d05a08d67a24 (patch) | |
tree | 7b4a6f11a17cb51f0ea82a1f23ea15574bb79c2b /src/fns.c | |
parent | 197516c20d6a23ba998c657139026b2545c968d9 (diff) | |
download | emacs-e50d9192e8e44fcb053934347636d05a08d67a24.tar.gz |
(count_combining): Use the macro PARSE_MULTIBYTE_SEQ.
(string_char_to_byte): Likewise.
(string_byte_to_char): Likewise.
Diffstat (limited to 'src/fns.c')
-rw-r--r-- | src/fns.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/fns.c b/src/fns.c index 8294d3b38d8..f46a7c32d6c 100644 --- a/src/fns.c +++ b/src/fns.c @@ -526,16 +526,15 @@ count_combining (str, len, i) unsigned char *str; int len, i; { - int j = i - 1; + int j = i - 1, bytes; if (i == 0 || i == len || CHAR_HEAD_P (str[i])) return 0; while (j >= 0 && !CHAR_HEAD_P (str[j])) j--; if (j < 0 || ! BASE_LEADING_CODE_P (str[j])) return 0; - j = i + 1; - while (j < len && ! CHAR_HEAD_P (str[j])) j++; - return j - i; + PARSE_MULTIBYTE_SEQ (str + j, len - j, bytes); + return (bytes <= i - j ? 0 : bytes - (i - j)); } /* This structure holds information of an argument of `concat' that is @@ -898,13 +897,19 @@ string_char_to_byte (string, char_index) { while (best_above > char_index) { - int best_above_byte_saved = --best_above_byte; - - while (best_above_byte > 0 - && !CHAR_HEAD_P (XSTRING (string)->data[best_above_byte])) + unsigned char *pend = XSTRING (string)->data + best_above_byte; + unsigned char *pbeg = pend - best_above_byte; + unsigned char *p = pend - 1; + int bytes; + + while (p > pbeg && !CHAR_HEAD_P (*p)) p--; + PARSE_MULTIBYTE_SEQ (p, pend - p, bytes); + if (bytes == pend - p) + best_above_byte -= bytes; + else if (bytes > pend - p) + best_above_byte -= (pend - p); + else best_above_byte--; - if (!BASE_LEADING_CODE_P (XSTRING (string)->data[best_above_byte])) - best_above_byte = best_above_byte_saved; best_above--; } i = best_above; @@ -964,13 +969,19 @@ string_byte_to_char (string, byte_index) { while (best_above_byte > byte_index) { - int best_above_byte_saved = --best_above_byte; - - while (best_above_byte > 0 - && !CHAR_HEAD_P (XSTRING (string)->data[best_above_byte])) + unsigned char *pend = XSTRING (string)->data + best_above_byte; + unsigned char *pbeg = pend - best_above_byte; + unsigned char *p = pend - 1; + int bytes; + + while (p > pbeg && !CHAR_HEAD_P (*p)) p--; + PARSE_MULTIBYTE_SEQ (p, pend - p, bytes); + if (bytes == pend - p) + best_above_byte -= bytes; + else if (bytes > pend - p) + best_above_byte -= (pend - p); + else best_above_byte--; - if (!BASE_LEADING_CODE_P (XSTRING (string)->data[best_above_byte])) - best_above_byte = best_above_byte_saved; best_above--; } i = best_above; |