source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/Transcoders/IconvGNU/IconvGNUTransService.hpp @ 2674

Revision 2674, 11.3 KB checked in by mattausch, 16 years ago (diff)
Line 
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: IconvGNUTransService.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#ifndef ICONVGNUTRANSSERVICE_HPP
23#define ICONVGNUTRANSSERVICE_HPP
24
25#include <xercesc/util/TransService.hpp>
26
27
28#include <iconv.h>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32// ---------------------------------------------------------------------------
33//  Libiconv wrapper (low-level conversion utilities collection)
34// ---------------------------------------------------------------------------
35
36class XMLUTIL_EXPORT IconvGNUWrapper
37{
38public:
39    // -----------------------------------------------------------------------
40    //  Constructors and Destructor
41    // -----------------------------------------------------------------------
42    IconvGNUWrapper
43    (
44  iconv_t               cd_from,
45  iconv_t               cd_to,
46  size_t                uchsize,
47  unsigned int  ubo
48    );
49    virtual ~IconvGNUWrapper();
50
51    // Convert "native unicode" character into XMLCh
52    void        mbcToXMLCh (const char *mbc, XMLCh *toRet) const;
53
54    // Convert XMLCh into "native unicode" character
55    void        xmlChToMbc (XMLCh xch, char *mbc) const;
56
57    // Return uppercase equivalent for XMLCh
58    XMLCh       toUpper (const XMLCh ch) const;
59
60    // Return uppercase equivalent for XMLCh
61    XMLCh       toLower (const XMLCh ch) const;
62
63    // Check if passed characters belongs to the :space: class
64    virtual bool isSpace(const XMLCh toCheck) const;
65
66    // Fill array of XMLCh characters with data, supplyed in the array
67    // of "native unicode" characters.
68    XMLCh*      mbsToXML (
69  const char*   mbs_str,
70  size_t                mbs_cnt,
71  XMLCh*                xml_str,
72  size_t                xml_cnt
73    ) const;
74
75
76    // Fill array of "native unicode" characters with data, supplyed
77    // in the array of XMLCh characters.
78    char*       xmlToMbs
79    (
80  const XMLCh*  xml_str,
81  size_t                xml_cnt,
82  char*         mbs_str,
83  size_t                mbs_cnt
84    ) const;
85
86    // Wrapper aroung the iconv() for transcoding from the local charset
87    size_t      iconvFrom
88    (
89  const char    *fromPtr,
90  size_t                *fromLen,
91  char          **toPtr,
92  size_t                toLen
93    ) const;
94
95    // Wrapper aroung the iconv() for transcoding to the local charset
96    size_t      iconvTo
97    (
98  const char    *fromPtr,
99  size_t                *fromLen,
100  char          **toPtr,
101  size_t                toLen
102    ) const;
103
104    // Private data accessors
105    inline iconv_t      cdTo () const { return fCDTo; }
106    inline iconv_t      cdFrom () const { return fCDFrom; }
107    inline size_t       uChSize () const { return fUChSize; }
108    inline unsigned int UBO () const { return fUBO; }
109
110protected:
111
112    // Hiden defaull constructor
113    IconvGNUWrapper();
114
115    // Private data accessors
116    inline void setCDTo (iconv_t cd) { fCDTo = cd; }
117    inline void setCDFrom (iconv_t cd) { fCDFrom = cd; }
118    inline void setUChSize (size_t sz) { fUChSize = sz; }
119    inline void setUBO (unsigned int u) { fUBO = u; }
120
121private:
122    // -----------------------------------------------------------------------
123    //  Unimplemented constructors and operators
124    // -----------------------------------------------------------------------
125    IconvGNUWrapper(const IconvGNUWrapper&);
126    IconvGNUWrapper& operator=(const IconvGNUWrapper&);
127
128    // -----------------------------------------------------------------------
129    //  Private data members
130    //
131    //  fCDTo
132    //      Characterset conversion descriptor TO the local-host encoding
133    //  fCDFrom
134    //      Characterset conversion descriptor FROM the local-host encoding
135    //  fUChSize
136    //      Sizeof the "native unicode" character in bytes
137    //  fUBO
138    //      "Native unicode" characters byte order
139    // -----------------------------------------------------------------------
140    size_t      fUChSize;
141    unsigned int fUBO;
142    iconv_t     fCDTo;
143    iconv_t     fCDFrom;
144};
145
146
147
148// ---------------------------------------------------------------------------
149//  FreeBSD-specific Transcoding Service implementation
150// ---------------------------------------------------------------------------
151
152class XMLUTIL_EXPORT IconvGNUTransService : public XMLTransService, IconvGNUWrapper
153{
154public :
155    // -----------------------------------------------------------------------
156    //  Constructors and Destructor
157    // -----------------------------------------------------------------------
158    IconvGNUTransService();
159    ~IconvGNUTransService();
160
161
162    // -----------------------------------------------------------------------
163    //  Implementation of the virtual transcoding service API
164    // -----------------------------------------------------------------------
165    virtual int compareIString
166    (
167        const   XMLCh* const    comp1
168        , const XMLCh* const    comp2
169    );
170
171    virtual int compareNIString
172    (
173        const   XMLCh* const    comp1
174        , const XMLCh* const    comp2
175        , const unsigned int    maxChars
176    );
177
178    virtual const XMLCh* getId() const;
179
180    virtual bool isSpace(const XMLCh toCheck) const;
181
182    virtual XMLLCPTranscoder* makeNewLCPTranscoder();
183
184    virtual bool supportsSrcOfs() const;
185
186    virtual void upperCase(XMLCh* const toUpperCase) const;
187    virtual void lowerCase(XMLCh* const toUpperCase) const;
188
189protected :
190    // -----------------------------------------------------------------------
191    //  Protected virtual methods
192    // -----------------------------------------------------------------------
193    virtual XMLTranscoder* makeNewXMLTranscoder
194    (
195        const   XMLCh* const            encodingName
196        ,       XMLTransService::Codes& resValue
197        , const unsigned int            blockSize
198        ,       MemoryManager* const    manager
199    );
200
201
202private :
203    // -----------------------------------------------------------------------
204    //  Unimplemented constructors and operators
205    // -----------------------------------------------------------------------
206    IconvGNUTransService(const IconvGNUTransService&);
207    IconvGNUTransService& operator=(const IconvGNUTransService&);
208
209
210    // -----------------------------------------------------------------------
211    //  Private data members
212    //
213    //  fUnicodeCP
214    //      Unicode encoding schema name
215    // -----------------------------------------------------------------------
216    const char* fUnicodeCP;
217
218};
219
220
221//----------------------------------------------------------------------------
222// Implementation of the transcoders for arbitrary input characterset is
223// supported ONLY through libiconv interface
224//----------------------------------------------------------------------------
225
226class XMLUTIL_EXPORT IconvGNUTranscoder : public XMLTranscoder, IconvGNUWrapper
227{
228public :
229    // -----------------------------------------------------------------------
230    //  Constructors and Destructor
231    // -----------------------------------------------------------------------
232    IconvGNUTranscoder(const    XMLCh* const    encodingName
233                , const unsigned int    blockSize
234                ,       iconv_t         cd_from
235                ,       iconv_t         cd_to
236                ,       size_t          uchsize
237                ,       unsigned int    ubo
238        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
239    );
240    ~IconvGNUTranscoder();
241
242
243    // -----------------------------------------------------------------------
244    //  Implementation of the virtual transcoder interface
245    // -----------------------------------------------------------------------
246    virtual unsigned int transcodeFrom
247    (
248        const   XMLByte* const          srcData
249        , const unsigned int            srcCount
250        ,       XMLCh* const            toFill
251        , const unsigned int            maxChars
252        ,       unsigned int&           bytesEaten
253        ,       unsigned char* const    charSizes
254    );
255
256    virtual unsigned int transcodeTo
257    (
258        const   XMLCh* const    srcData
259        , const unsigned int    srcCount
260        ,       XMLByte* const  toFill
261        , const unsigned int    maxBytes
262        ,       unsigned int&   charsEaten
263        , const UnRepOpts       options
264    );
265
266    virtual bool canTranscodeTo
267    (
268        const   unsigned int    toCheck
269    )   const;
270
271private :
272    // -----------------------------------------------------------------------
273    //  Unimplemented constructors and operators
274    // -----------------------------------------------------------------------
275    IconvGNUTranscoder();
276    IconvGNUTranscoder(const IconvGNUTranscoder&);
277    IconvGNUTranscoder& operator=(const IconvGNUTranscoder&);
278};
279
280
281// ---------------------------------------------------------------------------
282//  GNU-specific XMLCh <-> local (host) characterset transcoder
283// ---------------------------------------------------------------------------
284
285class XMLUTIL_EXPORT IconvGNULCPTranscoder : public XMLLCPTranscoder, IconvGNUWrapper
286{
287public :
288    // -----------------------------------------------------------------------
289    //  Constructors and Destructor
290    // -----------------------------------------------------------------------
291
292    IconvGNULCPTranscoder
293    (
294  iconv_t               from,
295  iconv_t               to,
296  size_t                uchsize,
297  unsigned int  ubo
298    );
299
300protected:
301    IconvGNULCPTranscoder();    // Unimplemented
302
303public:
304
305    ~IconvGNULCPTranscoder();
306
307
308    // -----------------------------------------------------------------------
309    //  Implementation of the virtual transcoder interface
310    // -----------------------------------------------------------------------
311    virtual unsigned int calcRequiredSize(const char* const srcText
312        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
313
314    virtual unsigned int calcRequiredSize(const XMLCh* const srcText
315        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
316
317    virtual char* transcode(const XMLCh* const toTranscode);
318    virtual char* transcode(const XMLCh* const toTranscode,
319                            MemoryManager* const manager);
320
321    virtual bool transcode
322    (
323        const   XMLCh* const    toTranscode
324        ,       char* const     toFill
325        , const unsigned int    maxBytes
326        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
327    );
328
329    virtual XMLCh* transcode(const char* const toTranscode);
330    virtual XMLCh* transcode(const char* const toTranscode,
331                             MemoryManager* const manager);
332
333    virtual bool transcode
334    (
335        const   char* const     toTranscode
336        ,       XMLCh* const    toFill
337        , const unsigned int    maxChars
338        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
339    );
340
341
342private :
343    // -----------------------------------------------------------------------
344    //  Unimplemented constructors and operators
345    // -----------------------------------------------------------------------
346    IconvGNULCPTranscoder(const IconvGNULCPTranscoder&);
347    IconvGNULCPTranscoder& operator=(const IconvGNULCPTranscoder&);
348};
349
350XERCES_CPP_NAMESPACE_END
351
352#endif /* ICONVGNUTRANSSERVICE */
353
Note: See TracBrowser for help on using the repository browser.