Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:11

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_ICONVGNUTRANSSERVICE_HPP)
0023 #define XERCESC_INCLUDE_GUARD_ICONVGNUTRANSSERVICE_HPP
0024 
0025 #include <xercesc/util/TransService.hpp>
0026 #include <xercesc/util/Mutexes.hpp>
0027 
0028 #include <iconv.h>
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 // ---------------------------------------------------------------------------
0033 //  Libiconv wrapper (low-level conversion utilities collection)
0034 // ---------------------------------------------------------------------------
0035 
0036 class XMLUTIL_EXPORT IconvGNUWrapper
0037 {
0038 public:
0039     // -----------------------------------------------------------------------
0040     //  Constructors and Destructor
0041     // -----------------------------------------------------------------------
0042     IconvGNUWrapper
0043     (
0044       iconv_t       cd_from,
0045       iconv_t       cd_to,
0046       size_t        uchsize,
0047       unsigned int  ubo,
0048       MemoryManager* manager
0049     );
0050     virtual ~IconvGNUWrapper();
0051 
0052     // Convert "native unicode" character into XMLCh
0053     void    mbcToXMLCh (const char *mbc, XMLCh *toRet) const;
0054 
0055     // Convert XMLCh into "native unicode" character
0056     void    xmlChToMbc (XMLCh xch, char *mbc) const;
0057 
0058     // Fill array of XMLCh characters with data, supplied in the array
0059     // of "native unicode" characters.
0060     XMLCh*  mbsToXML (
0061       const char*   mbs_str,
0062       XMLCh*        xml_str,
0063       size_t        cnt
0064     ) const;
0065 
0066 
0067     // Fill array of "native unicode" characters with data, supplied
0068     // in the array of XMLCh characters.
0069     char*   xmlToMbs
0070     (
0071       const XMLCh*  xml_str,
0072       char*     mbs_str,
0073       size_t        cnt
0074     ) const;
0075 
0076     // Private data accessors
0077     inline iconv_t  cdTo () const { return fCDTo; }
0078     inline iconv_t  cdFrom () const { return fCDFrom; }
0079     inline size_t   uChSize () const { return fUChSize; }
0080     inline unsigned int UBO () const { return fUBO; }
0081 
0082 protected:
0083     // The following four functions should called with the fMutex
0084     // locked.
0085     //
0086 
0087     // Return uppercase equivalent for XMLCh
0088     XMLCh   toUpper (const XMLCh ch);
0089 
0090     // Return uppercase equivalent for XMLCh
0091     XMLCh   toLower (const XMLCh ch);
0092 
0093     // Wrapper around the iconv() for transcoding from the local charset
0094     size_t  iconvFrom
0095     (
0096       const char    *fromPtr,
0097       size_t        *fromLen,
0098       char      **toPtr,
0099       size_t        toLen
0100     );
0101 
0102     // Wrapper around the iconv() for transcoding to the local charset
0103     size_t  iconvTo
0104     (
0105       const char    *fromPtr,
0106       size_t        *fromLen,
0107       char      **toPtr,
0108       size_t        toLen
0109     );
0110 
0111 protected:
0112 
0113     // Hidden constructor
0114     IconvGNUWrapper(MemoryManager* manager);
0115 
0116     // Private data accessors
0117     inline void setCDTo (iconv_t cd) { fCDTo = cd; }
0118     inline void setCDFrom (iconv_t cd) { fCDFrom = cd; }
0119     inline void setUChSize (size_t sz) { fUChSize = sz; }
0120     inline void setUBO (unsigned int u) { fUBO = u; }
0121 
0122 private:
0123     // -----------------------------------------------------------------------
0124     //  Unimplemented constructors and operators
0125     // -----------------------------------------------------------------------
0126     IconvGNUWrapper(const IconvGNUWrapper&);
0127     IconvGNUWrapper& operator=(const IconvGNUWrapper&);
0128 
0129     // -----------------------------------------------------------------------
0130     //  Private data members
0131     //
0132     //  fCDTo
0133     //      Characterset conversion descriptor TO the local-host encoding
0134     //  fCDFrom
0135     //      Characterset conversion descriptor FROM the local-host encoding
0136     //  fUChSize
0137     //      Sizeof the "native unicode" character in bytes
0138     //  fUBO
0139     //      "Native unicode" characters byte order
0140     // -----------------------------------------------------------------------
0141     size_t  fUChSize;
0142     unsigned int fUBO;
0143     iconv_t fCDTo;
0144     iconv_t fCDFrom;
0145 
0146 protected:
0147     XMLMutex    fMutex;
0148 };
0149 
0150 
0151 
0152 // ---------------------------------------------------------------------------
0153 //  FreeBSD-specific Transcoding Service implementation
0154 // ---------------------------------------------------------------------------
0155 
0156 class XMLUTIL_EXPORT IconvGNUTransService : public XMLTransService, IconvGNUWrapper
0157 {
0158 public :
0159     // -----------------------------------------------------------------------
0160     //  Constructors and Destructor
0161     // -----------------------------------------------------------------------
0162     IconvGNUTransService(MemoryManager* manager);
0163     ~IconvGNUTransService();
0164 
0165 
0166     // -----------------------------------------------------------------------
0167     //  Implementation of the virtual transcoding service API
0168     // -----------------------------------------------------------------------
0169     virtual int compareIString
0170     (
0171         const   XMLCh* const    comp1
0172         , const XMLCh* const    comp2
0173     );
0174 
0175     virtual int compareNIString
0176     (
0177         const   XMLCh* const    comp1
0178         , const XMLCh* const    comp2
0179         , const XMLSize_t       maxChars
0180     );
0181 
0182     virtual const XMLCh* getId() const;
0183 
0184     virtual XMLLCPTranscoder* makeNewLCPTranscoder(MemoryManager* manager);
0185 
0186     virtual bool supportsSrcOfs() const;
0187 
0188     virtual void upperCase(XMLCh* const toUpperCase);
0189     virtual void lowerCase(XMLCh* const toUpperCase);
0190 
0191 protected :
0192     // -----------------------------------------------------------------------
0193     //  Protected virtual methods
0194     // -----------------------------------------------------------------------
0195     virtual XMLTranscoder* makeNewXMLTranscoder
0196     (
0197         const   XMLCh* const            encodingName
0198         ,       XMLTransService::Codes& resValue
0199         , const XMLSize_t               blockSize
0200         ,       MemoryManager* const    manager
0201     );
0202 
0203 
0204 private :
0205     // -----------------------------------------------------------------------
0206     //  Unimplemented constructors and operators
0207     // -----------------------------------------------------------------------
0208     IconvGNUTransService(const IconvGNUTransService&);
0209     IconvGNUTransService& operator=(const IconvGNUTransService&);
0210 
0211 
0212     // -----------------------------------------------------------------------
0213     //  Private data members
0214     //
0215     //  fUnicodeCP
0216     //      Unicode encoding schema name
0217     // -----------------------------------------------------------------------
0218     const char* fUnicodeCP;
0219 
0220 };
0221 
0222 
0223 //----------------------------------------------------------------------------
0224 // Implementation of the transcoders for arbitrary input characterset is
0225 // supported ONLY through libiconv interface
0226 //----------------------------------------------------------------------------
0227 
0228 class XMLUTIL_EXPORT IconvGNUTranscoder : public XMLTranscoder, IconvGNUWrapper
0229 {
0230 public :
0231     // -----------------------------------------------------------------------
0232     //  Constructors and Destructor
0233     // -----------------------------------------------------------------------
0234     IconvGNUTranscoder(const    XMLCh* const    encodingName
0235         , const XMLSize_t   blockSize
0236         ,   iconv_t     cd_from
0237         ,   iconv_t     cd_to
0238         ,   size_t      uchsize
0239         ,   unsigned int    ubo
0240         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0241     );
0242     ~IconvGNUTranscoder();
0243 
0244 
0245     // -----------------------------------------------------------------------
0246     //  Implementation of the virtual transcoder interface
0247     // -----------------------------------------------------------------------
0248     virtual XMLSize_t transcodeFrom
0249     (
0250         const   XMLByte* const          srcData
0251         , const XMLSize_t               srcCount
0252         ,       XMLCh* const            toFill
0253         , const XMLSize_t               maxChars
0254         ,       XMLSize_t&              bytesEaten
0255         ,       unsigned char* const    charSizes
0256     );
0257 
0258     virtual XMLSize_t transcodeTo
0259     (
0260         const   XMLCh* const    srcData
0261         , const XMLSize_t       srcCount
0262         ,       XMLByte* const  toFill
0263         , const XMLSize_t       maxBytes
0264         ,       XMLSize_t&      charsEaten
0265         , const UnRepOpts       options
0266     );
0267 
0268     virtual bool canTranscodeTo
0269     (
0270         const   unsigned int    toCheck
0271     );
0272 
0273 private :
0274     // -----------------------------------------------------------------------
0275     //  Unimplemented constructors and operators
0276     // -----------------------------------------------------------------------
0277     IconvGNUTranscoder();
0278     IconvGNUTranscoder(const IconvGNUTranscoder&);
0279     IconvGNUTranscoder& operator=(const IconvGNUTranscoder&);
0280 };
0281 
0282 
0283 // ---------------------------------------------------------------------------
0284 //  GNU-specific XMLCh <-> local (host) characterset transcoder
0285 // ---------------------------------------------------------------------------
0286 
0287 class XMLUTIL_EXPORT IconvGNULCPTranscoder : public XMLLCPTranscoder, IconvGNUWrapper
0288 {
0289 public :
0290     // -----------------------------------------------------------------------
0291     //  Constructors and Destructor
0292     // -----------------------------------------------------------------------
0293 
0294     IconvGNULCPTranscoder
0295     (
0296       iconv_t       from,
0297       iconv_t       to,
0298       size_t        uchsize,
0299       unsigned int  ubo,
0300       MemoryManager* manager
0301     );
0302 
0303 protected:
0304     IconvGNULCPTranscoder();    // Unimplemented
0305 
0306 public:
0307 
0308     ~IconvGNULCPTranscoder();
0309 
0310 
0311     // -----------------------------------------------------------------------
0312     //  Implementation of the virtual transcoder interface
0313     // -----------------------------------------------------------------------
0314     virtual char* transcode(const XMLCh* const toTranscode,
0315                             MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0316 
0317     virtual XMLCh* transcode(const char* const toTranscode,
0318                              MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0319 
0320 
0321     // -----------------------------------------------------------------------
0322     //  DEPRECATED old transcode interface
0323     // -----------------------------------------------------------------------
0324     virtual XMLSize_t calcRequiredSize(const char* const srcText
0325         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0326 
0327     virtual XMLSize_t calcRequiredSize(const XMLCh* const srcText
0328         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0329 
0330     virtual bool transcode
0331     (
0332         const   char* const     toTranscode
0333         ,       XMLCh* const    toFill
0334         , const XMLSize_t       maxChars
0335         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0336     );
0337 
0338     virtual bool transcode
0339     (
0340         const   XMLCh* const    toTranscode
0341         ,       char* const     toFill
0342         , const XMLSize_t       maxChars
0343         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0344     );
0345 
0346 
0347 private :
0348     // -----------------------------------------------------------------------
0349     //  Unimplemented constructors and operators
0350     // -----------------------------------------------------------------------
0351     IconvGNULCPTranscoder(const IconvGNULCPTranscoder&);
0352     IconvGNULCPTranscoder& operator=(const IconvGNULCPTranscoder&);
0353 };
0354 
0355 XERCES_CPP_NAMESPACE_END
0356 
0357 #endif /* ICONVGNUTRANSSERVICE */
0358 
0359