Back to home page

EIC code displayed by LXR

 
 

    


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

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_XMLUTF8TRANSCODER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLUTF8TRANSCODER_HPP
0024 
0025 #include <xercesc/util/XercesDefs.hpp>
0026 #include <xercesc/util/TransService.hpp>
0027 #include <xercesc/util/UTFDataFormatException.hpp>
0028 
0029 XERCES_CPP_NAMESPACE_BEGIN
0030 
0031 //
0032 //  This class provides an implementation of the XMLTranscoder interface
0033 //  for a simple UTF8 transcoder. The parser does some encodings
0034 //  intrinsically without depending upon external transcoding services.
0035 //  To make everything more orthogonal, we implement these internal
0036 //  transcoders using the same transcoder abstraction as the pluggable
0037 //  transcoding services do.
0038 //
0039 class XMLUTIL_EXPORT XMLUTF8Transcoder : public XMLTranscoder
0040 {
0041 public :
0042     // -----------------------------------------------------------------------
0043     //  Public constructors and destructor
0044     // -----------------------------------------------------------------------
0045     XMLUTF8Transcoder
0046     (
0047         const   XMLCh* const   encodingName
0048         , const XMLSize_t      blockSize
0049         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0050     );
0051 
0052     virtual ~XMLUTF8Transcoder();
0053 
0054 
0055     // -----------------------------------------------------------------------
0056     //  Implementation of the XMLTranscoder interface
0057     // -----------------------------------------------------------------------
0058     virtual XMLSize_t transcodeFrom
0059     (
0060         const   XMLByte* const          srcData
0061         , const XMLSize_t               srcCount
0062         ,       XMLCh* const            toFill
0063         , const XMLSize_t               maxChars
0064         ,       XMLSize_t&              bytesEaten
0065         ,       unsigned char* const    charSizes
0066     );
0067 
0068     virtual XMLSize_t transcodeTo
0069     (
0070         const   XMLCh* const    srcData
0071         , const XMLSize_t       srcCount
0072         ,       XMLByte* const  toFill
0073         , const XMLSize_t       maxBytes
0074         ,       XMLSize_t&      charsEaten
0075         , const UnRepOpts       options
0076     );
0077 
0078     virtual bool canTranscodeTo
0079     (
0080         const   unsigned int    toCheck
0081     );
0082 
0083 
0084 private :
0085 
0086     inline void checkTrailingBytes(
0087                                     const XMLByte      toCheck
0088                                   , const unsigned int trailingBytes
0089                                   , const unsigned int position       
0090                                   ) const;
0091 
0092 private :
0093     // -----------------------------------------------------------------------
0094     //  Unimplemented constructors and operators
0095     // -----------------------------------------------------------------------
0096     XMLUTF8Transcoder(const XMLUTF8Transcoder&);
0097     XMLUTF8Transcoder& operator=(const XMLUTF8Transcoder&);
0098 };
0099 
0100 inline 
0101 void XMLUTF8Transcoder::checkTrailingBytes(const XMLByte      toCheck
0102                                           , const unsigned int trailingBytes
0103                                           , const unsigned int position) const
0104 {
0105 
0106     if((toCheck & 0xC0) != 0x80) 
0107     {
0108         char len[2]  = {(char)(trailingBytes+0x31), 0};
0109         char pos[2]  = {(char)(position+0x31), 0};
0110         char byte[2] = {(char)toCheck,0};
0111         ThrowXMLwithMemMgr3(UTFDataFormatException, XMLExcepts::UTF8_FormatError, pos, byte, len, getMemoryManager());
0112     }
0113 
0114 }
0115 
0116 XERCES_CPP_NAMESPACE_END
0117 
0118 #endif