2 * sbcs.c - routines to handle single-byte character sets.
9 * The charset_spec for any single-byte character set should
10 * provide read_sbcs() as its read function, and its `data' field
11 * should be a wchar_t string constant containing the 256 entries
12 * of the translation table.
15 long int sbcs_to_unicode(const struct sbcs_data
*sd
, long int input_chr
)
17 return sd
->sbcs2ucs
[input_chr
];
20 void read_sbcs(charset_spec
const *charset
, long int input_chr
,
22 void (*emit
)(void *ctx
, long int output
), void *emitctx
)
24 const struct sbcs_data
*sd
= charset
->data
;
28 emit(emitctx
, sbcs_to_unicode(sd
, input_chr
));
31 long int sbcs_from_unicode(const struct sbcs_data
*sd
, long int input_chr
)
36 * Binary-search in the ucs2sbcs table.
43 if (input_chr
< (long int)sd
->sbcs2ucs
[c
])
45 else if (input_chr
> (long int)sd
->sbcs2ucs
[c
])
54 int write_sbcs(charset_spec
const *charset
, long int input_chr
,
56 void (*emit
)(void *ctx
, long int output
), void *emitctx
)
58 const struct sbcs_data
*sd
= charset
->data
;
64 return TRUE
; /* stateless; no cleanup required */
66 ret
= sbcs_from_unicode(sd
, input_chr
);