source: icXML/icXML-devel/src/icxercesc/util/XMLUTF8Transcoder.hpp @ 2721

Last change on this file since 2721 was 2721, checked in by cameron, 6 years ago

Fix imports in icXML modified Xerces files

File size: 3.9 KB
Line 
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: XMLUTF8Transcoder.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XMLUTF8TRANSCODER_HPP)
23#define XERCESC_INCLUDE_GUARD_XMLUTF8TRANSCODER_HPP
24
25#include <xercesc/util/XercesDefs.hpp>
26#include <icxercesc/util/TransService.hpp>
27#include <xercesc/util/UTFDataFormatException.hpp>
28#include <icxercesc/internal/XMLReader.hpp>
29#include <icxmlc/XMLUTF8CharacterSetAdapter.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33//
34//  This class provides an implementation of the XMLTranscoder interface
35//  for a simple UTF8 transcoder. The parser does some encodings
36//  intrinsically without depending upon external transcoding services.
37//  To make everything more orthogonal, we implement these internal
38//  transcoders using the same transcoder abstraction as the pluggable
39//  transcoding services do.
40//
41class XMLUTIL_EXPORT XMLUTF8Transcoder : public XMLTranscoder
42{
43public :
44        // -----------------------------------------------------------------------
45        //  Public constructors and destructor
46        // -----------------------------------------------------------------------
47        XMLUTF8Transcoder
48        (
49                const   XMLCh* const   encodingName
50                , const XMLSize_t      blockSize
51                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
52        );
53
54        virtual ~XMLUTF8Transcoder();
55
56        // -----------------------------------------------------------------------
57        //  Implementation of the XMLTranscoder interface
58        // -----------------------------------------------------------------------
59        virtual XMLSize_t transcodeFrom
60        (
61                const   XMLByte* const          srcData
62                , const XMLSize_t               srcCount
63                ,       XMLCh* const            toFill
64                , const XMLSize_t               maxChars
65                ,       XMLSize_t&              bytesEaten
66                ,       unsigned char* const    charSizes
67        );
68
69        virtual XMLSize_t transcodeFrom
70        (
71                  const XMLByte* const          srcData
72                , const XMLSize_t               srcCount
73                ,       XMLBuffer &             toFill
74        );
75
76        virtual XMLSize_t transcodeTo
77        (
78                const   XMLCh* const    srcData
79                , const XMLSize_t       srcCount
80                ,       XMLByte* const  toFill
81                , const XMLSize_t       maxBytes
82                ,       XMLSize_t&      charsEaten
83                , const UnRepOpts       options
84        );
85
86        virtual bool canTranscodeTo
87        (
88                const   unsigned int    toCheck
89        );
90
91private :
92
93        inline void checkTrailingBytes
94        (
95                  const XMLByte      toCheck
96                , const unsigned int trailingBytes
97                , const unsigned int position
98        ) const;
99
100private :
101        // -----------------------------------------------------------------------
102        //  Unimplemented constructors and operators
103        // -----------------------------------------------------------------------
104        XMLUTF8Transcoder(const XMLUTF8Transcoder&);
105        XMLUTF8Transcoder& operator=(const XMLUTF8Transcoder&);
106
107};
108
109inline
110void XMLUTF8Transcoder::checkTrailingBytes(const XMLByte      toCheck
111                                                                                  , const unsigned int trailingBytes
112                                                                                  , const unsigned int position) const
113{
114
115        if ((toCheck & 0xC0) != 0x80)
116        {
117                char len[2]  = {(char)(trailingBytes+0x31), 0};
118                char pos[2]  = {(char)(position+0x31), 0};
119                char byte[2] = {toCheck,0};
120                ThrowXMLwithMemMgr3(UTFDataFormatException, XMLExcepts::UTF8_FormatError, pos, byte, len, getMemoryManager());
121        }
122
123}
124
125XERCES_CPP_NAMESPACE_END
126
127#endif
Note: See TracBrowser for help on using the repository browser.