2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: EUCJPCodingSystem.C /main/1 1996/07/29 16:49:22 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
31 #include "EUCJPCodingSystem.h"
32 #if defined(linux) || defined(CSRG_BASED)
39 namespace SP_NAMESPACE {
42 class EUCJPDecoder : public Decoder {
45 size_t decode(Char *, const char *, size_t, const char **);
49 class EUCJPEncoder : public Encoder {
52 void output(const Char *, size_t, streambuf *);
55 Decoder *EUCJPCodingSystem::makeDecoder() const
57 return new EUCJPDecoder;
60 Encoder *EUCJPCodingSystem::makeEncoder() const
62 return new EUCJPEncoder;
65 size_t EUCJPDecoder::decode(Char *to, const char *s,
66 size_t slen, const char **rest)
69 const unsigned char *us = (const unsigned char *)s;
76 else if (*us == 0x8e) {
84 else if (*us == 0x8f) {
90 unsigned short n = (*us++ | 0x80) << 8;
99 unsigned short n = *us++ << 8;
104 *rest = (const char *)us;
108 // FIXME handle errors from streambuf::sputc
110 void EUCJPEncoder::output(const Char *s, size_t n, streambuf *sb)
112 for (; n > 0; s++, n--) {
114 unsigned short mask = (unsigned short)(c & 0x8080);
116 sb->sputc(char(c & 0xff));
117 else if (mask == 0x8080) {
118 sb->sputc(char((c >> 8) & 0xff));
119 sb->sputc(char(c & 0xff));
121 else if (mask == 0x0080) {
123 sb->sputc(char(c & 0xff));
128 sb->sputc(char((c >> 8) & 0xff));
129 sb->sputc(char(c & 0x7f));
138 #else /* not SP_MULTI_BYTE */
141 static char non_empty_translation_unit; // sigh
144 #endif /* not SP_MULTI_BYTE */