source: NonGTP/Xerces/xercesc/util/Transcoders/IconvFBSD/IconvFBSDTransService.hpp @ 188

Revision 188, 15.3 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2001 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Log: IconvFBSDTransService.hpp,v $
59 * Revision 1.9  2003/12/24 15:24:15  cargilld
60 * More updates to memory management so that the static memory manager.
61 *
62 * Revision 1.8  2003/05/17 16:32:18  knoaman
63 * Memory manager implementation : transcoder update.
64 *
65 * Revision 1.7  2003/05/15 18:47:04  knoaman
66 * Partial implementation of the configurable memory manager.
67 *
68 * Revision 1.6  2003/03/07 18:15:57  tng
69 * Return a reference instead of void for operator=
70 *
71 * Revision 1.5  2003/03/07 15:08:57  tng
72 * [Bug 17571] fix building IconvFBSD (namespaces) .  Patch from Bjoern A. Zeeb.
73 *
74 * Revision 1.4  2002/11/04 15:14:34  tng
75 * C++ Namespace Support.
76 *
77 * Revision 1.3  2002/04/11 15:38:05  knoaman
78 * String lower case support for FreeBSD by Max Gotlib
79 *
80 * Revision 1.2  2002/04/09 15:44:00  knoaman
81 * Add lower case string support.
82 *
83 * Revision 1.1.1.1  2002/02/01 22:22:36  peiyongz
84 * sane_include
85 *
86 * Revision 1.3  2002/01/14 19:45:15  tng
87 * Support IconvFBSD in multi-threading environment with all the possible combinations of threading and transcoding options.  By Max Gotlib.
88 *
89 * Revision 1.2  2001/12/11 15:10:14  tng
90 * More changes to IconvFBSDTransService.  Allow using "old" TransServece implementation (via '-t native' option to runConfigure) or
91 * to employ libiconv (it is a part of FreeBSD ports-collection) services.  By Max Gotlib.
92 *
93 * Revision 1.1  2001/12/03 14:45:11  tng
94 * FreeBSD native transcoder (IconvFBSD) added by Max Gotlib.
95 *
96 */
97
98#ifndef ICONVFBSDTRANSSERVICE_HPP
99#define ICONVFBSDTRANSSERVICE_HPP
100
101#include <xercesc/util/TransService.hpp>
102
103#ifdef XML_USE_LIBICONV
104#  include <iconv.h>
105#endif
106
107XERCES_CPP_NAMESPACE_BEGIN
108
109#ifdef XML_USE_LIBICONV
110
111// ---------------------------------------------------------------------------
112//  Libiconv wrapper (low-level conversion utilities collection)
113// ---------------------------------------------------------------------------
114
115class XMLUTIL_EXPORT IconvFBSDCD
116{
117public:
118    // -----------------------------------------------------------------------
119    //  Constructors and Destructor
120    // -----------------------------------------------------------------------
121    IconvFBSDCD
122    (
123        iconv_t         cd_from,
124        iconv_t         cd_to,
125        size_t          uchsize,
126        unsigned int    ubo
127    );
128    virtual ~IconvFBSDCD();
129
130    // Convert "native unicode" character into XMLCh
131    void        mbcToXMLCh (const char *mbc, XMLCh *toRet) const;
132
133    // Convert XMLCh into "native unicode" character
134    void        xmlChToMbc (XMLCh xch, char *mbc) const;
135
136    // Return uppercase equivalent for XMLCh
137    XMLCh       toUpper (const XMLCh ch) const;
138
139    // Return uppercase equivalent for XMLCh
140    XMLCh       toLower (const XMLCh ch) const;
141
142    // Check if passed characters belongs to the :space: class
143    virtual bool isSpace(const XMLCh toCheck) const;
144
145    // Fill array of XMLCh characters with data, supplyed in the array
146    // of "native unicode" characters.
147    XMLCh*      mbsToXML (
148        const char*     mbs_str,
149        size_t          mbs_cnt,
150        XMLCh*          xml_str,
151        size_t          xml_cnt
152    ) const;
153
154
155    // Fill array of "native unicode" characters with data, supplyed
156    // in the array of XMLCh characters.
157    char*       xmlToMbs
158    (
159        const XMLCh*    xml_str,
160        size_t          xml_cnt,
161        char*           mbs_str,
162        size_t          mbs_cnt
163    ) const;
164
165    // Wrapper aroung the iconv() for transcoding from the local charset
166    size_t      iconvFrom
167    (
168        const char      *fromPtr,
169        size_t          *fromLen,
170        char            **toPtr,
171        size_t          toLen
172    ) const;
173
174    // Wrapper aroung the iconv() for transcoding to the local charset
175    size_t      iconvTo
176    (
177        const char      *fromPtr,
178        size_t          *fromLen,
179        char            **toPtr,
180        size_t          toLen
181    ) const;
182
183    // Private data accessors
184    inline iconv_t      cdTo () const { return fCDTo; }
185    inline iconv_t      cdFrom () const { return fCDFrom; }
186    inline size_t       uChSize () const { return fUChSize; }
187    inline unsigned int UBO () const { return fUBO; }
188
189protected:
190
191    // Hiden defaull constructor
192    IconvFBSDCD();
193
194    // Private data accessors
195    inline void setCDTo (iconv_t cd) { fCDTo = cd; }
196    inline void setCDFrom (iconv_t cd) { fCDFrom = cd; }
197    inline void setUChSize (size_t sz) { fUChSize = sz; }
198    inline void setUBO (unsigned int u) { fUBO = u; }
199
200private:
201    // -----------------------------------------------------------------------
202    //  Unimplemented constructors and operators
203    // -----------------------------------------------------------------------
204    IconvFBSDCD(const IconvFBSDCD&);
205    IconvFBSDCD& operator=(const IconvFBSDCD&);
206
207    // -----------------------------------------------------------------------
208    //  Private data members
209    //
210    //  fCDTo
211    //      Characterset conversion descriptor TO the local-host encoding
212    //  fCDFrom
213    //      Characterset conversion descriptor FROM the local-host encoding
214    //  fUChSize
215    //      Sizeof the "native unicode" character in bytes
216    //  fUBO
217    //      "Native unicode" characters byte order
218    // -----------------------------------------------------------------------
219    size_t      fUChSize;
220    unsigned int fUBO;
221    iconv_t     fCDTo;
222    iconv_t     fCDFrom;
223};
224
225#endif /* XML_USE_LIBICONV */
226
227
228
229// ---------------------------------------------------------------------------
230//  FreeBSD-specific Transcoding Service implementation
231// ---------------------------------------------------------------------------
232
233class XMLUTIL_EXPORT IconvFBSDTransService : public XMLTransService
234#ifdef XML_USE_LIBICONV
235, IconvFBSDCD
236#endif
237{
238public :
239    // -----------------------------------------------------------------------
240    //  Constructors and Destructor
241    // -----------------------------------------------------------------------
242    IconvFBSDTransService();
243    ~IconvFBSDTransService();
244
245
246    // -----------------------------------------------------------------------
247    //  Implementation of the virtual transcoding service API
248    // -----------------------------------------------------------------------
249    virtual int compareIString
250    (
251        const   XMLCh* const    comp1
252        , const XMLCh* const    comp2
253    );
254
255    virtual int compareNIString
256    (
257        const   XMLCh* const    comp1
258        , const XMLCh* const    comp2
259        , const unsigned int    maxChars
260    );
261
262    virtual const XMLCh* getId() const;
263
264    virtual bool isSpace(const XMLCh toCheck) const;
265
266    virtual XMLLCPTranscoder* makeNewLCPTranscoder();
267
268    virtual bool supportsSrcOfs() const;
269
270    virtual void upperCase(XMLCh* const toUpperCase) const;
271    virtual void lowerCase(XMLCh* const toUpperCase) const;
272
273protected :
274    // -----------------------------------------------------------------------
275    //  Protected virtual methods
276    // -----------------------------------------------------------------------
277    virtual XMLTranscoder* makeNewXMLTranscoder
278    (
279        const   XMLCh* const            encodingName
280        ,       XMLTransService::Codes& resValue
281        , const unsigned int            blockSize
282        ,       MemoryManager* const    manager
283    );
284
285
286private :
287    // -----------------------------------------------------------------------
288    //  Unimplemented constructors and operators
289    // -----------------------------------------------------------------------
290    IconvFBSDTransService(const IconvFBSDTransService&);
291    IconvFBSDTransService& operator=(const IconvFBSDTransService&);
292
293#ifdef XML_USE_LIBICONV
294
295    // -----------------------------------------------------------------------
296    //  Private data members
297    //
298    //  fUnicodeCP
299    //      Unicode encoding schema name
300    // -----------------------------------------------------------------------
301    const char* fUnicodeCP;
302
303#endif /* XML_USE_LIBICONV */
304};
305
306
307#ifdef XML_USE_LIBICONV
308//----------------------------------------------------------------------------
309// Implementation of the transcoders for arbitrary input characterset is
310// supported ONLY through libiconv interface
311//----------------------------------------------------------------------------
312
313class XMLUTIL_EXPORT IconvFBSDTranscoder : public XMLTranscoder, IconvFBSDCD
314{
315public :
316    // -----------------------------------------------------------------------
317    //  Constructors and Destructor
318    // -----------------------------------------------------------------------
319    IconvFBSDTranscoder(const   XMLCh* const    encodingName
320                        , const unsigned int    blockSize
321                        ,       iconv_t         cd_from
322                        ,       iconv_t         cd_to
323                        ,       size_t          uchsize
324                        ,       unsigned int    ubo
325                        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
326    );
327    ~IconvFBSDTranscoder();
328
329
330    // -----------------------------------------------------------------------
331    //  Implementation of the virtual transcoder interface
332    // -----------------------------------------------------------------------
333    virtual unsigned int transcodeFrom
334    (
335        const   XMLByte* const          srcData
336        , const unsigned int            srcCount
337        ,       XMLCh* const            toFill
338        , const unsigned int            maxChars
339        ,       unsigned int&           bytesEaten
340        ,       unsigned char* const    charSizes
341    );
342
343    virtual unsigned int transcodeTo
344    (
345        const   XMLCh* const    srcData
346        , const unsigned int    srcCount
347        ,       XMLByte* const  toFill
348        , const unsigned int    maxBytes
349        ,       unsigned int&   charsEaten
350        , const UnRepOpts       options
351    );
352
353    virtual bool canTranscodeTo
354    (
355        const   unsigned int    toCheck
356    )   const;
357
358private :
359    // -----------------------------------------------------------------------
360    //  Unimplemented constructors and operators
361    // -----------------------------------------------------------------------
362    IconvFBSDTranscoder();
363    IconvFBSDTranscoder(const IconvFBSDTranscoder&);
364    IconvFBSDTranscoder& operator=(const IconvFBSDTranscoder&);
365};
366
367#endif /* XML_USE_LIBICONV */
368
369
370// ---------------------------------------------------------------------------
371//  FreeBSD-specific XMLCh <-> local (host) characterset transcoder
372// ---------------------------------------------------------------------------
373
374class XMLUTIL_EXPORT IconvFBSDLCPTranscoder : public XMLLCPTranscoder
375#ifdef XML_USE_LIBICONV
376, IconvFBSDCD
377#endif
378{
379public :
380    // -----------------------------------------------------------------------
381    //  Constructors and Destructor
382    // -----------------------------------------------------------------------
383#ifdef XML_USE_LIBICONV
384
385    IconvFBSDLCPTranscoder
386    (
387        iconv_t         from,
388        iconv_t         to,
389        size_t          uchsize,
390        unsigned int    ubo
391    );
392
393protected:
394    IconvFBSDLCPTranscoder();   // Unimplemented
395
396public:
397
398#else /* !XML_USE_LIBICONV */
399
400    IconvFBSDLCPTranscoder();
401
402#endif /* XML_USE_LIBICONV */
403
404    ~IconvFBSDLCPTranscoder();
405
406
407    // -----------------------------------------------------------------------
408    //  Implementation of the virtual transcoder interface
409    // -----------------------------------------------------------------------
410    virtual unsigned int calcRequiredSize(const char* const srcText
411        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
412
413    virtual unsigned int calcRequiredSize(const XMLCh* const srcText
414        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
415
416    virtual char* transcode(const XMLCh* const toTranscode);
417    virtual char* transcode(const XMLCh* const toTranscode,
418                            MemoryManager* const manager);
419
420    virtual bool transcode
421    (
422        const   XMLCh* const    toTranscode
423        ,       char* const     toFill
424        , const unsigned int    maxBytes
425        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
426    );
427
428    virtual XMLCh* transcode(const char* const toTranscode);
429    virtual XMLCh* transcode(const char* const toTranscode,
430                             MemoryManager* const manager);
431
432    virtual bool transcode
433    (
434        const   char* const     toTranscode
435        ,       XMLCh* const    toFill
436        , const unsigned int    maxChars
437        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
438    );
439
440
441private :
442    // -----------------------------------------------------------------------
443    //  Unimplemented constructors and operators
444    // -----------------------------------------------------------------------
445    IconvFBSDLCPTranscoder(const IconvFBSDLCPTranscoder&);
446    IconvFBSDLCPTranscoder& operator=(const IconvFBSDLCPTranscoder&);
447};
448
449XERCES_CPP_NAMESPACE_END
450
451#endif /* ICONVFBSDTRANSSERVICE */
Note: See TracBrowser for help on using the repository browser.