1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include "splib.h"
10 #include "CodingSystem.h"
11
12 #include <string.h>
13
14 #ifdef SP_NAMESPACE
15 namespace SP_NAMESPACE {
16 #endif
17
~InputCodingSystem()18 InputCodingSystem::~InputCodingSystem()
19 {
20 }
21
convertIn(const char * s) const22 StringC InputCodingSystem::convertIn(const char *s) const
23 {
24 Decoder *decoder = makeDecoder();
25 StringC str;
26 str.resize(strlen(s));
27 str.resize(decoder->decode(&str[0], s, strlen(s), &s));
28 delete decoder;
29 return str;
30 }
31
isIdentity() const32 Boolean InputCodingSystem::isIdentity() const
33 {
34 return 0;
35 }
36
~OutputCodingSystem()37 OutputCodingSystem::~OutputCodingSystem()
38 {
39 }
40
fixedBytesPerChar() const41 unsigned OutputCodingSystem::fixedBytesPerChar() const
42 {
43 return 0;
44 }
45
convertOut(const StringC & str) const46 String<char> OutputCodingSystem::convertOut(const StringC &str) const
47 {
48 Encoder *encoder = makeEncoder();
49 StrOutputByteStream stream;
50 encoder->output(str.data(), str.size(), &stream);
51 delete encoder;
52 String<char> result;
53 stream.extractString(result);
54 result += '\0';
55 return result;
56 }
57
Decoder(unsigned minBytesPerChar)58 Decoder::Decoder(unsigned minBytesPerChar)
59 : minBytesPerChar_(minBytesPerChar)
60 {
61 }
62
~Decoder()63 Decoder::~Decoder()
64 {
65 }
66
convertOffset(unsigned long &) const67 Boolean Decoder::convertOffset(unsigned long &) const
68 {
69 return false;
70 }
71
Encoder()72 Encoder::Encoder()
73 {
74 }
75
~Encoder()76 Encoder::~Encoder()
77 {
78 }
79
output(Char * s,size_t n,OutputByteStream * sp)80 void Encoder::output(Char *s, size_t n, OutputByteStream *sp)
81 {
82 output((const Char *)s, n, sp);
83 }
84
startFile(OutputByteStream *)85 void Encoder::startFile(OutputByteStream *)
86 {
87 }
88
handleUnencodable(Char,OutputByteStream *)89 void Encoder::handleUnencodable(Char, OutputByteStream *)
90 {
91 }
92
setUnencodableHandler(Handler *)93 void Encoder::setUnencodableHandler(Handler *)
94 {
95 }
96
RecoveringEncoder()97 RecoveringEncoder::RecoveringEncoder()
98 : unencodableHandler_(0)
99 {
100 }
101
handleUnencodable(Char c,OutputByteStream * sbufp)102 void RecoveringEncoder::handleUnencodable(Char c, OutputByteStream *sbufp)
103 {
104 if (unencodableHandler_)
105 unencodableHandler_->handleUnencodable(c, sbufp);
106 }
107
setUnencodableHandler(Handler * handler)108 void RecoveringEncoder::setUnencodableHandler(Handler *handler)
109 {
110 unencodableHandler_ = handler;
111 }
112
113 #ifdef SP_NAMESPACE
114 }
115 #endif
116