1
// Copyright (c) 1994 James Clark
2
// See the file COPYING for copying permission.
8
#include "EUCJPCodingSystem.h"
11
namespace SP_NAMESPACE {
14
class EUCJPDecoder : public Decoder {
17
size_t decode(Char *, const char *, size_t, const char **);
21
class EUCJPEncoder : public Encoder {
24
void output(const Char *, size_t, OutputByteStream *);
27
Decoder *EUCJPCodingSystem::makeDecoder() const
29
return new EUCJPDecoder;
32
Encoder *EUCJPCodingSystem::makeEncoder() const
34
return new EUCJPEncoder;
37
size_t EUCJPDecoder::decode(Char *to, const char *s,
38
size_t slen, const char **rest)
41
const unsigned char *us = (const unsigned char *)s;
48
else if (*us == 0x8e) {
56
else if (*us == 0x8f) {
62
unsigned short n = (*us++ | 0x80) << 8;
71
unsigned short n = *us++ << 8;
76
*rest = (const char *)us;
81
void EUCJPEncoder::output(const Char *s, size_t n, OutputByteStream *sb)
83
for (; n > 0; s++, n--) {
85
unsigned short mask = (unsigned short)(c & 0x8080);
87
sb->sputc((unsigned char)(c & 0xff));
88
else if (mask == 0x8080) {
89
sb->sputc((unsigned char)((c >> 8) & 0xff));
90
sb->sputc((unsigned char)(c & 0xff));
92
else if (mask == 0x0080) {
93
sb->sputc((unsigned char)0x8e);
94
sb->sputc((unsigned char)(c & 0xff));
98
sb->sputc((unsigned char)0x8f);
99
sb->sputc((unsigned char)((c >> 8) & 0xff));
100
sb->sputc((unsigned char)(c & 0x7f));
109
#else /* not SP_MULTI_BYTE */
112
static char non_empty_translation_unit; // sigh
115
#endif /* not SP_MULTI_BYTE */