source: NonGTP/Xerces/xerces/include/xercesc/util/XMLUTF8Transcoder.hpp @ 358

Revision 358, 3.9 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2000,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef XMLUTF8TRANSCODER_HPP
18#define XMLUTF8TRANSCODER_HPP
19
20#include <xercesc/util/XercesDefs.hpp>
21#include <xercesc/util/TransService.hpp>
22#include <xercesc/util/UTFDataFormatException.hpp>
23
24XERCES_CPP_NAMESPACE_BEGIN
25
26//
27//  This class provides an implementation of the XMLTranscoder interface
28//  for a simple UTF8 transcoder. The parser does some encodings
29//  intrinsically without depending upon external transcoding services.
30//  To make everything more orthagonal, we implement these internal
31//  transcoders using the same transcoder abstraction as the pluggable
32//  transcoding services do.
33//
34class XMLUTIL_EXPORT XMLUTF8Transcoder : public XMLTranscoder
35{
36public :
37    // -----------------------------------------------------------------------
38    //  Public constructors and destructor
39    // -----------------------------------------------------------------------
40    XMLUTF8Transcoder
41    (
42        const   XMLCh* const    encodingName
43        , const unsigned int    blockSize
44        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
45    );
46
47    virtual ~XMLUTF8Transcoder();
48
49
50    // -----------------------------------------------------------------------
51    //  Implementation of the XMLTranscoder interface
52    // -----------------------------------------------------------------------
53    virtual unsigned int transcodeFrom
54    (
55        const   XMLByte* const          srcData
56        , const unsigned int            srcCount
57        ,       XMLCh* const            toFill
58        , const unsigned int            maxChars
59        ,       unsigned int&           bytesEaten
60        ,       unsigned char* const    charSizes
61    );
62
63    virtual unsigned int transcodeTo
64    (
65        const   XMLCh* const    srcData
66        , const unsigned int    srcCount
67        ,       XMLByte* const  toFill
68        , const unsigned int    maxBytes
69        ,       unsigned int&   charsEaten
70        , const UnRepOpts       options
71    );
72
73    virtual bool canTranscodeTo
74    (
75        const   unsigned int    toCheck
76    )   const;
77
78
79private :
80
81    inline void checkTrailingBytes(
82                                    const XMLByte      toCheck
83                                  , const unsigned int trailingBytes
84                                  , const unsigned int position       
85                                  ) const;
86
87private :
88    // -----------------------------------------------------------------------
89    //  Unimplemented constructors and operators
90    // -----------------------------------------------------------------------
91    XMLUTF8Transcoder(const XMLUTF8Transcoder&);
92    XMLUTF8Transcoder& operator=(const XMLUTF8Transcoder&);
93};
94
95inline
96void XMLUTF8Transcoder::checkTrailingBytes(const XMLByte      toCheck
97                                          , const unsigned int trailingBytes
98                                          , const unsigned int position) const
99{
100
101    if((toCheck & 0xC0) != 0x80)
102    {
103        char len[2]  = {(char)(trailingBytes+0x31), 0};
104        char pos[2]  = {(char)(position+0x31), 0};
105        char byte[2] = {toCheck,0};
106        ThrowXMLwithMemMgr3(UTFDataFormatException, XMLExcepts::UTF8_FormatError, pos, byte, len, getMemoryManager());
107    }
108
109}
110
111XERCES_CPP_NAMESPACE_END
112
113#endif
Note: See TracBrowser for help on using the repository browser.