3065 some functions in the tcp module can be static
[unleashed.git] / usr / src / cmd / man / src / util / nsgmls.src / lib / Big5CodingSystem.cxx
blobc6006b4354dd3706fe9c2d7a72311e14db94dcea
1 // Copyright (c) 1997 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
5 #include "splib.h"
7 #ifdef SP_MULTI_BYTE
9 #include "Big5CodingSystem.h"
11 #ifdef SP_NAMESPACE
12 namespace SP_NAMESPACE {
13 #endif
15 class Big5Decoder : public Decoder {
16 public:
17 Big5Decoder() { }
18 size_t decode(Char *, const char *, size_t, const char **);
19 private:
22 class Big5Encoder : public Encoder {
23 public:
24 Big5Encoder() { }
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)
45 Char *start = to;
46 const unsigned char *us = (const unsigned char *)s;
47 while (slen > 0) {
48 if (!(*us & 0x80)) {
49 *to++ = *us++;
50 slen--;
52 else {
53 if (slen < 2)
54 break;
55 slen -= 2;
56 unsigned short n = *us++ << 8;
57 n |= *us++;
58 *to++ = n;
61 *rest = (const char *)us;
62 return to - start;
65 void Big5Encoder::output(const Char *s, size_t n, OutputByteStream *sb)
67 for (; n > 0; s++, n--) {
68 Char c = *s;
69 if (c < 0x80)
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));
75 else
76 handleUnencodable(c, sb);
80 #ifdef SP_NAMESPACE
82 #endif
84 #else /* not SP_MULTI_BYTE */
86 #ifndef __GNUG__
87 static char non_empty_translation_unit; // sigh
88 #endif
90 #endif /* not SP_MULTI_BYTE */