aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2002-09-03 04:06:54 +0000
committerKenichi Handa2002-09-03 04:06:54 +0000
commit43c4748349284a134b17c92077a14db81b92166b (patch)
treec41064b4a5c56e4689ebf20a3f59863858a2a741 /src
parent9281d0779766a39f743240e33dd46a1accf0f7fa (diff)
downloademacs-43c4748349284a134b17c92077a14db81b92166b.tar.gz
emacs-43c4748349284a134b17c92077a14db81b92166b.zip
(LEADING_CODE_LATIN_1_MIN)
(LEADING_CODE_LATIN_1_MAX): New macros. (unibyte_to_multibyte_table): Extern it. (unibyte_char_to_multibyte): New macro. (MAKE_CHAR_MULTIBYTE): Use unibyte_to_multibyte_table. (CHAR_LEADING_CODE): New macro. (FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE): New macro.
Diffstat (limited to 'src')
-rw-r--r--src/character.h62
1 files changed, 51 insertions, 11 deletions
diff --git a/src/character.h b/src/character.h
index f603140e769..b2ddccde542 100644
--- a/src/character.h
+++ b/src/character.h
@@ -51,6 +51,10 @@ Boston, MA 02111-1307, USA. */
51#define MAX_4_BYTE_CHAR 0x1FFFFF 51#define MAX_4_BYTE_CHAR 0x1FFFFF
52#define MAX_5_BYTE_CHAR 0x3FFF7F 52#define MAX_5_BYTE_CHAR 0x3FFF7F
53 53
54/* Leading code range of Latin-1 chars. */
55#define LEADING_CODE_LATIN_1_MIN 0xC2
56#define LEADING_CODE_LATIN_1_MAX 0xC3
57
54/* Nonzero iff C is a character that corresponds to a raw 8-bit 58/* Nonzero iff C is a character that corresponds to a raw 8-bit
55 byte. */ 59 byte. */
56#define CHAR_BYTE8_P(c) ((c) > MAX_5_BYTE_CHAR) 60#define CHAR_BYTE8_P(c) ((c) > MAX_5_BYTE_CHAR)
@@ -68,21 +72,24 @@ Boston, MA 02111-1307, USA. */
68 that corresponds to a raw 8-bit byte. */ 72 that corresponds to a raw 8-bit byte. */
69#define CHAR_BYTE8_HEAD_P(byte) ((byte) == 0xC0 || (byte) == 0xC1) 73#define CHAR_BYTE8_HEAD_P(byte) ((byte) == 0xC0 || (byte) == 0xC1)
70 74
71/* If C is not ASCII, make it unibyte. */ 75/* Mapping table from unibyte chars to multibyte chars. */
72 76extern int unibyte_to_multibyte_table[256];
73#define MAKE_CHAR_UNIBYTE(c) \
74 if (! ASCII_CHAR_P (c)) \
75 c = multibyte_char_to_unibyte (c, Qnil); \
76 else
77 77
78/* Convert the unibyte character C to the corresponding multibyte
79 character. If C can't be converted, return C. */
80#define unibyte_char_to_multibyte(c) \
81 ((c) < 256 ? unibyte_to_multibyte_table[(c)] : (c))
78 82
79/* If C is not ASCII, make it multibyte. */ 83/* If C is not ASCII, make it unibyte. */
84#define MAKE_CHAR_UNIBYTE(c) \
85 do { \
86 if (! ASCII_CHAR_P (c)) \
87 c = CHAR_TO_BYTE8 (c); \
88 } while (0)
80 89
81#define MAKE_CHAR_MULTIBYTE(c) \
82 if (! ASCII_CHAR_P (c)) \
83 c = unibyte_char_to_multibyte (c); \
84 else
85 90
91/* If C is not ASCII, make it multibyte. It assumes C < 256. */
92#define MAKE_CHAR_MULTIBYTE(c) ((c) = unibyte_to_multibyte_table[(c)])
86 93
87/* This is the maximum byte length of multibyte form. */ 94/* This is the maximum byte length of multibyte form. */
88#define MAX_MULTIBYTE_LENGTH 5 95#define MAX_MULTIBYTE_LENGTH 5
@@ -126,6 +133,17 @@ Boston, MA 02111-1307, USA. */
126 : (c) <= MAX_5_BYTE_CHAR ? 5 \ 133 : (c) <= MAX_5_BYTE_CHAR ? 5 \
127 : 2) 134 : 2)
128 135
136
137/* Return the leading code of multibyte form of C. */
138#define CHAR_LEADING_CODE(c) \
139 ((c) <= MAX_1_BYTE_CHAR ? c \
140 : (c) <= MAX_2_BYTE_CHAR ? (0xC0 | ((c) >> 6)) \
141 : (c) <= MAX_3_BYTE_CHAR ? (0xE0 | ((c) >> 12)) \
142 : (c) <= MAX_4_BYTE_CHAR ? (0xF0 | ((c) >> 18)) \
143 : (c) <= MAX_5_BYTE_CHAR ? 0xF8 \
144 : (0xC0 | (((c) >> 6) & 0x01)))
145
146
129/* Store multibyte form of the character C in P. The caller should 147/* Store multibyte form of the character C in P. The caller should
130 allocate at least MAX_MULTIBYTE_LENGTH bytes area at P in advance. 148 allocate at least MAX_MULTIBYTE_LENGTH bytes area at P in advance.
131 Returns the length of the multibyte form. */ 149 Returns the length of the multibyte form. */
@@ -337,6 +355,28 @@ Boston, MA 02111-1307, USA. */
337 } \ 355 } \
338 else 356 else
339 357
358/* Like FETCH_STRING_CHAR_ADVANCE */
359
360#define FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \
361 if (1) \
362 { \
363 CHARIDX++; \
364 if (STRING_MULTIBYTE (STRING)) \
365 { \
366 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \
367 int len; \
368 \
369 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \
370 BYTEIDX += len; \
371 } \
372 else \
373 { \
374 OUTPUT = XSTRING (STRING)->data[BYTEIDX++]; \
375 MAKE_CHAR_MULTIBYTE (OUTPUT); \
376 } \
377 } \
378 else
379
340 380
341/* Like FETCH_STRING_CHAR_ADVANCE but assumes STRING is multibyte. */ 381/* Like FETCH_STRING_CHAR_ADVANCE but assumes STRING is multibyte. */
342 382