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

Revision 188, 11.6 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) 1999-2000 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) 1999, 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 * $Id: MacOSUnicodeConverter.hpp,v 1.10 2003/12/24 15:24:15 cargilld Exp $
59 */
60
61#ifndef MACOSUNICODECONVERTER_HPP
62#define MACOSUNICODECONVERTER_HPP
63
64#include <cstddef>
65#include <xercesc/util/TransService.hpp>
66
67#if defined(__APPLE__)
68    //  Framework includes from ProjectBuilder
69    #include <CoreServices/CoreServices.h>
70#else
71    //  Classic includes otherwise
72    #include <UnicodeConverter.h>
73#endif
74
75XERCES_CPP_NAMESPACE_BEGIN
76
77//
78//  The transcoding service has to provide a couple of required string
79//  and character operations, but its most important service is the creation
80//  of transcoder objects. There are two types of transcoders, which are
81//  discussed below in the XMLTranscoder class' description.
82//
83class XMLUTIL_EXPORT MacOSUnicodeConverter : public XMLTransService
84{
85public :
86    // -----------------------------------------------------------------------
87    //  Public Constructors and Destructor
88    // -----------------------------------------------------------------------
89    ~MacOSUnicodeConverter();
90
91    // -----------------------------------------------------------------------
92    //  Implementation of the virtual transcoding service API
93    // -----------------------------------------------------------------------
94    virtual int compareIString
95    (
96        const   XMLCh* const    comp1
97        , const XMLCh* const    comp2
98    );
99
100    virtual int compareNIString
101    (
102        const   XMLCh* const    comp1
103        , const XMLCh* const    comp2
104        , const unsigned int    maxChars
105    );
106
107    virtual const XMLCh* getId() const;
108
109    virtual bool isSpace(const XMLCh toCheck) const;
110
111    virtual XMLLCPTranscoder* makeNewLCPTranscoder();
112
113    virtual bool supportsSrcOfs() const;
114
115    virtual void upperCase(XMLCh* const toUpperCase) const;
116    virtual void lowerCase(XMLCh* const toLowerCase) const;
117
118protected :
119    // -----------------------------------------------------------------------
120    //  Hidden constructors
121    // -----------------------------------------------------------------------
122    MacOSUnicodeConverter();
123
124    // -----------------------------------------------------------------------
125    //  Protected virtual methods
126    // -----------------------------------------------------------------------
127    virtual XMLTranscoder* makeNewXMLTranscoder
128    (
129        const   XMLCh* const            encodingName
130        ,       XMLTransService::Codes& resValue
131        , const unsigned int            blockSize
132        ,       MemoryManager* const    manager
133    );
134
135    //  Sniff for available functionality
136    static bool IsMacOSUnicodeConverterSupported(void);
137
138
139private :
140        friend class XMLPlatformUtils;
141       
142        bool    mHasUnicodeCollation;   // True if unicode collation is available
143       
144    // -----------------------------------------------------------------------
145    //  Unimplemented constructors and operators
146    // -----------------------------------------------------------------------
147    MacOSUnicodeConverter(const MacOSUnicodeConverter&);
148    MacOSUnicodeConverter& operator=(const MacOSUnicodeConverter&);
149
150    // -----------------------------------------------------------------------
151    //  Private methods
152    // -----------------------------------------------------------------------
153        void ConvertWideToNarrow(const XMLCh* wide, char* narrow, std::size_t maxChars);
154};
155
156
157//
158//  This type of transcoder is for non-local code page encodings, i.e.
159//  named encodings. These are used internally by the scanner to internalize
160//  raw XML into the internal Unicode format, and by writer classes to
161//  convert that internal Unicode format (which comes out of the parser)
162//  back out to a format that the receiving client code wants to use.
163//
164class XMLUTIL_EXPORT MacOSTranscoder : public XMLTranscoder
165{
166public :
167    // -----------------------------------------------------------------------
168    //  Constructors and Destructor
169    // -----------------------------------------------------------------------
170    MacOSTranscoder(
171            const XMLCh* const          encodingName,
172            TextToUnicodeInfo           textToUnicodeInfo,
173            UnicodeToTextInfo           unicodeToTextInfo,
174            const unsigned int          blockSize,
175            MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
176                );
177    ~MacOSTranscoder();
178
179
180    // -----------------------------------------------------------------------
181    //  The virtual transcoding interface
182    // -----------------------------------------------------------------------
183    virtual unsigned int transcodeFrom
184    (
185        const   XMLByte* const          srcData
186        , const unsigned int            srcCount
187        ,       XMLCh* const            toFill
188        , const unsigned int            maxChars
189        ,       unsigned int&           bytesEaten
190        ,       unsigned char* const    charSizes
191    );
192
193    virtual unsigned int transcodeTo
194    (
195        const   XMLCh* const    srcData
196        , const unsigned int    srcCount
197        ,       XMLByte* const  toFill
198        , const unsigned int    maxBytes
199        ,       unsigned int&   charsEaten
200        , const UnRepOpts       options
201    );
202
203    virtual bool canTranscodeTo
204    (
205        const   unsigned int    toCheck
206    )   const;
207
208
209
210
211private :
212    // -----------------------------------------------------------------------
213    //  Unimplemented constructors and operators
214    // -----------------------------------------------------------------------
215    MacOSTranscoder(const MacOSTranscoder&);
216    MacOSTranscoder& operator=(const MacOSTranscoder&);
217
218    // -----------------------------------------------------------------------
219    //  Private members
220    // -----------------------------------------------------------------------
221    TextToUnicodeInfo   mTextToUnicodeInfo;
222    UnicodeToTextInfo   mUnicodeToTextInfo;
223};
224
225
226
227//
228//  This class is a specialized transcoder that only transcodes between
229//  the internal XMLCh format and the local code page. It is specialized
230//  for the very common job of translating data from the client app's
231//  native code page to the internal format and vice versa.
232//
233class XMLUTIL_EXPORT MacOSLCPTranscoder : public XMLLCPTranscoder
234{
235public :
236    // -----------------------------------------------------------------------
237    //  Constructors and Destructor
238    // -----------------------------------------------------------------------
239    MacOSLCPTranscoder(TextToUnicodeInfo textToUnicodeInfo, UnicodeToTextInfo unicodeToTextInfo);
240    ~MacOSLCPTranscoder();
241
242
243    // -----------------------------------------------------------------------
244    //  The virtual transcoder API
245    //
246    //  NOTE:   All these APIs don't include null terminator characters in
247    //          their parameters. So calcRequiredSize() returns the number
248    //          of actual chars, not including the null. maxBytes and maxChars
249    //          parameters refer to actual chars, not including the null so
250    //          its assumed that the buffer is physically one char or byte
251    //          larger.
252    // -----------------------------------------------------------------------
253    virtual unsigned int calcRequiredSize(const char* const srcText
254        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
255
256    virtual unsigned int calcRequiredSize(const XMLCh* const srcText
257        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
258
259    virtual char* transcode(const XMLCh* const toTranscode);
260    virtual char* transcode(const XMLCh* const toTranscode,
261                            MemoryManager* const manager);
262
263    virtual XMLCh* transcode(const char* const toTranscode);
264    virtual XMLCh* transcode(const char* const toTranscode,
265                            MemoryManager* const manager);
266
267    virtual bool transcode
268    (
269        const   char* const     toTranscode
270        ,       XMLCh* const    toFill
271        , const unsigned int    maxChars
272        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
273    );
274
275    virtual bool transcode
276    (
277        const   XMLCh* const    toTranscode
278        ,       char* const     toFill
279        , const unsigned int    maxChars
280        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
281    );
282
283
284private :
285    // -----------------------------------------------------------------------
286    //  Unimplemented constructors and operators
287    // -----------------------------------------------------------------------
288    MacOSLCPTranscoder(const MacOSLCPTranscoder&);
289    MacOSLCPTranscoder& operator=(const MacOSLCPTranscoder&);
290
291    // -----------------------------------------------------------------------
292    //  Private data members
293    // -----------------------------------------------------------------------
294    TextToUnicodeInfo   mTextToUnicodeInfo;
295    UnicodeToTextInfo   mUnicodeToTextInfo;
296 };
297
298XERCES_CPP_NAMESPACE_END
299
300#endif
Note: See TracBrowser for help on using the repository browser.