source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/XMLUTF8Transcoder.hpp @ 2674

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