[2674] | 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 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifndef MACOSUNICODECONVERTER_HPP |
---|
| 23 | #define MACOSUNICODECONVERTER_HPP |
---|
| 24 | |
---|
| 25 | #include <cstddef> |
---|
| 26 | #include <xercesc/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 | |
---|
| 37 | XERCES_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 | // |
---|
| 45 | class XMLUTIL_EXPORT MacOSUnicodeConverter : public XMLTransService |
---|
| 46 | { |
---|
| 47 | public : |
---|
| 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 unsigned int maxChars |
---|
| 67 | ); |
---|
| 68 | |
---|
| 69 | virtual const XMLCh* getId() const; |
---|
| 70 | |
---|
| 71 | virtual bool isSpace(const XMLCh toCheck) const; |
---|
| 72 | |
---|
| 73 | virtual XMLLCPTranscoder* makeNewLCPTranscoder(); |
---|
| 74 | |
---|
| 75 | virtual bool supportsSrcOfs() const; |
---|
| 76 | |
---|
| 77 | virtual void upperCase(XMLCh* const toUpperCase) const; |
---|
| 78 | virtual void lowerCase(XMLCh* const toLowerCase) const; |
---|
| 79 | |
---|
| 80 | protected : |
---|
| 81 | // ----------------------------------------------------------------------- |
---|
| 82 | // Hidden constructors |
---|
| 83 | // ----------------------------------------------------------------------- |
---|
| 84 | MacOSUnicodeConverter(); |
---|
| 85 | |
---|
| 86 | // ----------------------------------------------------------------------- |
---|
| 87 | // Protected virtual methods |
---|
| 88 | // ----------------------------------------------------------------------- |
---|
| 89 | virtual XMLTranscoder* makeNewXMLTranscoder |
---|
| 90 | ( |
---|
| 91 | const XMLCh* const encodingName |
---|
| 92 | , XMLTransService::Codes& resValue |
---|
| 93 | , const unsigned int blockSize |
---|
| 94 | , MemoryManager* const manager |
---|
| 95 | ); |
---|
| 96 | virtual XMLTranscoder* makeNewXMLTranscoder |
---|
| 97 | ( |
---|
| 98 | const XMLCh* const encodingName |
---|
| 99 | , XMLTransService::Codes& resValue |
---|
| 100 | , const unsigned int blockSize |
---|
| 101 | , TextEncoding textEncoding |
---|
| 102 | , MemoryManager* const manager |
---|
| 103 | ); |
---|
| 104 | |
---|
| 105 | // Sniff for available functionality |
---|
| 106 | static bool IsMacOSUnicodeConverterSupported(void); |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | private : |
---|
| 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 | // |
---|
| 142 | class XMLUTIL_EXPORT MacOSTranscoder : public XMLTranscoder |
---|
| 143 | { |
---|
| 144 | public : |
---|
| 145 | // ----------------------------------------------------------------------- |
---|
| 146 | // Constructors and Destructor |
---|
| 147 | // ----------------------------------------------------------------------- |
---|
| 148 | MacOSTranscoder( |
---|
| 149 | const XMLCh* const encodingName, |
---|
| 150 | TECObjectRef textToUnicode, |
---|
| 151 | TECObjectRef unicodeToText, |
---|
| 152 | const unsigned int blockSize, |
---|
| 153 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 154 | ); |
---|
| 155 | ~MacOSTranscoder(); |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | // ----------------------------------------------------------------------- |
---|
| 159 | // The virtual transcoding interface |
---|
| 160 | // ----------------------------------------------------------------------- |
---|
| 161 | virtual unsigned int transcodeFrom |
---|
| 162 | ( |
---|
| 163 | const XMLByte* const srcData |
---|
| 164 | , const unsigned int srcCount |
---|
| 165 | , XMLCh* const toFill |
---|
| 166 | , const unsigned int maxChars |
---|
| 167 | , unsigned int& bytesEaten |
---|
| 168 | , unsigned char* const charSizes |
---|
| 169 | ); |
---|
| 170 | |
---|
| 171 | virtual unsigned int transcodeTo |
---|
| 172 | ( |
---|
| 173 | const XMLCh* const srcData |
---|
| 174 | , const unsigned int srcCount |
---|
| 175 | , XMLByte* const toFill |
---|
| 176 | , const unsigned int maxBytes |
---|
| 177 | , unsigned int& charsEaten |
---|
| 178 | , const UnRepOpts options |
---|
| 179 | ); |
---|
| 180 | |
---|
| 181 | virtual bool canTranscodeTo |
---|
| 182 | ( |
---|
| 183 | const unsigned int toCheck |
---|
| 184 | ) const; |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | private : |
---|
| 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 | // |
---|
| 211 | class XMLUTIL_EXPORT MacOSLCPTranscoder : public XMLLCPTranscoder |
---|
| 212 | { |
---|
| 213 | public : |
---|
| 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 unsigned int calcRequiredSize(const char* const srcText |
---|
| 232 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 233 | |
---|
| 234 | virtual unsigned int calcRequiredSize(const XMLCh* const srcText |
---|
| 235 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 236 | |
---|
| 237 | virtual char* transcode(const XMLCh* const toTranscode); |
---|
| 238 | virtual char* transcode(const XMLCh* const toTranscode, |
---|
| 239 | MemoryManager* const manager); |
---|
| 240 | |
---|
| 241 | virtual XMLCh* transcode(const char* const toTranscode); |
---|
| 242 | virtual XMLCh* transcode(const char* const toTranscode, |
---|
| 243 | MemoryManager* const manager); |
---|
| 244 | |
---|
| 245 | virtual bool transcode |
---|
| 246 | ( |
---|
| 247 | const char* const toTranscode |
---|
| 248 | , XMLCh* const toFill |
---|
| 249 | , const unsigned int maxChars |
---|
| 250 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 251 | ); |
---|
| 252 | |
---|
| 253 | virtual bool transcode |
---|
| 254 | ( |
---|
| 255 | const XMLCh* const toTranscode |
---|
| 256 | , char* const toFill |
---|
| 257 | , const unsigned int maxChars |
---|
| 258 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 259 | ); |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | private : |
---|
| 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 rentrancy of LCP transcoder |
---|
| 275 | }; |
---|
| 276 | |
---|
| 277 | XERCES_CPP_NAMESPACE_END |
---|
| 278 | |
---|
| 279 | #endif |
---|