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.h /main/1 1996/07/29 16:48:04 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef CodingSystem_INCLUDED
28 #define CodingSystem_INCLUDED 1
47 namespace SP_NAMESPACE {
50 class SP_API Decoder {
52 Decoder(unsigned minBytesPerChar = 1);
54 virtual size_t decode(Char *, const char *, size_t, const char **) = 0;
55 virtual Boolean convertOffset(unsigned long &offset) const;
56 // Decoder assumes that for every decoded Char there must be at least
57 // minBytesPerChar bytes
58 unsigned minBytesPerChar() const;
60 unsigned minBytesPerChar_;
64 class SP_API Encoder {
66 class SP_API Handler {
68 virtual void handleUnencodable(Char, streambuf *) = 0;
72 virtual void output(const Char *, size_t, streambuf *) = 0;
73 // This outputs a byte order mark with Unicode.
74 virtual void startFile(streambuf *);
75 virtual void output(Char *, size_t, streambuf *);
76 void setUnencodableHandler(Handler *);
78 void handleUnencodable(Char, streambuf *);
80 Handler *unencodableHandler_;
83 class SP_API InputCodingSystem {
85 virtual ~InputCodingSystem();
86 virtual Decoder *makeDecoder() const = 0;
87 StringC convertIn(const char *) const;
88 virtual Boolean isIdentity() const;
91 class SP_API OutputCodingSystem {
93 virtual ~OutputCodingSystem();
94 virtual Encoder *makeEncoder() const = 0;
95 virtual unsigned fixedBytesPerChar() const;
96 String<char> convertOut(const StringC &) const;
99 class SP_API CodingSystem : public InputCodingSystem, public OutputCodingSystem {
103 unsigned Decoder::minBytesPerChar() const
105 return minBytesPerChar_;
109 void Encoder::handleUnencodable(Char c, streambuf *sbufp)
111 if (unencodableHandler_)
112 unencodableHandler_->handleUnencodable(c, sbufp);
116 void Encoder::setUnencodableHandler(Handler *handler)
118 unencodableHandler_ = handler;
125 #endif /* not CodingSystem_INCLUDED */