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
44 #if defined(linux) || defined(CSRG_BASED)
52 namespace SP_NAMESPACE {
55 class SP_API Decoder {
57 Decoder(unsigned minBytesPerChar = 1);
59 virtual size_t decode(Char *, const char *, size_t, const char **) = 0;
60 virtual Boolean convertOffset(unsigned long &offset) const;
61 // Decoder assumes that for every decoded Char there must be at least
62 // minBytesPerChar bytes
63 unsigned minBytesPerChar() const;
65 unsigned minBytesPerChar_;
69 class SP_API Encoder {
71 class SP_API Handler {
73 virtual void handleUnencodable(Char, streambuf *) = 0;
77 virtual void output(const Char *, size_t, streambuf *) = 0;
78 // This outputs a byte order mark with Unicode.
79 virtual void startFile(streambuf *);
80 virtual void output(Char *, size_t, streambuf *);
81 void setUnencodableHandler(Handler *);
83 void handleUnencodable(Char, streambuf *);
85 Handler *unencodableHandler_;
88 class SP_API InputCodingSystem {
90 virtual ~InputCodingSystem();
91 virtual Decoder *makeDecoder() const = 0;
92 StringC convertIn(const char *) const;
93 virtual Boolean isIdentity() const;
96 class SP_API OutputCodingSystem {
98 virtual ~OutputCodingSystem();
99 virtual Encoder *makeEncoder() const = 0;
100 virtual unsigned fixedBytesPerChar() const;
101 String<char> convertOut(const StringC &) const;
104 class SP_API CodingSystem : public InputCodingSystem, public OutputCodingSystem {
108 unsigned Decoder::minBytesPerChar() const
110 return minBytesPerChar_;
114 void Encoder::handleUnencodable(Char c, streambuf *sbufp)
116 if (unencodableHandler_)
117 unencodableHandler_->handleUnencodable(c, sbufp);
121 void Encoder::setUnencodableHandler(Handler *handler)
123 unencodableHandler_ = handler;
130 #endif /* not CodingSystem_INCLUDED */