1 // Copyright (c) 1997 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
9 #include "Big5CodingSystem.h"
12 namespace SP_NAMESPACE
{
15 class Big5Decoder
: public Decoder
{
18 size_t decode(Char
*, const char *, size_t, const char **);
22 class Big5Encoder
: public Encoder
{
25 void output(const Char
*, size_t, OutputByteStream
*);
26 void output(Char
*tmp_char
, size_t tmp_size_t
, OutputByteStream
*tmp_obs
) {
27 output((const Char
*)tmp_char
, (size_t) tmp_size_t
, (OutputByteStream
*)tmp_obs
);
32 Decoder
*Big5CodingSystem::makeDecoder() const
34 return new Big5Decoder
;
37 Encoder
*Big5CodingSystem::makeEncoder() const
39 return new Big5Encoder
;
42 size_t Big5Decoder::decode(Char
*to
, const char *s
,
43 size_t slen
, const char **rest
)
46 const unsigned char *us
= (const unsigned char *)s
;
56 unsigned short n
= *us
++ << 8;
61 *rest
= (const char *)us
;
65 void Big5Encoder::output(const Char
*s
, size_t n
, OutputByteStream
*sb
)
67 for (; n
> 0; s
++, n
--) {
70 sb
->sputc((unsigned char)c
);
71 else if (c
& 0x8000) {
72 sb
->sputc((unsigned char)(c
>> 8));
73 sb
->sputc((unsigned char)(c
& 0xff));
76 handleUnencodable(c
, sb
);
84 #else /* not SP_MULTI_BYTE */
87 static char non_empty_translation_unit
; // sigh
90 #endif /* not SP_MULTI_BYTE */