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