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: IdentityCodingSystem.C /main/1 1996/07/29 16:54:48 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #include "IdentityCodingSystem.h"
37 namespace SP_NAMESPACE {
40 class IdentityDecoder : public Decoder {
42 size_t decode(Char *to, const char *from, size_t fromLen,
44 Boolean convertOffset(unsigned long &offset) const;
47 class IdentityEncoder : public Encoder {
51 void output(Char *, size_t, streambuf *);
52 void output(const Char *, size_t, streambuf *);
54 void allocBuf(size_t);
59 IdentityCodingSystem::IdentityCodingSystem()
63 Decoder *IdentityCodingSystem::makeDecoder() const
65 return new IdentityDecoder;
68 Encoder *IdentityCodingSystem::makeEncoder() const
70 return new IdentityEncoder;
73 Boolean IdentityCodingSystem::isIdentity() const
78 size_t IdentityDecoder::decode(Char *to, const char *from, size_t fromLen,
81 if (sizeof(Char) == sizeof(char) && from == (char *)to) {
82 *rest = from + fromLen;
85 for (size_t n = fromLen; n > 0; n--)
86 *to++ = (unsigned char)*from++; // zero extend
91 Boolean IdentityDecoder::convertOffset(unsigned long &) const
96 IdentityEncoder::IdentityEncoder()
97 : buf_(0), bufSize_(0)
101 IdentityEncoder::~IdentityEncoder()
106 void IdentityEncoder::allocBuf(size_t n)
110 buf_ = new char[bufSize_ = n];
114 // FIXME handle errors from streambuf::sputn
116 void IdentityEncoder::output(Char *s, size_t n, streambuf *sb)
119 if (sizeof(Char) != sizeof(char)) {
121 for (size_t i = 0; i < n; i++) {
122 if (s[i] > UCHAR_MAX) {
125 handleUnencodable(s[i], sb);
136 void IdentityEncoder::output(const Char *s, size_t n, streambuf *sb)
138 if (sizeof(Char) != sizeof(char)) {
141 for (size_t i = 0; i < n; i++) {
142 if (s[i] > UCHAR_MAX) {
145 handleUnencodable(s[i], sb);
148 buf_[j++] = char(s[i]);
153 sb->sputn((const char *)s, n);