xercesxpath.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,455 行 · 第 1/4 页
CPP
1,455 行
// // [37] NameTest ::= '*' | NCName ':' '*' | QName // [34] MultiplyOperator ::= '*' // case CHARTYPE_STAR: // '*' // // 3.7 Lexical Structure // // If there is a preceding token and the preceding token is not one of @, ::, (, [, , or // an Operator, then a * must be recognized as a MultiplyOperator. // // Otherwise, the token must not be recognized as a MultiplyOperator. // if (starIsMultiplyOperator) { addToken(tokens, XercesXPath::EXPRTOKEN_OPERATOR_MULT); starIsMultiplyOperator = false; } else { addToken(tokens, XercesXPath::EXPRTOKEN_NAMETEST_ANY); starIsMultiplyOperator = true; } ++currentOffset; break; // // NCName, QName and non-terminals // case CHARTYPE_NONASCII: // possibly a valid non-ascii 'Letter' (BaseChar | Ideographic) case CHARTYPE_LETTER: case CHARTYPE_UNDERSCORE: // // 3.7 Lexical Structure // // If there is a preceding token and the preceding token is not one of @, ::, (, [, , or // an Operator, then an NCName must be recognized as an OperatorName. // // If the character following an NCName (possibly after intervening ExprWhitespace) is (, // then the token must be recognized as a NodeType or a FunctionName. // // If the two characters following an NCName (possibly after intervening ExprWhitespace) // are ::, then the token must be recognized as an AxisName. // // Otherwise, the token must not be recognized as an OperatorName, a NodeType, a // FunctionName, or an AxisName. // // [33] OperatorName ::= 'and' | 'or' | 'mod' | 'div' // [38] NodeType ::= 'comment' | 'text' | 'processing-instruction' | 'node' // [35] FunctionName ::= QName - NodeType // [6] AxisName ::= (see above) // // [37] NameTest ::= '*' | NCName ':' '*' | QName // [5] NCName ::= (Letter | '_') (NCNameChar)* // [?] NCNameChar ::= Letter | Digit | '.' | '-' | '_' (ascii subset of 'NCNameChar') // [?] QName ::= (NCName ':')? NCName // [?] Letter ::= [A-Za-z] (ascii subset of 'Letter') // [?] Digit ::= [0-9] (ascii subset of 'Digit') // nameOffset = currentOffset; currentOffset = scanNCName(data, endOffset, currentOffset); if (currentOffset == nameOffset) { return false; // REVISIT } if (currentOffset < endOffset) { ch = data[currentOffset]; } else { ch = 0; } dataBuffer.set(data + nameOffset, currentOffset - nameOffset); nameHandle = fStringPool->addOrFind(dataBuffer.getRawBuffer()); bool isNameTestNCName = false; bool isAxisName = false; prefixHandle = -1; if (ch == chColon) { if (++currentOffset == endOffset) { return false; // REVISIT } ch = data[currentOffset]; if (ch == chAsterisk) { if (++currentOffset < endOffset) { ch = data[currentOffset]; } isNameTestNCName = true; } else if (ch == chColon) { if (++currentOffset < endOffset) { ch = data[currentOffset]; } isAxisName = true; } else { prefixHandle = nameHandle; nameOffset = currentOffset; currentOffset = scanNCName(data, endOffset, currentOffset); if (currentOffset == nameOffset) { return false; // REVISIT } if (currentOffset < endOffset) { ch = data[currentOffset]; } else { ch = 0; } dataBuffer.set(data + nameOffset, currentOffset - nameOffset); nameHandle = fStringPool->addOrFind(dataBuffer.getRawBuffer()); } } // // [39] ExprWhitespace ::= S // while (XMLChar1_0::isWhitespace(ch)) { if (++currentOffset == endOffset) { break; } ch = data[currentOffset]; } // // If there is a preceding token and the preceding token is not one of @, ::, (, [, , or // an Operator, then an NCName must be recognized as an OperatorName. // if (starIsMultiplyOperator) { if (nameHandle == fAndSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_OPERATOR_AND); starIsMultiplyOperator = false; } else if (nameHandle == fOrSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_OPERATOR_OR); starIsMultiplyOperator = false; } else if (nameHandle == fModSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_OPERATOR_MOD); starIsMultiplyOperator = false; } else if (nameHandle == fDivSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_OPERATOR_DIV); starIsMultiplyOperator = false; } else { return false; // REVISIT } if (isNameTestNCName) { return false; // REVISIT - NCName:* where an OperatorName is required } else if (isAxisName) { return false; // REVISIT - AxisName:: where an OperatorName is required } break; } // // If the character following an NCName (possibly after intervening ExprWhitespace) is (, // then the token must be recognized as a NodeType or a FunctionName. // if (ch == chOpenParen && !isNameTestNCName && !isAxisName) { if (nameHandle == fCommentSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_NODETYPE_COMMENT); } else if (nameHandle == fTextSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_NODETYPE_TEXT); } else if (nameHandle == fPISymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_NODETYPE_PI); } else if (nameHandle == fNodeSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_NODETYPE_NODE); } else { addToken(tokens, XercesXPath::EXPRTOKEN_FUNCTION_NAME); tokens->addElement(prefixHandle); tokens->addElement(nameHandle); } addToken(tokens, XercesXPath::EXPRTOKEN_OPEN_PAREN); starIsMultiplyOperator = false; ++currentOffset; break; } // // If the two characters following an NCName (possibly after intervening ExprWhitespace) // are ::, then the token must be recognized as an AxisName. // if (isAxisName || (ch == chColon && currentOffset + 1 < endOffset && data[currentOffset + 1] == chColon)) { if (nameHandle == fAncestorSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_ANCESTOR); } else if (nameHandle == fAncestorOrSelfSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_ANCESTOR_OR_SELF); } else if (nameHandle == fAttributeSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_ATTRIBUTE); } else if (nameHandle == fChildSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_CHILD); } else if (nameHandle == fDescendantSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_DESCENDANT); } else if (nameHandle == fDescendantOrSelfSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_DESCENDANT_OR_SELF); } else if (nameHandle == fFollowingSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_FOLLOWING); } else if (nameHandle == fFollowingSiblingSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_FOLLOWING_SIBLING); } else if (nameHandle == fNamespaceSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_NAMESPACE); } else if (nameHandle == fParentSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_PARENT); } else if (nameHandle == fPrecedingSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_PRECEDING); } else if (nameHandle == fPrecedingSiblingSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_PRECEDING_SIBLING); } else if (nameHandle == fSelfSymbol) { addToken(tokens, XercesXPath::EXPRTOKEN_AXISNAME_SELF); } else { return false; // REVISIT } if (isNameTestNCName) { return false; // REVISIT - "NCName:* ::" where "AxisName ::" is required } addToken(tokens, XercesXPath::EXPRTOKEN_DOUBLE_COLON); starIsMultiplyOperator = false; if (!isAxisName) { currentOffset += 2; } break; } // // Otherwise, the token must not be recognized as an OperatorName, a NodeType, a // FunctionName, or an AxisName. // if (isNameTestNCName) { addToken(tokens, XercesXPath::EXPRTOKEN_NAMETEST_NAMESPACE); tokens->addElement(nameHandle); } else { addToken(tokens, XercesXPath::EXPRTOKEN_NAMETEST_QNAME); tokens->addElement(prefixHandle); tokens->addElement(nameHandle); } starIsMultiplyOperator = true; break; } } return true;}int XPathScanner::scanNCName(const XMLCh* const data, const int endOffset, int currentOffset) { XMLCh ch = data[currentOffset]; if (!XMLChar1_0::isXMLLetter(ch) && ch != chUnderscore) { return currentOffset; } while (++currentOffset < endOffset) { ch = data[currentOffset]; if (ch == chColon || !XMLChar1_0::isNameChar(ch)) { break; } } return currentOffset;}int XPathScanner::scanNumber(const XMLCh* const data, const int endOffset, int currentOffset, ValueVectorOf<int>* const tokens) { XMLCh ch = data[currentOffset]; int whole = 0; int part = 0; while (ch >= chDigit_0 && ch <= chDigit_9) { whole = (whole * 10) + (ch - chDigit_0); if (++currentOffset == endOffset) { break; } ch = data[currentOffset]; } if (ch == chPeriod) { if (++currentOffset < endOffset) { ch = data[currentOffset]; while (ch >= chDigit_0 && ch <= chDigit_9) { part = (part * 10) + (ch - chDigit_0); if (++currentOffset == endOffset) { break; } ch = data[currentOffset]; } if (part != 0) { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::XPath_FindSolution, tokens->getMemoryManager()); } } } tokens->addElement(whole); tokens->addElement(part); return currentOffset;}// ---------------------------------------------------------------------------// XPathScannerForSchema: Constructors and Destructor// ---------------------------------------------------------------------------XPathScannerForSchema::XPathScannerForSchema(XMLStringPool* const stringPool) : XPathScanner(stringPool){}// ---------------------------------------------------------------------------// XPathScannerForSchema: Helper methods// ---------------------------------------------------------------------------void XPathScannerForSchema::addToken(ValueVectorOf<int>* const tokens, const int aToken) { if (aToken == XercesXPath::EXPRTOKEN_ATSIGN || aToken == XercesXPath::EXPRTOKEN_AXISNAME_ATTRIBUTE || aToken == XercesXPath::EXPRTOKEN_AXISNAME_CHILD || //token == XercesXPath::EXPRTOKEN_AXISNAME_SELF || aToken == XercesXPath::EXPRTOKEN_DOUBLE_COLON || aToken == XercesXPath::EXPRTOKEN_NAMETEST_QNAME || //token == XercesXPath::EXPRTOKEN_NODETYPE_NODE || aToken == XercesXPath::EXPRTOKEN_OPERATOR_SLASH || aToken == XercesXPath::EXPRTOKEN_PERIOD || aToken == XercesXPath::EXPRTOKEN_NAMETEST_ANY || aToken == XercesXPath::EXPRTOKEN_NAMETEST_NAMESPACE || aToken == XercesXPath::EXPRTOKEN_OPERATOR_DOUBLE_SLASH || aToken == XercesXPath::EXPRTOKEN_OPERATOR_UNION) { tokens->addElement(aToken); return; } ThrowXMLwithMemMgr(XPathException, XMLExcepts::XPath_TokenNotSupported, tokens->getMemoryManager());}XERCES_CPP_NAMESPACE_END/** * End of file XercesPath.cpp */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?