1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: ICUTransService.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef ICUTRANSSERVICE_HPP |
---|
23 | #define ICUTRANSSERVICE_HPP |
---|
24 | |
---|
25 | #include <xercesc/util/Mutexes.hpp> |
---|
26 | #include <xercesc/util/TransService.hpp> |
---|
27 | |
---|
28 | struct UConverter; |
---|
29 | |
---|
30 | XERCES_CPP_NAMESPACE_BEGIN |
---|
31 | |
---|
32 | class XMLUTIL_EXPORT ICUTransService : public XMLTransService |
---|
33 | { |
---|
34 | public : |
---|
35 | friend class Uniconv390TransService; |
---|
36 | // ----------------------------------------------------------------------- |
---|
37 | // Constructors and Destructor |
---|
38 | // ----------------------------------------------------------------------- |
---|
39 | ICUTransService(); |
---|
40 | ~ICUTransService(); |
---|
41 | |
---|
42 | |
---|
43 | // ----------------------------------------------------------------------- |
---|
44 | // Implementation of the virtual transcoding service API |
---|
45 | // ----------------------------------------------------------------------- |
---|
46 | virtual int compareIString |
---|
47 | ( |
---|
48 | const XMLCh* const comp1 |
---|
49 | , const XMLCh* const comp2 |
---|
50 | ); |
---|
51 | |
---|
52 | virtual int compareNIString |
---|
53 | ( |
---|
54 | const XMLCh* const comp1 |
---|
55 | , const XMLCh* const comp2 |
---|
56 | , const unsigned int maxChars |
---|
57 | ); |
---|
58 | |
---|
59 | virtual const XMLCh* getId() const; |
---|
60 | |
---|
61 | virtual bool isSpace(const XMLCh toCheck) const; |
---|
62 | |
---|
63 | virtual XMLLCPTranscoder* makeNewLCPTranscoder(); |
---|
64 | |
---|
65 | virtual bool supportsSrcOfs() const; |
---|
66 | |
---|
67 | virtual void upperCase(XMLCh* const toUpperCase) const; |
---|
68 | virtual void lowerCase(XMLCh* const toLowerCase) const; |
---|
69 | |
---|
70 | |
---|
71 | protected : |
---|
72 | // ----------------------------------------------------------------------- |
---|
73 | // Protected virtual methods |
---|
74 | // ----------------------------------------------------------------------- |
---|
75 | virtual XMLTranscoder* makeNewXMLTranscoder |
---|
76 | ( |
---|
77 | const XMLCh* const encodingName |
---|
78 | , XMLTransService::Codes& resValue |
---|
79 | , const unsigned int blockSize |
---|
80 | , MemoryManager* const manager |
---|
81 | ); |
---|
82 | |
---|
83 | |
---|
84 | private : |
---|
85 | // ----------------------------------------------------------------------- |
---|
86 | // Unimplemented constructors and operators |
---|
87 | // ----------------------------------------------------------------------- |
---|
88 | ICUTransService(const ICUTransService&); |
---|
89 | ICUTransService& operator=(const ICUTransService&); |
---|
90 | }; |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | class XMLUTIL_EXPORT ICUTranscoder : public XMLTranscoder |
---|
95 | { |
---|
96 | public : |
---|
97 | // ----------------------------------------------------------------------- |
---|
98 | // Constructors and Destructor |
---|
99 | // ----------------------------------------------------------------------- |
---|
100 | ICUTranscoder |
---|
101 | ( |
---|
102 | const XMLCh* const encodingName |
---|
103 | , UConverter* const toAdopt |
---|
104 | , const unsigned int blockSize |
---|
105 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
106 | ); |
---|
107 | ~ICUTranscoder(); |
---|
108 | |
---|
109 | |
---|
110 | // ----------------------------------------------------------------------- |
---|
111 | // Implementation of the virtual transcoder interface |
---|
112 | // ----------------------------------------------------------------------- |
---|
113 | virtual unsigned int transcodeFrom |
---|
114 | ( |
---|
115 | const XMLByte* const srcData |
---|
116 | , const unsigned int srcCount |
---|
117 | , XMLCh* const toFill |
---|
118 | , const unsigned int maxChars |
---|
119 | , unsigned int& bytesEaten |
---|
120 | , unsigned char* const charSizes |
---|
121 | ); |
---|
122 | |
---|
123 | virtual unsigned int transcodeTo |
---|
124 | ( |
---|
125 | const XMLCh* const srcData |
---|
126 | , const unsigned int srcCount |
---|
127 | , XMLByte* const toFill |
---|
128 | , const unsigned int maxBytes |
---|
129 | , unsigned int& charsEaten |
---|
130 | , const UnRepOpts options |
---|
131 | ); |
---|
132 | |
---|
133 | virtual bool canTranscodeTo |
---|
134 | ( |
---|
135 | const unsigned int toCheck |
---|
136 | ) const; |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | private : |
---|
141 | // ----------------------------------------------------------------------- |
---|
142 | // Unimplemented constructors and operators |
---|
143 | // ----------------------------------------------------------------------- |
---|
144 | ICUTranscoder(); |
---|
145 | ICUTranscoder(const ICUTranscoder&); |
---|
146 | ICUTranscoder& operator=(const ICUTranscoder&); |
---|
147 | |
---|
148 | |
---|
149 | // ----------------------------------------------------------------------- |
---|
150 | // Private data members |
---|
151 | // |
---|
152 | // fConverter |
---|
153 | // This is a pointer to the ICU converter that this transcoder |
---|
154 | // uses. |
---|
155 | // |
---|
156 | // fFixed |
---|
157 | // This is set to true if the encoding is a fixed size one. This |
---|
158 | // can be used to optimize some operations. |
---|
159 | // |
---|
160 | // fSrcOffsets |
---|
161 | // This is an array of longs, which are allocated to the size of |
---|
162 | // the trancoding block (if any) indicated in the ctor. It is used |
---|
163 | // to get the character offsets from ICU, which are then translated |
---|
164 | // into an array of char sizes for return. |
---|
165 | // ----------------------------------------------------------------------- |
---|
166 | UConverter* fConverter; |
---|
167 | bool fFixed; |
---|
168 | XMLUInt32* fSrcOffsets; |
---|
169 | }; |
---|
170 | |
---|
171 | |
---|
172 | class XMLUTIL_EXPORT ICULCPTranscoder : public XMLLCPTranscoder |
---|
173 | { |
---|
174 | public : |
---|
175 | // ----------------------------------------------------------------------- |
---|
176 | // Constructors and Destructor |
---|
177 | // ----------------------------------------------------------------------- |
---|
178 | ICULCPTranscoder(UConverter* const toAdopt); |
---|
179 | ~ICULCPTranscoder(); |
---|
180 | |
---|
181 | |
---|
182 | // ----------------------------------------------------------------------- |
---|
183 | // Implementation of the virtual transcoder interface |
---|
184 | // ----------------------------------------------------------------------- |
---|
185 | virtual unsigned int calcRequiredSize(const char* const srcText |
---|
186 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
187 | |
---|
188 | virtual unsigned int calcRequiredSize(const XMLCh* const srcText |
---|
189 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
190 | |
---|
191 | virtual char* transcode(const XMLCh* const toTranscode); |
---|
192 | virtual char* transcode(const XMLCh* const toTranscode, |
---|
193 | MemoryManager* const manager); |
---|
194 | |
---|
195 | virtual XMLCh* transcode(const char* const toTranscode); |
---|
196 | virtual XMLCh* transcode(const char* const toTranscode, |
---|
197 | MemoryManager* const manager); |
---|
198 | |
---|
199 | virtual bool transcode |
---|
200 | ( |
---|
201 | const char* const toTranscode |
---|
202 | , XMLCh* const toFill |
---|
203 | , const unsigned int maxChars |
---|
204 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
205 | ); |
---|
206 | |
---|
207 | virtual bool transcode |
---|
208 | ( |
---|
209 | const XMLCh* const toTranscode |
---|
210 | , char* const toFill |
---|
211 | , const unsigned int maxChars |
---|
212 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
213 | ); |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | private : |
---|
218 | // ----------------------------------------------------------------------- |
---|
219 | // Unimplemented constructors and operators |
---|
220 | // ----------------------------------------------------------------------- |
---|
221 | ICULCPTranscoder(); |
---|
222 | ICULCPTranscoder(const ICULCPTranscoder&); |
---|
223 | ICULCPTranscoder& operator=(const ICULCPTranscoder&); |
---|
224 | |
---|
225 | |
---|
226 | // ----------------------------------------------------------------------- |
---|
227 | // Private data members |
---|
228 | // |
---|
229 | // fConverter |
---|
230 | // This is a pointer to the ICU converter that this transcoder |
---|
231 | // uses. |
---|
232 | // |
---|
233 | // fMutex |
---|
234 | // We have to synchronize threaded calls to the converter. |
---|
235 | // ----------------------------------------------------------------------- |
---|
236 | UConverter* fConverter; |
---|
237 | XMLMutex fMutex; |
---|
238 | }; |
---|
239 | |
---|
240 | XERCES_CPP_NAMESPACE_END |
---|
241 | |
---|
242 | #endif |
---|