ICUTransService.hpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:12k
源码类别:

词法分析

开发平台:

Visual C++

  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.  * $Log: ICUTransService.hpp,v $
  58.  * Revision 1.8  2003/05/17 16:32:17  knoaman
  59.  * Memory manager implementation : transcoder update.
  60.  *
  61.  * Revision 1.7  2003/05/15 18:47:03  knoaman
  62.  * Partial implementation of the configurable memory manager.
  63.  *
  64.  * Revision 1.6  2003/03/07 18:15:57  tng
  65.  * Return a reference instead of void for operator=
  66.  *
  67.  * Revision 1.5  2002/11/22 14:56:47  tng
  68.  * 390: Uniconv390 support.  Patch by Chris Larsson and Stephen Dulin.
  69.  *
  70.  * Revision 1.4  2002/11/11 14:08:01  tng
  71.  * Fix: UConverter should be declared outside xerces-c++ namespace
  72.  *
  73.  * Revision 1.3  2002/11/04 15:14:33  tng
  74.  * C++ Namespace Support.
  75.  *
  76.  * Revision 1.2  2002/04/09 15:44:00  knoaman
  77.  * Add lower case string support.
  78.  *
  79.  * Revision 1.1.1.1  2002/02/01 22:22:36  peiyongz
  80.  * sane_include
  81.  *
  82.  * Revision 1.10  2000/03/18 00:00:03  roddey
  83.  * Initial updates for two way transcoding support
  84.  *
  85.  * Revision 1.9  2000/03/02 19:55:34  roddey
  86.  * This checkin includes many changes done while waiting for the
  87.  * 1.1.0 code to be finished. I can't list them all here, but a list is
  88.  * available elsewhere.
  89.  *
  90.  * Revision 1.8  2000/02/06 07:48:32  rahulj
  91.  * Year 2K copyright swat.
  92.  *
  93.  * Revision 1.7  2000/01/25 22:49:56  roddey
  94.  * Moved the supportsSrcOfs() method from the individual transcoder to the
  95.  * transcoding service, where it should have been to begin with.
  96.  *
  97.  * Revision 1.6  2000/01/25 19:19:08  roddey
  98.  * Simple addition of a getId() method to the xcode and netacess abstractions to
  99.  * allow each impl to give back an id string.
  100.  *
  101.  * Revision 1.5  2000/01/19 23:21:11  abagchi
  102.  * Made this file compatible with ICU 1.4
  103.  *
  104.  * Revision 1.4  2000/01/19 00:58:07  roddey
  105.  * Update to support new ICU 1.4 release.
  106.  *
  107.  * Revision 1.3  1999/12/18 00:22:32  roddey
  108.  * Changes to support the new, completely orthagonal, transcoder architecture.
  109.  *
  110.  * Revision 1.2  1999/12/15 19:43:45  roddey
  111.  * Now implements the new transcoding abstractions, with separate interface
  112.  * classes for XML transcoders and local code page transcoders.
  113.  *
  114.  * Revision 1.1.1.1  1999/11/09 01:06:08  twl
  115.  * Initial checkin
  116.  *
  117.  * Revision 1.3  1999/11/08 20:45:34  rahul
  118.  * Swat for adding in Product name and CVS comment log variable.
  119.  *
  120.  */
  121. #ifndef ICUTRANSSERVICE_HPP
  122. #define ICUTRANSSERVICE_HPP
  123. #include <xercesc/util/Mutexes.hpp>
  124. #include <xercesc/util/TransService.hpp>
  125. struct UConverter;
  126. XERCES_CPP_NAMESPACE_BEGIN
  127. class XMLUTIL_EXPORT ICUTransService : public XMLTransService
  128. {
  129. public :
  130.     friend class Uniconv390TransService;
  131.     // -----------------------------------------------------------------------
  132.     //  Constructors and Destructor
  133.     // -----------------------------------------------------------------------
  134.     ICUTransService();
  135.     ~ICUTransService();
  136.     // -----------------------------------------------------------------------
  137.     //  Implementation of the virtual transcoding service API
  138.     // -----------------------------------------------------------------------
  139.     virtual int compareIString
  140.     (
  141.         const   XMLCh* const    comp1
  142.         , const XMLCh* const    comp2
  143.     );
  144.     virtual int compareNIString
  145.     (
  146.         const   XMLCh* const    comp1
  147.         , const XMLCh* const    comp2
  148.         , const unsigned int    maxChars
  149.     );
  150.     virtual const XMLCh* getId() const;
  151.     virtual bool isSpace(const XMLCh toCheck) const;
  152.     virtual XMLLCPTranscoder* makeNewLCPTranscoder();
  153.     virtual bool supportsSrcOfs() const;
  154.     virtual void upperCase(XMLCh* const toUpperCase) const;
  155.     virtual void lowerCase(XMLCh* const toLowerCase) const;
  156. protected :
  157.     // -----------------------------------------------------------------------
  158.     //  Protected virtual methods
  159.     // -----------------------------------------------------------------------
  160.     virtual XMLTranscoder* makeNewXMLTranscoder
  161.     (
  162.         const   XMLCh* const            encodingName
  163.         ,       XMLTransService::Codes& resValue
  164.         , const unsigned int            blockSize
  165.         ,       MemoryManager* const    manager
  166.     );
  167. private :
  168.     // -----------------------------------------------------------------------
  169.     //  Unimplemented constructors and operators
  170.     // -----------------------------------------------------------------------
  171.     ICUTransService(const ICUTransService&);
  172.     ICUTransService& operator=(const ICUTransService&);
  173. };
  174. class XMLUTIL_EXPORT ICUTranscoder : public XMLTranscoder
  175. {
  176. public :
  177.     // -----------------------------------------------------------------------
  178.     //  Constructors and Destructor
  179.     // -----------------------------------------------------------------------
  180.     ICUTranscoder
  181.     (
  182.         const   XMLCh* const        encodingName
  183.         ,       UConverter* const   toAdopt
  184.         , const unsigned int        blockSize
  185.         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
  186.     );
  187.     ~ICUTranscoder();
  188.     // -----------------------------------------------------------------------
  189.     //  Implementation of the virtual transcoder interface
  190.     // -----------------------------------------------------------------------
  191.     virtual unsigned int transcodeFrom
  192.     (
  193.         const   XMLByte* const          srcData
  194.         , const unsigned int            srcCount
  195.         ,       XMLCh* const            toFill
  196.         , const unsigned int            maxChars
  197.         ,       unsigned int&           bytesEaten
  198.         ,       unsigned char* const    charSizes
  199.     );
  200.     virtual unsigned int transcodeTo
  201.     (
  202.         const   XMLCh* const    srcData
  203.         , const unsigned int    srcCount
  204.         ,       XMLByte* const  toFill
  205.         , const unsigned int    maxBytes
  206.         ,       unsigned int&   charsEaten
  207.         , const UnRepOpts       options
  208.     );
  209.     virtual bool canTranscodeTo
  210.     (
  211.         const   unsigned int    toCheck
  212.     )   const;
  213. private :
  214.     // -----------------------------------------------------------------------
  215.     //  Unimplemented constructors and operators
  216.     // -----------------------------------------------------------------------
  217.     ICUTranscoder();
  218.     ICUTranscoder(const ICUTranscoder&);
  219.     ICUTranscoder& operator=(const ICUTranscoder&);
  220.     // -----------------------------------------------------------------------
  221.     //  Private data members
  222.     //
  223.     //  fConverter
  224.     //      This is a pointer to the ICU converter that this transcoder
  225.     //      uses.
  226.     //
  227.     //  fFixed
  228.     //      This is set to true if the encoding is a fixed size one. This
  229.     //      can be used to optimize some operations.
  230.     //
  231.     //  fSrcOffsets
  232.     //      This is an array of longs, which are allocated to the size of
  233.     //      the trancoding block (if any) indicated in the ctor. It is used
  234.     //      to get the character offsets from ICU, which are then translated
  235.     //      into an array of char sizes for return.
  236.     // -----------------------------------------------------------------------
  237.     UConverter*     fConverter;
  238.     bool            fFixed;
  239.     XMLUInt32*      fSrcOffsets;
  240. };
  241. class XMLUTIL_EXPORT ICULCPTranscoder : public XMLLCPTranscoder
  242. {
  243. public :
  244.     // -----------------------------------------------------------------------
  245.     //  Constructors and Destructor
  246.     // -----------------------------------------------------------------------
  247.     ICULCPTranscoder(UConverter* const toAdopt);
  248.     ~ICULCPTranscoder();
  249.     // -----------------------------------------------------------------------
  250.     //  Implementation of the virtual transcoder interface
  251.     // -----------------------------------------------------------------------
  252.     virtual unsigned int calcRequiredSize(const char* const srcText);
  253.     virtual unsigned int calcRequiredSize(const XMLCh* const srcText);
  254.     virtual char* transcode(const XMLCh* const toTranscode);
  255.     virtual char* transcode(const XMLCh* const toTranscode,
  256.                             MemoryManager* const manager);
  257.     virtual XMLCh* transcode(const char* const toTranscode);
  258.     virtual XMLCh* transcode(const char* const toTranscode,
  259.                              MemoryManager* const manager);
  260.     virtual bool transcode
  261.     (
  262.         const   char* const     toTranscode
  263.         ,       XMLCh* const    toFill
  264.         , const unsigned int    maxChars
  265.     );
  266.     virtual bool transcode
  267.     (
  268.         const   XMLCh* const    toTranscode
  269.         ,       char* const     toFill
  270.         , const unsigned int    maxChars
  271.     );
  272. private :
  273.     // -----------------------------------------------------------------------
  274.     //  Unimplemented constructors and operators
  275.     // -----------------------------------------------------------------------
  276.     ICULCPTranscoder();
  277.     ICULCPTranscoder(const ICULCPTranscoder&);
  278.     ICULCPTranscoder& operator=(const ICULCPTranscoder&);
  279.     // -----------------------------------------------------------------------
  280.     //  Private data members
  281.     //
  282.     //  fConverter
  283.     //      This is a pointer to the ICU converter that this transcoder
  284.     //      uses.
  285.     //
  286.     //  fMutex
  287.     //      We have to synchronize threaded calls to the converter.
  288.     // -----------------------------------------------------------------------
  289.     UConverter*     fConverter;
  290.     XMLMutex        fMutex;
  291. };
  292. XERCES_CPP_NAMESPACE_END
  293. #endif