2 * big5enc.c - multibyte encoding of Big5
11 * Big5 has no associated data, so `charset' may be ignored.
14 static void read_big5(charset_spec
const *charset
, long int input_chr
,
16 void (*emit
)(void *ctx
, long int output
), void *emitctx
)
21 * For reading Big5, state->s0 simply contains the single
22 * stored lead byte when we are half way through a double-byte
23 * character, or 0 if we aren't.
27 if (input_chr
>= 0xA1 && input_chr
<= 0xFE) {
29 * Lead byte. Just store it.
31 state
->s0
= input_chr
;
34 * Anything else we pass straight through unchanged.
36 emit(emitctx
, input_chr
);
40 * We have a stored lead byte. We expect a valid followup
43 if ((input_chr
>= 0x40 && input_chr
<= 0x7E) ||
44 (input_chr
>= 0xA1 && input_chr
<= 0xFE)) {
45 emit(emitctx
, big5_to_unicode(state
->s0
- 0xA1, input_chr
- 0x40));
54 * Big5 is a stateless multi-byte encoding (in the sense that just
55 * after any character has been completed, the state is always the
56 * same); hence when writing it, there is no need to use the
60 static int write_big5(charset_spec
const *charset
, long int input_chr
,
62 void (*emit
)(void *ctx
, long int output
), void *emitctx
)
68 return TRUE
; /* stateless; no cleanup required */
70 if (input_chr
< 0x80) {
71 emit(emitctx
, input_chr
);
75 if (unicode_to_big5(input_chr
, &r
, &c
)) {
76 emit(emitctx
, r
+ 0xA1);
77 emit(emitctx
, c
+ 0x40);
85 const charset_spec charset_CS_BIG5
= {
86 CS_BIG5
, read_big5
, write_big5
, NULL
89 #else /* ENUM_CHARSETS */
93 #endif /* ENUM_CHARSETS */