[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2002 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: IconvGNUTransService.hpp,v $
|
---|
| 59 | * Revision 1.6 2003/12/24 15:24:15 cargilld
|
---|
| 60 | * More updates to memory management so that the static memory manager.
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.5 2003/05/17 16:32:18 knoaman
|
---|
| 63 | * Memory manager implementation : transcoder update.
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.4 2003/05/15 18:47:05 knoaman
|
---|
| 66 | * Partial implementation of the configurable memory manager.
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.3 2003/03/07 18:15:57 tng
|
---|
| 69 | * Return a reference instead of void for operator=
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.2 2002/11/04 15:14:34 tng
|
---|
| 72 | * C++ Namespace Support.
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.1 2002/08/19 19:38:18 tng
|
---|
| 75 | * [Bug 11771] Linux specific IconvGNU transcoder. Patch from Vasily Tchekalkin.
|
---|
| 76 | *
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | #ifndef ICONVGNUTRANSSERVICE_HPP
|
---|
| 80 | #define ICONVGNUTRANSSERVICE_HPP
|
---|
| 81 |
|
---|
| 82 | #include <xercesc/util/TransService.hpp>
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | #include <iconv.h>
|
---|
| 86 |
|
---|
| 87 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 88 |
|
---|
| 89 | // ---------------------------------------------------------------------------
|
---|
| 90 | // Libiconv wrapper (low-level conversion utilities collection)
|
---|
| 91 | // ---------------------------------------------------------------------------
|
---|
| 92 |
|
---|
| 93 | class XMLUTIL_EXPORT IconvGNUWrapper
|
---|
| 94 | {
|
---|
| 95 | public:
|
---|
| 96 | // -----------------------------------------------------------------------
|
---|
| 97 | // Constructors and Destructor
|
---|
| 98 | // -----------------------------------------------------------------------
|
---|
| 99 | IconvGNUWrapper
|
---|
| 100 | (
|
---|
| 101 | iconv_t cd_from,
|
---|
| 102 | iconv_t cd_to,
|
---|
| 103 | size_t uchsize,
|
---|
| 104 | unsigned int ubo
|
---|
| 105 | );
|
---|
| 106 | virtual ~IconvGNUWrapper();
|
---|
| 107 |
|
---|
| 108 | // Convert "native unicode" character into XMLCh
|
---|
| 109 | void mbcToXMLCh (const char *mbc, XMLCh *toRet) const;
|
---|
| 110 |
|
---|
| 111 | // Convert XMLCh into "native unicode" character
|
---|
| 112 | void xmlChToMbc (XMLCh xch, char *mbc) const;
|
---|
| 113 |
|
---|
| 114 | // Return uppercase equivalent for XMLCh
|
---|
| 115 | XMLCh toUpper (const XMLCh ch) const;
|
---|
| 116 |
|
---|
| 117 | // Return uppercase equivalent for XMLCh
|
---|
| 118 | XMLCh toLower (const XMLCh ch) const;
|
---|
| 119 |
|
---|
| 120 | // Check if passed characters belongs to the :space: class
|
---|
| 121 | virtual bool isSpace(const XMLCh toCheck) const;
|
---|
| 122 |
|
---|
| 123 | // Fill array of XMLCh characters with data, supplyed in the array
|
---|
| 124 | // of "native unicode" characters.
|
---|
| 125 | XMLCh* mbsToXML (
|
---|
| 126 | const char* mbs_str,
|
---|
| 127 | size_t mbs_cnt,
|
---|
| 128 | XMLCh* xml_str,
|
---|
| 129 | size_t xml_cnt
|
---|
| 130 | ) const;
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | // Fill array of "native unicode" characters with data, supplyed
|
---|
| 134 | // in the array of XMLCh characters.
|
---|
| 135 | char* xmlToMbs
|
---|
| 136 | (
|
---|
| 137 | const XMLCh* xml_str,
|
---|
| 138 | size_t xml_cnt,
|
---|
| 139 | char* mbs_str,
|
---|
| 140 | size_t mbs_cnt
|
---|
| 141 | ) const;
|
---|
| 142 |
|
---|
| 143 | // Wrapper aroung the iconv() for transcoding from the local charset
|
---|
| 144 | size_t iconvFrom
|
---|
| 145 | (
|
---|
| 146 | const char *fromPtr,
|
---|
| 147 | size_t *fromLen,
|
---|
| 148 | char **toPtr,
|
---|
| 149 | size_t toLen
|
---|
| 150 | ) const;
|
---|
| 151 |
|
---|
| 152 | // Wrapper aroung the iconv() for transcoding to the local charset
|
---|
| 153 | size_t iconvTo
|
---|
| 154 | (
|
---|
| 155 | const char *fromPtr,
|
---|
| 156 | size_t *fromLen,
|
---|
| 157 | char **toPtr,
|
---|
| 158 | size_t toLen
|
---|
| 159 | ) const;
|
---|
| 160 |
|
---|
| 161 | // Private data accessors
|
---|
| 162 | inline iconv_t cdTo () const { return fCDTo; }
|
---|
| 163 | inline iconv_t cdFrom () const { return fCDFrom; }
|
---|
| 164 | inline size_t uChSize () const { return fUChSize; }
|
---|
| 165 | inline unsigned int UBO () const { return fUBO; }
|
---|
| 166 |
|
---|
| 167 | protected:
|
---|
| 168 |
|
---|
| 169 | // Hiden defaull constructor
|
---|
| 170 | IconvGNUWrapper();
|
---|
| 171 |
|
---|
| 172 | // Private data accessors
|
---|
| 173 | inline void setCDTo (iconv_t cd) { fCDTo = cd; }
|
---|
| 174 | inline void setCDFrom (iconv_t cd) { fCDFrom = cd; }
|
---|
| 175 | inline void setUChSize (size_t sz) { fUChSize = sz; }
|
---|
| 176 | inline void setUBO (unsigned int u) { fUBO = u; }
|
---|
| 177 |
|
---|
| 178 | private:
|
---|
| 179 | // -----------------------------------------------------------------------
|
---|
| 180 | // Unimplemented constructors and operators
|
---|
| 181 | // -----------------------------------------------------------------------
|
---|
| 182 | IconvGNUWrapper(const IconvGNUWrapper&);
|
---|
| 183 | IconvGNUWrapper& operator=(const IconvGNUWrapper&);
|
---|
| 184 |
|
---|
| 185 | // -----------------------------------------------------------------------
|
---|
| 186 | // Private data members
|
---|
| 187 | //
|
---|
| 188 | // fCDTo
|
---|
| 189 | // Characterset conversion descriptor TO the local-host encoding
|
---|
| 190 | // fCDFrom
|
---|
| 191 | // Characterset conversion descriptor FROM the local-host encoding
|
---|
| 192 | // fUChSize
|
---|
| 193 | // Sizeof the "native unicode" character in bytes
|
---|
| 194 | // fUBO
|
---|
| 195 | // "Native unicode" characters byte order
|
---|
| 196 | // -----------------------------------------------------------------------
|
---|
| 197 | size_t fUChSize;
|
---|
| 198 | unsigned int fUBO;
|
---|
| 199 | iconv_t fCDTo;
|
---|
| 200 | iconv_t fCDFrom;
|
---|
| 201 | };
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | // ---------------------------------------------------------------------------
|
---|
| 206 | // FreeBSD-specific Transcoding Service implementation
|
---|
| 207 | // ---------------------------------------------------------------------------
|
---|
| 208 |
|
---|
| 209 | class XMLUTIL_EXPORT IconvGNUTransService : public XMLTransService, IconvGNUWrapper
|
---|
| 210 | {
|
---|
| 211 | public :
|
---|
| 212 | // -----------------------------------------------------------------------
|
---|
| 213 | // Constructors and Destructor
|
---|
| 214 | // -----------------------------------------------------------------------
|
---|
| 215 | IconvGNUTransService();
|
---|
| 216 | ~IconvGNUTransService();
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | // -----------------------------------------------------------------------
|
---|
| 220 | // Implementation of the virtual transcoding service API
|
---|
| 221 | // -----------------------------------------------------------------------
|
---|
| 222 | virtual int compareIString
|
---|
| 223 | (
|
---|
| 224 | const XMLCh* const comp1
|
---|
| 225 | , const XMLCh* const comp2
|
---|
| 226 | );
|
---|
| 227 |
|
---|
| 228 | virtual int compareNIString
|
---|
| 229 | (
|
---|
| 230 | const XMLCh* const comp1
|
---|
| 231 | , const XMLCh* const comp2
|
---|
| 232 | , const unsigned int maxChars
|
---|
| 233 | );
|
---|
| 234 |
|
---|
| 235 | virtual const XMLCh* getId() const;
|
---|
| 236 |
|
---|
| 237 | virtual bool isSpace(const XMLCh toCheck) const;
|
---|
| 238 |
|
---|
| 239 | virtual XMLLCPTranscoder* makeNewLCPTranscoder();
|
---|
| 240 |
|
---|
| 241 | virtual bool supportsSrcOfs() const;
|
---|
| 242 |
|
---|
| 243 | virtual void upperCase(XMLCh* const toUpperCase) const;
|
---|
| 244 | virtual void lowerCase(XMLCh* const toUpperCase) const;
|
---|
| 245 |
|
---|
| 246 | protected :
|
---|
| 247 | // -----------------------------------------------------------------------
|
---|
| 248 | // Protected virtual methods
|
---|
| 249 | // -----------------------------------------------------------------------
|
---|
| 250 | virtual XMLTranscoder* makeNewXMLTranscoder
|
---|
| 251 | (
|
---|
| 252 | const XMLCh* const encodingName
|
---|
| 253 | , XMLTransService::Codes& resValue
|
---|
| 254 | , const unsigned int blockSize
|
---|
| 255 | , MemoryManager* const manager
|
---|
| 256 | );
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 | private :
|
---|
| 260 | // -----------------------------------------------------------------------
|
---|
| 261 | // Unimplemented constructors and operators
|
---|
| 262 | // -----------------------------------------------------------------------
|
---|
| 263 | IconvGNUTransService(const IconvGNUTransService&);
|
---|
| 264 | IconvGNUTransService& operator=(const IconvGNUTransService&);
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | // -----------------------------------------------------------------------
|
---|
| 268 | // Private data members
|
---|
| 269 | //
|
---|
| 270 | // fUnicodeCP
|
---|
| 271 | // Unicode encoding schema name
|
---|
| 272 | // -----------------------------------------------------------------------
|
---|
| 273 | const char* fUnicodeCP;
|
---|
| 274 |
|
---|
| 275 | };
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 | //----------------------------------------------------------------------------
|
---|
| 279 | // Implementation of the transcoders for arbitrary input characterset is
|
---|
| 280 | // supported ONLY through libiconv interface
|
---|
| 281 | //----------------------------------------------------------------------------
|
---|
| 282 |
|
---|
| 283 | class XMLUTIL_EXPORT IconvGNUTranscoder : public XMLTranscoder, IconvGNUWrapper
|
---|
| 284 | {
|
---|
| 285 | public :
|
---|
| 286 | // -----------------------------------------------------------------------
|
---|
| 287 | // Constructors and Destructor
|
---|
| 288 | // -----------------------------------------------------------------------
|
---|
| 289 | IconvGNUTranscoder(const XMLCh* const encodingName
|
---|
| 290 | , const unsigned int blockSize
|
---|
| 291 | , iconv_t cd_from
|
---|
| 292 | , iconv_t cd_to
|
---|
| 293 | , size_t uchsize
|
---|
| 294 | , unsigned int ubo
|
---|
| 295 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 296 | );
|
---|
| 297 | ~IconvGNUTranscoder();
|
---|
| 298 |
|
---|
| 299 |
|
---|
| 300 | // -----------------------------------------------------------------------
|
---|
| 301 | // Implementation of the virtual transcoder interface
|
---|
| 302 | // -----------------------------------------------------------------------
|
---|
| 303 | virtual unsigned int transcodeFrom
|
---|
| 304 | (
|
---|
| 305 | const XMLByte* const srcData
|
---|
| 306 | , const unsigned int srcCount
|
---|
| 307 | , XMLCh* const toFill
|
---|
| 308 | , const unsigned int maxChars
|
---|
| 309 | , unsigned int& bytesEaten
|
---|
| 310 | , unsigned char* const charSizes
|
---|
| 311 | );
|
---|
| 312 |
|
---|
| 313 | virtual unsigned int transcodeTo
|
---|
| 314 | (
|
---|
| 315 | const XMLCh* const srcData
|
---|
| 316 | , const unsigned int srcCount
|
---|
| 317 | , XMLByte* const toFill
|
---|
| 318 | , const unsigned int maxBytes
|
---|
| 319 | , unsigned int& charsEaten
|
---|
| 320 | , const UnRepOpts options
|
---|
| 321 | );
|
---|
| 322 |
|
---|
| 323 | virtual bool canTranscodeTo
|
---|
| 324 | (
|
---|
| 325 | const unsigned int toCheck
|
---|
| 326 | ) const;
|
---|
| 327 |
|
---|
| 328 | private :
|
---|
| 329 | // -----------------------------------------------------------------------
|
---|
| 330 | // Unimplemented constructors and operators
|
---|
| 331 | // -----------------------------------------------------------------------
|
---|
| 332 | IconvGNUTranscoder();
|
---|
| 333 | IconvGNUTranscoder(const IconvGNUTranscoder&);
|
---|
| 334 | IconvGNUTranscoder& operator=(const IconvGNUTranscoder&);
|
---|
| 335 | };
|
---|
| 336 |
|
---|
| 337 |
|
---|
| 338 | // ---------------------------------------------------------------------------
|
---|
| 339 | // GNU-specific XMLCh <-> local (host) characterset transcoder
|
---|
| 340 | // ---------------------------------------------------------------------------
|
---|
| 341 |
|
---|
| 342 | class XMLUTIL_EXPORT IconvGNULCPTranscoder : public XMLLCPTranscoder, IconvGNUWrapper
|
---|
| 343 | {
|
---|
| 344 | public :
|
---|
| 345 | // -----------------------------------------------------------------------
|
---|
| 346 | // Constructors and Destructor
|
---|
| 347 | // -----------------------------------------------------------------------
|
---|
| 348 |
|
---|
| 349 | IconvGNULCPTranscoder
|
---|
| 350 | (
|
---|
| 351 | iconv_t from,
|
---|
| 352 | iconv_t to,
|
---|
| 353 | size_t uchsize,
|
---|
| 354 | unsigned int ubo
|
---|
| 355 | );
|
---|
| 356 |
|
---|
| 357 | protected:
|
---|
| 358 | IconvGNULCPTranscoder(); // Unimplemented
|
---|
| 359 |
|
---|
| 360 | public:
|
---|
| 361 |
|
---|
| 362 | ~IconvGNULCPTranscoder();
|
---|
| 363 |
|
---|
| 364 |
|
---|
| 365 | // -----------------------------------------------------------------------
|
---|
| 366 | // Implementation of the virtual transcoder interface
|
---|
| 367 | // -----------------------------------------------------------------------
|
---|
| 368 | virtual unsigned int calcRequiredSize(const char* const srcText
|
---|
| 369 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
| 370 |
|
---|
| 371 | virtual unsigned int calcRequiredSize(const XMLCh* const srcText
|
---|
| 372 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
| 373 |
|
---|
| 374 | virtual char* transcode(const XMLCh* const toTranscode);
|
---|
| 375 | virtual char* transcode(const XMLCh* const toTranscode,
|
---|
| 376 | MemoryManager* const manager);
|
---|
| 377 |
|
---|
| 378 | virtual bool transcode
|
---|
| 379 | (
|
---|
| 380 | const XMLCh* const toTranscode
|
---|
| 381 | , char* const toFill
|
---|
| 382 | , const unsigned int maxBytes
|
---|
| 383 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 384 | );
|
---|
| 385 |
|
---|
| 386 | virtual XMLCh* transcode(const char* const toTranscode);
|
---|
| 387 | virtual XMLCh* transcode(const char* const toTranscode,
|
---|
| 388 | MemoryManager* const manager);
|
---|
| 389 |
|
---|
| 390 | virtual bool transcode
|
---|
| 391 | (
|
---|
| 392 | const char* const toTranscode
|
---|
| 393 | , XMLCh* const toFill
|
---|
| 394 | , const unsigned int maxChars
|
---|
| 395 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 396 | );
|
---|
| 397 |
|
---|
| 398 |
|
---|
| 399 | private :
|
---|
| 400 | // -----------------------------------------------------------------------
|
---|
| 401 | // Unimplemented constructors and operators
|
---|
| 402 | // -----------------------------------------------------------------------
|
---|
| 403 | IconvGNULCPTranscoder(const IconvGNULCPTranscoder&);
|
---|
| 404 | IconvGNULCPTranscoder& operator=(const IconvGNULCPTranscoder&);
|
---|
| 405 | };
|
---|
| 406 |
|
---|
| 407 | XERCES_CPP_NAMESPACE_END
|
---|
| 408 |
|
---|
| 409 | #endif /* ICONVGNUTRANSSERVICE */
|
---|
| 410 |
|
---|