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