b299164398454b60b7540c28ac341b91ad727b6a
[oweals/cde.git] / cde / programs / nsgmls / CodingSystem.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
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.
26
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30
31 #include "splib.h"
32 #include "CodingSystem.h"
33 #ifdef SP_SHORT_HEADERS
34 #include <strstrea.h>
35 #else
36 #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
37 #include <strstream>
38 #else
39 #include <strstream.h>
40 #endif
41 #endif
42 #include <string.h>
43 #include <sys/param.h>
44
45 #ifdef SP_NAMESPACE
46 namespace SP_NAMESPACE {
47 #endif
48
49 InputCodingSystem::~InputCodingSystem()
50 {
51 }
52
53 StringC InputCodingSystem::convertIn(const char *s) const
54 {
55   Decoder *decoder = makeDecoder();
56   StringC str;
57   str.resize(strlen(s));
58   str.resize(decoder->decode(&str[0], s, strlen(s), &s));
59   delete decoder;
60   return str;
61 }
62
63 Boolean InputCodingSystem::isIdentity() const
64 {
65   return 0;
66 }
67
68 OutputCodingSystem::~OutputCodingSystem()
69 {
70 }
71
72 unsigned OutputCodingSystem::fixedBytesPerChar() const
73 {
74   return 0;
75 }
76
77 String<char> OutputCodingSystem::convertOut(const StringC &str) const
78 {
79   Encoder *encoder = makeEncoder();
80   strstreambuf stream(MAXPATHLEN);
81   StringC copy(str);
82   encoder->output(copy.data(), copy.size(), &stream);
83   delete encoder;
84   char *s = stream.str();
85 #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
86   String<char> result(s, stream.pcount());
87 #else
88   String<char> result(s, stream.out_waiting());
89 #endif
90   result += '\0';
91   stream.freeze(0);
92 #ifdef __lucid
93   // Workaround lcc bug (3.1p2 with -O -XF).
94   String<char> temp(result);
95   return temp;
96 #else
97   return result;
98 #endif
99 }
100
101 Decoder::Decoder(unsigned minBytesPerChar)
102 : minBytesPerChar_(minBytesPerChar)
103 {
104 }
105
106 Decoder::~Decoder()
107 {
108 }
109
110 Boolean Decoder::convertOffset(unsigned long &) const
111 {
112   return false;
113 }
114
115 Encoder::Encoder()
116 : unencodableHandler_(0)
117 {
118 }
119
120 Encoder::~Encoder()
121 {
122 }
123
124 void Encoder::output(Char *s, size_t n, streambuf *sp)
125 {
126   output((const Char *)s, n, sp);
127 }
128
129 void Encoder::startFile(streambuf *)
130 {
131 }
132
133 #ifdef SP_NAMESPACE
134 }
135 #endif