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"
35 namespace SP_NAMESPACE {
38 class EUCJPDecoder : public Decoder {
41 size_t decode(Char *, const char *, size_t, const char **);
45 class EUCJPEncoder : public Encoder {
48 void output(const Char *, size_t, streambuf *);
51 Decoder *EUCJPCodingSystem::makeDecoder() const
53 return new EUCJPDecoder;
56 Encoder *EUCJPCodingSystem::makeEncoder() const
58 return new EUCJPEncoder;
61 size_t EUCJPDecoder::decode(Char *to, const char *s,
62 size_t slen, const char **rest)
65 const unsigned char *us = (const unsigned char *)s;
72 else if (*us == 0x8e) {
80 else if (*us == 0x8f) {
86 unsigned short n = (*us++ | 0x80) << 8;
95 unsigned short n = *us++ << 8;
100 *rest = (const char *)us;
104 // FIXME handle errors from streambuf::sputc
106 void EUCJPEncoder::output(const Char *s, size_t n, streambuf *sb)
108 for (; n > 0; s++, n--) {
110 unsigned short mask = (unsigned short)(c & 0x8080);
112 sb->sputc(char(c & 0xff));
113 else if (mask == 0x8080) {
114 sb->sputc(char((c >> 8) & 0xff));
115 sb->sputc(char(c & 0xff));
117 else if (mask == 0x0080) {
119 sb->sputc(char(c & 0xff));
124 sb->sputc(char((c >> 8) & 0xff));
125 sb->sputc(char(c & 0x7f));
134 #else /* not SP_MULTI_BYTE */
137 static char non_empty_translation_unit; // sigh
140 #endif /* not SP_MULTI_BYTE */