MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathIsPositionalPredicate

Function xmlXPathIsPositionalPredicate

ThirdParty/libxml2/vtklibxml2/xpath.c:10751–10805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10749}
10750
10751static int
10752xmlXPathIsPositionalPredicate(xmlXPathParserContextPtr ctxt,
10753 xmlXPathStepOpPtr op,
10754 int *maxPos)
10755{
10756
10757 xmlXPathStepOpPtr exprOp;
10758
10759 /*
10760 * BIG NOTE: This is not intended for XPATH_OP_FILTER yet!
10761 */
10762
10763 /*
10764 * If not -1, then ch1 will point to:
10765 * 1) For predicates (XPATH_OP_PREDICATE):
10766 * - an inner predicate operator
10767 * 2) For filters (XPATH_OP_FILTER):
10768 * - an inner filter operator OR
10769 * - an expression selecting the node set.
10770 * E.g. "key('a', 'b')" or "(//foo | //bar)".
10771 */
10772 if ((op->op != XPATH_OP_PREDICATE) && (op->op != XPATH_OP_FILTER))
10773 return(0);
10774
10775 if (op->ch2 != -1) {
10776 exprOp = &ctxt->comp->steps[op->ch2];
10777 } else
10778 return(0);
10779
10780 if ((exprOp != NULL) &&
10781 (exprOp->op == XPATH_OP_VALUE) &&
10782 (exprOp->value4 != NULL) &&
10783 (((xmlXPathObjectPtr) exprOp->value4)->type == XPATH_NUMBER))
10784 {
10785 double floatval = ((xmlXPathObjectPtr) exprOp->value4)->floatval;
10786
10787 /*
10788 * We have a "[n]" predicate here.
10789 * TODO: Unfortunately this simplistic test here is not
10790 * able to detect a position() predicate in compound
10791 * expressions like "[@attr = 'a" and position() = 1],
10792 * and even not the usage of position() in
10793 * "[position() = 1]"; thus - obviously - a position-range,
10794 * like it "[position() < 5]", is also not detected.
10795 * Maybe we could rewrite the AST to ease the optimization.
10796 */
10797
10798 if ((floatval > INT_MIN) && (floatval < INT_MAX)) {
10799 *maxPos = (int) floatval;
10800 if (floatval == (double) *maxPos)
10801 return(1);
10802 }
10803 }
10804 return(0);
10805}
10806
10807static int
10808xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected