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: CodingSystem.C /main/2 1996/08/08 12:10:51 mgreess $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "CodingSystem.h"
33 #ifdef SP_SHORT_HEADERS
36 #if defined(linux) || defined(CSRG_BASED)
39 #include <strstream.h>
43 #include <sys/param.h>
46 namespace SP_NAMESPACE {
49 InputCodingSystem::~InputCodingSystem()
53 StringC InputCodingSystem::convertIn(const char *s) const
55 Decoder *decoder = makeDecoder();
57 str.resize(strlen(s));
58 str.resize(decoder->decode(&str[0], s, strlen(s), &s));
63 Boolean InputCodingSystem::isIdentity() const
68 OutputCodingSystem::~OutputCodingSystem()
72 unsigned OutputCodingSystem::fixedBytesPerChar() const
77 String<char> OutputCodingSystem::convertOut(const StringC &str) const
79 Encoder *encoder = makeEncoder();
80 strstreambuf stream(MAXPATHLEN);
82 encoder->output(copy.data(), copy.size(), &stream);
84 char *s = stream.str();
85 #if defined(linux) || defined(CSRG_BASED)
86 String<char> result(s, stream.pcount());
88 String<char> result(s, stream.out_waiting());
93 // Workaround lcc bug (3.1p2 with -O -XF).
94 String<char> temp(result);
101 Decoder::Decoder(unsigned minBytesPerChar)
102 : minBytesPerChar_(minBytesPerChar)
110 Boolean Decoder::convertOffset(unsigned long &) const
116 : unencodableHandler_(0)
124 void Encoder::output(Char *s, size_t n, streambuf *sp)
126 output((const Char *)s, n, sp);
129 void Encoder::startFile(streambuf *)