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

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