source: icXML/icXML-devel/src/xercesc/util/Transcoders/MacOSUnicodeConverter/MacOSUnicodeConverter.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 10.3 KB
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: MacOSUnicodeConverter.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_MACOSUNICODECONVERTER_HPP)
23#define XERCESC_INCLUDE_GUARD_MACOSUNICODECONVERTER_HPP
24
25#include <cstddef>
26#include <icxercesc/util/TransService.hpp>
27#include <xercesc/util/Mutexes.hpp>
28
29#if defined(__APPLE__)
30    //  Framework includes from ProjectBuilder
31    #include <CoreServices/CoreServices.h>
32#else
33    //  Classic includes otherwise
34    #include <UnicodeConverter.h>
35#endif
36
37XERCES_CPP_NAMESPACE_BEGIN
38
39//
40//  The transcoding service has to provide a couple of required string
41//  and character operations, but its most important service is the creation
42//  of transcoder objects. There are two types of transcoders, which are
43//  discussed below in the XMLTranscoder class' description.
44//
45class XMLUTIL_EXPORT MacOSUnicodeConverter : public XMLTransService
46{
47public :
48    // -----------------------------------------------------------------------
49    //  Public Constructors and Destructor
50    // -----------------------------------------------------------------------
51    ~MacOSUnicodeConverter();
52
53    // -----------------------------------------------------------------------
54    //  Implementation of the virtual transcoding service API
55    // -----------------------------------------------------------------------
56    virtual int compareIString
57    (
58        const   XMLCh* const    comp1
59        , const XMLCh* const    comp2
60    );
61
62    virtual int compareNIString
63    (
64        const   XMLCh* const    comp1
65        , const XMLCh* const    comp2
66        , const XMLSize_t       maxChars
67    );
68
69    virtual const XMLCh* getId() const;
70
71    virtual XMLLCPTranscoder* makeNewLCPTranscoder(MemoryManager* manager);
72
73    virtual bool supportsSrcOfs() const;
74
75    virtual void upperCase(XMLCh* const toUpperCase);
76    virtual void lowerCase(XMLCh* const toLowerCase);
77
78protected :
79    // -----------------------------------------------------------------------
80    //  Hidden constructors
81    // -----------------------------------------------------------------------
82    MacOSUnicodeConverter(MemoryManager* manager);
83
84    // -----------------------------------------------------------------------
85    //  Protected virtual methods
86    // -----------------------------------------------------------------------
87    virtual XMLTranscoder* makeNewXMLTranscoder
88    (
89        const   XMLCh* const            encodingName
90        ,       XMLTransService::Codes& resValue
91        , const XMLSize_t               blockSize
92        ,       MemoryManager* const    manager
93    );
94    virtual XMLTranscoder* makeNewXMLTranscoder
95    (
96        const   XMLCh* const            encodingName
97        ,       XMLTransService::Codes& resValue
98        , const XMLSize_t               blockSize
99        ,               TextEncoding                    textEncoding
100        ,       MemoryManager* const    manager
101    );
102
103    //  Sniff for available functionality
104    static bool IsMacOSUnicodeConverterSupported(void);
105       
106        // Copy from a C string to a Str255
107        static void CopyCStringToPascal(const char* c, Str255 pas);
108
109private :
110        friend class XMLPlatformUtils;
111       
112        static const XMLCh fgMyServiceId[];                     // Name of the our unicode converter
113        static const XMLCh fgMacLCPEncodingName[];      // Name of the LCP transcoder we create
114
115        bool            fHasUnicodeCollation;                   // True if unicode collation is available
116        CollatorRef     fCollator;                                              // Our collator
117       
118    // -----------------------------------------------------------------------
119    //  Unimplemented constructors and operators
120    // -----------------------------------------------------------------------
121    MacOSUnicodeConverter(const MacOSUnicodeConverter&);
122    MacOSUnicodeConverter& operator=(const MacOSUnicodeConverter&);
123
124    // -----------------------------------------------------------------------
125    //  Private methods
126    // -----------------------------------------------------------------------
127        void ConvertWideToNarrow(const XMLCh* wide, char* narrow, std::size_t maxChars);
128       
129        //  Figure out what text encoding to use for LCP transcoder
130        TextEncoding discoverLCPEncoding();
131
132};
133
134
135//
136//  This type of transcoder is for non-local code page encodings, i.e.
137//  named encodings. These are used internally by the scanner to internalize
138//  raw XML into the internal Unicode format, and by writer classes to
139//  convert that internal Unicode format (which comes out of the parser)
140//  back out to a format that the receiving client code wants to use.
141//
142class XMLUTIL_EXPORT MacOSTranscoder : public XMLTranscoder
143{
144public :
145    // -----------------------------------------------------------------------
146    //  Constructors and Destructor
147    // -----------------------------------------------------------------------
148    MacOSTranscoder(
149            const XMLCh* const          encodingName,
150            TECObjectRef                        textToUnicode,
151            TECObjectRef                        unicodeToText,
152            const XMLSize_t         blockSize,
153            MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
154                );
155    ~MacOSTranscoder();
156
157
158    // -----------------------------------------------------------------------
159    //  The virtual transcoding interface
160    // -----------------------------------------------------------------------
161    virtual XMLSize_t transcodeFrom
162    (
163        const   XMLByte* const          srcData
164        , const XMLSize_t               srcCount
165        ,       XMLCh* const            toFill
166        , const XMLSize_t               maxChars
167        ,       XMLSize_t&              bytesEaten
168        ,       unsigned char* const    charSizes
169    );
170
171    virtual XMLSize_t transcodeTo
172    (
173        const   XMLCh* const    srcData
174        , const XMLSize_t       srcCount
175        ,       XMLByte* const  toFill
176        , const XMLSize_t       maxBytes
177        ,       XMLSize_t&      charsEaten
178        , const UnRepOpts       options
179    );
180
181    virtual bool canTranscodeTo
182    (
183        const   unsigned int    toCheck
184    );
185
186
187
188
189private :
190    // -----------------------------------------------------------------------
191    //  Unimplemented constructors and operators
192    // -----------------------------------------------------------------------
193    MacOSTranscoder(const MacOSTranscoder&);
194    MacOSTranscoder& operator=(const MacOSTranscoder&);
195
196    // -----------------------------------------------------------------------
197    //  Private members
198    // -----------------------------------------------------------------------
199    TECObjectRef        mTextToUnicode;
200    TECObjectRef        mUnicodeToText;
201};
202
203
204
205//
206//  This class is a specialized transcoder that only transcodes between
207//  the internal XMLCh format and the local code page. It is specialized
208//  for the very common job of translating data from the client app's
209//  native code page to the internal format and vice versa.
210//
211class XMLUTIL_EXPORT MacOSLCPTranscoder : public XMLLCPTranscoder
212{
213public :
214    // -----------------------------------------------------------------------
215    //  Constructors and Destructor
216    // -----------------------------------------------------------------------
217    MacOSLCPTranscoder(XMLTranscoder* const     transcoder, MemoryManager* const manager);
218    ~MacOSLCPTranscoder();
219
220
221    // -----------------------------------------------------------------------
222    //  The virtual transcoder API
223    //
224    //  NOTE:   All these APIs don't include null terminator characters in
225    //          their parameters. So calcRequiredSize() returns the number
226    //          of actual chars, not including the null. maxBytes and maxChars
227    //          parameters refer to actual chars, not including the null so
228    //          its assumed that the buffer is physically one char or byte
229    //          larger.
230    // -----------------------------------------------------------------------
231    virtual char* transcode(const XMLCh* const toTranscode,
232                            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
233
234    virtual XMLCh* transcode(const char* const toTranscode,
235                            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
236
237        // -----------------------------------------------------------------------
238    //  DEPRECATED old transcode interface
239    // -----------------------------------------------------------------------
240    virtual XMLSize_t calcRequiredSize(const char* const srcText
241        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
242
243    virtual XMLSize_t calcRequiredSize(const XMLCh* const srcText
244        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
245
246    virtual bool transcode
247    (
248        const   char* const     toTranscode
249        ,       XMLCh* const    toFill
250        , const XMLSize_t       maxChars
251        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
252    );
253
254    virtual bool transcode
255    (
256        const   XMLCh* const    toTranscode
257        ,       char* const     toFill
258        , const XMLSize_t       maxChars
259        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
260    );
261
262private :
263    // -----------------------------------------------------------------------
264    //  Unimplemented constructors and operators
265    // -----------------------------------------------------------------------
266    MacOSLCPTranscoder(const MacOSLCPTranscoder&);
267    MacOSLCPTranscoder& operator=(const MacOSLCPTranscoder&);
268
269    // -----------------------------------------------------------------------
270    //  Private data members
271    // -----------------------------------------------------------------------
272    XMLTranscoder* const        mTranscoder;
273        MemoryManager* const    mManager;
274        XMLMutex                                mMutex;                 // Mutex to enable reentrancy of LCP transcoder
275 };
276
277XERCES_CPP_NAMESPACE_END
278
279#endif
Note: See TracBrowser for help on using the repository browser.