xmlreader.hpp
来自「IBM的解析xml的工具Xerces的源代码」· HPP 代码 · 共 954 行 · 第 1/3 页
HPP
954 行
inline unsigned long XMLReader::charsLeftInBuffer() const{ return fCharsAvail - fCharIndex;}// ---------------------------------------------------------------------------// XMLReader: Getter methods// ---------------------------------------------------------------------------inline XMLSSize_t XMLReader::getColumnNumber() const{ return fCurCol;}inline const XMLCh* XMLReader::getEncodingStr() const{ return fEncodingStr;}inline XMLSSize_t XMLReader::getLineNumber() const{ return fCurLine;}inline bool XMLReader::getNoMoreFlag() const{ return fNoMore;}inline const XMLCh* XMLReader::getPublicId() const{ return fPublicId;}inline unsigned int XMLReader::getReaderNum() const{ return fReaderNum;}inline XMLReader::RefFrom XMLReader::getRefFrom() const{ return fRefFrom;}inline XMLReader::Sources XMLReader::getSource() const{ return fSource;}inline const XMLCh* XMLReader::getSystemId() const{ return fSystemId;}inline bool XMLReader::getThrowAtEnd() const{ return fThrowAtEnd;}inline XMLReader::Types XMLReader::getType() const{ return fType;}// ---------------------------------------------------------------------------// XMLReader: Setter methods// ---------------------------------------------------------------------------inline void XMLReader::setReaderNum(const unsigned int newNum){ fReaderNum = newNum;}inline void XMLReader::setThrowAtEnd(const bool newValue){ fThrowAtEnd = newValue;}inline void XMLReader::setXMLVersion(const XMLVersion version){ fXMLVersion = version; if (version == XMLV1_1) { fNEL = true; fgCharCharsTable = XMLChar1_1::fgCharCharsTable1_1; } else { fNEL = XMLChar1_0::enableNEL; fgCharCharsTable = XMLChar1_0::fgCharCharsTable1_0; }}// ---------------------------------------------------------------------------//// XMLReader: movePlainContentChars()//// Move as many plain (no special handling of any sort required) content// characters as possible from this reader to the supplied destination buffer.//// This is THE hottest performance spot in the parser.//// ---------------------------------------------------------------------------inline void XMLReader::movePlainContentChars(XMLBuffer &dest){ unsigned int count = fCharIndex; while (fCharIndex < fCharsAvail) { if (!isPlainContentChar(fCharBuf[fCharIndex])) break; fCharIndex++; } if (count != fCharIndex) { fCurCol += (fCharIndex - count); dest.append(&fCharBuf[count], fCharIndex - count); }}// ---------------------------------------------------------------------------// XMLReader: getNextCharIfNot() method inlined for speed// ---------------------------------------------------------------------------inline bool XMLReader::getNextCharIfNot(const XMLCh chNotToGet, XMLCh& chGotten){ // // See if there is at least a char in the buffer. Else, do the buffer // reload logic. // if (fCharIndex >= fCharsAvail) { // If fNoMore is set, then we have nothing else to give if (fNoMore) return false; // Try to refresh if (!refreshCharBuffer()) return false; } // Check the next char if (fCharBuf[fCharIndex] == chNotToGet) return false; // Its not the one we want to skip so bump the index chGotten = fCharBuf[fCharIndex++]; // Handle end of line normalization and line/col member maintenance. handleEOL(chGotten, false); return true;}// ---------------------------------------------------------------------------// XMLReader: getNextChar() method inlined for speed// ---------------------------------------------------------------------------inline bool XMLReader::getNextChar(XMLCh& chGotten){ // // See if there is at least a char in the buffer. Else, do the buffer // reload logic. // if (fCharIndex >= fCharsAvail) { // If fNoMore is set, then we have nothing else to give if (fNoMore) return false; // Try to refresh if (!refreshCharBuffer()) return false; } chGotten = fCharBuf[fCharIndex++]; // Handle end of line normalization and line/col member maintenance. handleEOL(chGotten, false); return true;}// ---------------------------------------------------------------------------// XMLReader: peekNextChar() method inlined for speed// ---------------------------------------------------------------------------inline bool XMLReader::peekNextChar(XMLCh& chGotten){ // // If there is something still in the buffer, get it. Else do the reload // scenario. // if (fCharIndex >= fCharsAvail) { // Try to refresh the buffer if (!refreshCharBuffer()) { chGotten = chNull; return false; } } chGotten = fCharBuf[fCharIndex]; // // Even though we are only peeking, we have to act the same as the // normal char get method in regards to newline normalization, though // its not as complicated as the actual character getting method's. // if ((chGotten == chCR || ((chGotten == chNEL || chGotten == chLineSeparator) && fNEL)) && (fSource == Source_External)) chGotten = chLF; return true;}/*** * * XML1.1 * * 2.11 End-of-Line Handling * * XML parsed entities are often stored in computer files which, for editing * convenience, are organized into lines. These lines are typically separated * by some combination of the characters CARRIAGE RETURN (#xD) and LINE FEED (#xA). * * To simplify the tasks of applications, the XML processor MUST behave as if * it normalized all line breaks in external parsed entities (including the document * entity) on input, before parsing, by translating all of the following to a single * #xA character: * * 1. the two-character sequence #xD #xA * 2. the two-character sequence #xD #x85 * 3. the single character #x85 * 4. the single character #x2028 * 5. any #xD character that is not immediately followed by #xA or #x85. * * ***/inline void XMLReader::handleEOL(XMLCh& curCh, bool inDecl){ // 1. the two-character sequence #xD #xA // 2. the two-character sequence #xD #x85 // 5. any #xD character that is not immediately followed by #xA or #x85. if (curCh == chCR) { fCurCol = 1; fCurLine++; // // If not already internalized, then convert it to an // LF and eat any following LF. // if (fSource == Source_External) { if ((fCharIndex < fCharsAvail) || refreshCharBuffer()) { if ( fCharBuf[fCharIndex] == chLF || ((fCharBuf[fCharIndex] == chNEL) && fNEL) ) { fCharIndex++; } } curCh = chLF; } } else if (curCh == chLF) { fCurCol = 1; fCurLine++; } // 3. the single character #x85 // 4. the single character #x2028 else if (curCh == chNEL || curCh == chLineSeparator) { if (inDecl && fXMLVersion == XMLV1_1) { /*** * XML1.1 * * 2.11 End-of-Line Handling * ... * The characters #x85 and #x2028 cannot be reliably recognized and translated * until an entity's encoding declaration (if present) has been read. * Therefore, it is a fatal error to use them within the XML declaration or * text declaration. * ***/ ThrowXMLwithMemMgr1 ( TranscodingException , XMLExcepts::Reader_NelLsepinDecl , fSystemId , fMemoryManager ); } if (fNEL && fSource == Source_External) { fCurCol = 1; fCurLine++; curCh = chLF; } } else { fCurCol++; } return;}XERCES_CPP_NAMESPACE_END#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?