• Home
  • Raw
  • Download

Lines Matching +full:robust +full:- +full:predicates

7  *     http://www.w3.org/TR/1999/REC-xpath-19991116
19 #pragma convert("ISO8859-1")
76 * non-element nodes; actually it will speed up comparison only if
166 ATTRIBUTE_NO_SANITIZE("float-divide-by-zero")
172 xmlXPathNINF = -INFINITY; in xmlInitXPathInternal()
178 xmlXPathNINF = -xmlXPathPINF; in xmlInitXPathInternal()
205 * Returns 1 if the value is +Infinite, -1 if -Infinite, 0 otherwise
210 return isinf(val) ? (val > 0 ? 1 : -1) : 0; in xmlXPathIsInf()
214 if (val <= -xmlXPathPINF) in xmlXPathIsInf()
215 return -1; in xmlXPathIsInf()
256 * This one is optimized for handling of non-element nodes.
258 * Returns -2 in case of error 1 if first point < second point, 0 if
259 * it's the same node, -1 otherwise
270 return(-2); in xmlXPathCmpNodesExt()
278 switch (node1->type) { in xmlXPathCmpNodesExt()
280 if (node2->type == XML_ELEMENT_NODE) { in xmlXPathCmpNodesExt()
281 if ((0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodesExt()
282 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodesExt()
283 (node1->doc == node2->doc)) in xmlXPathCmpNodesExt()
285 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodesExt()
286 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodesExt()
290 return(-1); in xmlXPathCmpNodesExt()
298 node1 = node1->parent; in xmlXPathCmpNodesExt()
309 if (node1->prev != NULL) { in xmlXPathCmpNodesExt()
311 node1 = node1->prev; in xmlXPathCmpNodesExt()
312 if (node1->type == XML_ELEMENT_NODE) { in xmlXPathCmpNodesExt()
313 precedence1 = 3; /* element in prev-sibl axis */ in xmlXPathCmpNodesExt()
316 if (node1->prev == NULL) { in xmlXPathCmpNodesExt()
322 node1 = node1->parent; in xmlXPathCmpNodesExt()
328 node1 = node1->parent; in xmlXPathCmpNodesExt()
330 if ((node1 == NULL) || (node1->type != XML_ELEMENT_NODE) || in xmlXPathCmpNodesExt()
331 (0 <= (ptrdiff_t) node1->content)) { in xmlXPathCmpNodesExt()
349 switch (node2->type) { in xmlXPathCmpNodesExt()
355 node2 = node2->parent; in xmlXPathCmpNodesExt()
363 if (node2->prev != NULL) { in xmlXPathCmpNodesExt()
365 node2 = node2->prev; in xmlXPathCmpNodesExt()
366 if (node2->type == XML_ELEMENT_NODE) { in xmlXPathCmpNodesExt()
367 precedence2 = 3; /* element in prev-sibl axis */ in xmlXPathCmpNodesExt()
370 if (node2->prev == NULL) { in xmlXPathCmpNodesExt()
372 node2 = node2->parent; in xmlXPathCmpNodesExt()
378 node2 = node2->parent; in xmlXPathCmpNodesExt()
380 if ((node2 == NULL) || (node2->type != XML_ELEMENT_NODE) || in xmlXPathCmpNodesExt()
381 (0 <= (ptrdiff_t) node2->content)) in xmlXPathCmpNodesExt()
399 * adjacent non-element nodes around. in xmlXPathCmpNodesExt()
401 cur = miscNode2->prev; in xmlXPathCmpNodesExt()
405 if (cur->type == XML_ELEMENT_NODE) in xmlXPathCmpNodesExt()
406 return(-1); in xmlXPathCmpNodesExt()
407 cur = cur->prev; in xmlXPathCmpNodesExt()
409 return (-1); in xmlXPathCmpNodesExt()
419 return(-1); in xmlXPathCmpNodesExt()
423 * Special case: One of the helper-elements is contained by the other. in xmlXPathCmpNodesExt()
426 * <node1>Text-1(precedence1 == 2)</node1> in xmlXPathCmpNodesExt()
428 * Text-6(precedence2 == 3) in xmlXPathCmpNodesExt()
432 cur = node1->parent; in xmlXPathCmpNodesExt()
436 cur = cur->parent; in xmlXPathCmpNodesExt()
440 cur = node2->parent; in xmlXPathCmpNodesExt()
443 return(-1); in xmlXPathCmpNodesExt()
444 cur = cur->parent; in xmlXPathCmpNodesExt()
452 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
453 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
454 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodesExt()
455 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodesExt()
456 (node1->doc == node2->doc)) { in xmlXPathCmpNodesExt()
458 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodesExt()
459 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodesExt()
463 return(-1); in xmlXPathCmpNodesExt()
468 if (node1 == node2->prev) in xmlXPathCmpNodesExt()
470 if (node1 == node2->next) in xmlXPathCmpNodesExt()
471 return(-1); in xmlXPathCmpNodesExt()
475 for (depth2 = 0, cur = node2; cur->parent != NULL; cur = cur->parent) { in xmlXPathCmpNodesExt()
476 if (cur->parent == node1) in xmlXPathCmpNodesExt()
481 for (depth1 = 0, cur = node1; cur->parent != NULL; cur = cur->parent) { in xmlXPathCmpNodesExt()
482 if (cur->parent == node2) in xmlXPathCmpNodesExt()
483 return(-1); in xmlXPathCmpNodesExt()
487 * Distinct document (or distinct entities :-( ) case. in xmlXPathCmpNodesExt()
490 return(-2); in xmlXPathCmpNodesExt()
496 depth1--; in xmlXPathCmpNodesExt()
497 node1 = node1->parent; in xmlXPathCmpNodesExt()
500 depth2--; in xmlXPathCmpNodesExt()
501 node2 = node2->parent; in xmlXPathCmpNodesExt()
503 while (node1->parent != node2->parent) { in xmlXPathCmpNodesExt()
504 node1 = node1->parent; in xmlXPathCmpNodesExt()
505 node2 = node2->parent; in xmlXPathCmpNodesExt()
508 return(-2); in xmlXPathCmpNodesExt()
513 if (node1 == node2->prev) in xmlXPathCmpNodesExt()
515 if (node1 == node2->next) in xmlXPathCmpNodesExt()
516 return(-1); in xmlXPathCmpNodesExt()
520 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
521 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
522 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodesExt()
523 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodesExt()
524 (node1->doc == node2->doc)) { in xmlXPathCmpNodesExt()
526 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodesExt()
527 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodesExt()
531 return(-1); in xmlXPathCmpNodesExt()
534 for (cur = node1->next;cur != NULL;cur = cur->next) in xmlXPathCmpNodesExt()
537 return(-1); /* assume there is no sibling list corruption */ in xmlXPathCmpNodesExt()
554 * Returns -2 in case of error -1 if first point < second point, 0 if
563 return res == -2 ? res : -res; in wrap_cmp()
569 return res == -2 ? res : -res; in wrap_cmp()
625 sizeof(xmlXPathErrorMessages[0])) - 1)
637 xmlResetError(&ctxt->lastError); in xmlXPathErrMemory()
644 ctxt->lastError.message = (char *) xmlStrdup(buf); in xmlXPathErrMemory()
646 ctxt->lastError.message = (char *) in xmlXPathErrMemory()
649 ctxt->lastError.domain = XML_FROM_XPATH; in xmlXPathErrMemory()
650 ctxt->lastError.code = XML_ERR_NO_MEMORY; in xmlXPathErrMemory()
651 if (ctxt->error != NULL) in xmlXPathErrMemory()
652 ctxt->error(ctxt->userData, &ctxt->lastError); in xmlXPathErrMemory()
682 ctxt->error = XPATH_MEMORY_ERROR; in xmlXPathPErrMemory()
683 xmlXPathErrMemory(ctxt->context, extra); in xmlXPathPErrMemory()
702 error + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, in xmlXPathErr()
709 if (ctxt->error != 0) in xmlXPathErr()
711 ctxt->error = error; in xmlXPathErr()
712 if (ctxt->context == NULL) { in xmlXPathErr()
715 error + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, in xmlXPathErr()
717 (const char *) ctxt->base, NULL, NULL, in xmlXPathErr()
718 ctxt->cur - ctxt->base, 0, in xmlXPathErr()
724 xmlResetError(&ctxt->context->lastError); in xmlXPathErr()
726 ctxt->context->lastError.domain = XML_FROM_XPATH; in xmlXPathErr()
727 ctxt->context->lastError.code = error + XML_XPATH_EXPRESSION_OK - in xmlXPathErr()
729 ctxt->context->lastError.level = XML_ERR_ERROR; in xmlXPathErr()
730 ctxt->context->lastError.str1 = (char *) xmlStrdup(ctxt->base); in xmlXPathErr()
731 ctxt->context->lastError.int1 = ctxt->cur - ctxt->base; in xmlXPathErr()
732 ctxt->context->lastError.node = ctxt->context->debugNode; in xmlXPathErr()
733 if (ctxt->context->error != NULL) { in xmlXPathErr()
734 ctxt->context->error(ctxt->context->userData, in xmlXPathErr()
735 &ctxt->context->lastError); in xmlXPathErr()
738 NULL, ctxt->context->debugNode, XML_FROM_XPATH, in xmlXPathErr()
739 error + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, in xmlXPathErr()
741 (const char *) ctxt->base, NULL, NULL, in xmlXPathErr()
742 ctxt->cur - ctxt->base, 0, in xmlXPathErr()
768 * Adds opCount to the running total of operations and returns -1 if the
773 xmlXPathContextPtr xpctxt = ctxt->context; in xmlXPathCheckOpLimit()
775 if ((opCount > xpctxt->opLimit) || in xmlXPathCheckOpLimit()
776 (xpctxt->opCount > xpctxt->opLimit - opCount)) { in xmlXPathCheckOpLimit()
777 xpctxt->opCount = xpctxt->opLimit; in xmlXPathCheckOpLimit()
779 return(-1); in xmlXPathCheckOpLimit()
782 xpctxt->opCount += opCount; in xmlXPathCheckOpLimit()
787 ((ctxt->context->opLimit != 0) && (xmlXPathCheckOpLimit(ctxt, n) < 0))
798 * Pointer-list for various purposes.
808 * TODO: Since such a list-handling is used in xmlschemas.c and libxslt
816 if (list->size <= list->number) { in xmlPointerListAddSize()
820 if (list->size == 0) { in xmlPointerListAddSize()
825 if (list->size > 50000000) { in xmlPointerListAddSize()
827 "xmlPointerListAddSize: re-allocating item\n"); in xmlPointerListAddSize()
828 return(-1); in xmlPointerListAddSize()
830 newSize = list->size * 2; in xmlPointerListAddSize()
832 tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *)); in xmlPointerListAddSize()
835 "xmlPointerListAddSize: re-allocating item\n"); in xmlPointerListAddSize()
836 return(-1); in xmlPointerListAddSize()
838 list->items = tmp; in xmlPointerListAddSize()
839 list->size = newSize; in xmlPointerListAddSize()
841 list->items[list->number++] = item; in xmlPointerListAddSize()
866 ret->number = 0; in xmlPointerListCreate()
882 if (list->items != NULL) in xmlPointerListFree()
883 xmlFree(list->items); in xmlPointerListFree()
1022 cur->maxStep = 10; in xmlXPathNewCompExpr()
1023 cur->nbStep = 0; in xmlXPathNewCompExpr()
1024 cur->steps = (xmlXPathStepOp *) xmlMalloc(cur->maxStep * in xmlXPathNewCompExpr()
1026 if (cur->steps == NULL) { in xmlXPathNewCompExpr()
1031 memset(cur->steps, 0, cur->maxStep * sizeof(xmlXPathStepOp)); in xmlXPathNewCompExpr()
1032 cur->last = -1; in xmlXPathNewCompExpr()
1050 if (comp->dict == NULL) { in xmlXPathFreeCompExpr()
1051 for (i = 0; i < comp->nbStep; i++) { in xmlXPathFreeCompExpr()
1052 op = &comp->steps[i]; in xmlXPathFreeCompExpr()
1053 if (op->value4 != NULL) { in xmlXPathFreeCompExpr()
1054 if (op->op == XPATH_OP_VALUE) in xmlXPathFreeCompExpr()
1055 xmlXPathFreeObject(op->value4); in xmlXPathFreeCompExpr()
1057 xmlFree(op->value4); in xmlXPathFreeCompExpr()
1059 if (op->value5 != NULL) in xmlXPathFreeCompExpr()
1060 xmlFree(op->value5); in xmlXPathFreeCompExpr()
1063 for (i = 0; i < comp->nbStep; i++) { in xmlXPathFreeCompExpr()
1064 op = &comp->steps[i]; in xmlXPathFreeCompExpr()
1065 if (op->value4 != NULL) { in xmlXPathFreeCompExpr()
1066 if (op->op == XPATH_OP_VALUE) in xmlXPathFreeCompExpr()
1067 xmlXPathFreeObject(op->value4); in xmlXPathFreeCompExpr()
1070 xmlDictFree(comp->dict); in xmlXPathFreeCompExpr()
1072 if (comp->steps != NULL) { in xmlXPathFreeCompExpr()
1073 xmlFree(comp->steps); in xmlXPathFreeCompExpr()
1076 if (comp->stream != NULL) { in xmlXPathFreeCompExpr()
1077 xmlFreePatternList(comp->stream); in xmlXPathFreeCompExpr()
1080 if (comp->expr != NULL) { in xmlXPathFreeCompExpr()
1081 xmlFree(comp->expr); in xmlXPathFreeCompExpr()
1101 * Returns -1 in case of failure, the index otherwise
1107 xmlXPathCompExprPtr comp = ctxt->comp; in xmlXPathCompExprAdd()
1108 if (comp->nbStep >= comp->maxStep) { in xmlXPathCompExprAdd()
1111 if (comp->maxStep >= XPATH_MAX_STEPS) { in xmlXPathCompExprAdd()
1113 return(-1); in xmlXPathCompExprAdd()
1115 comp->maxStep *= 2; in xmlXPathCompExprAdd()
1116 real = (xmlXPathStepOp *) xmlRealloc(comp->steps, in xmlXPathCompExprAdd()
1117 comp->maxStep * sizeof(xmlXPathStepOp)); in xmlXPathCompExprAdd()
1119 comp->maxStep /= 2; in xmlXPathCompExprAdd()
1121 return(-1); in xmlXPathCompExprAdd()
1123 comp->steps = real; in xmlXPathCompExprAdd()
1125 comp->last = comp->nbStep; in xmlXPathCompExprAdd()
1126 comp->steps[comp->nbStep].ch1 = ch1; in xmlXPathCompExprAdd()
1127 comp->steps[comp->nbStep].ch2 = ch2; in xmlXPathCompExprAdd()
1128 comp->steps[comp->nbStep].op = op; in xmlXPathCompExprAdd()
1129 comp->steps[comp->nbStep].value = value; in xmlXPathCompExprAdd()
1130 comp->steps[comp->nbStep].value2 = value2; in xmlXPathCompExprAdd()
1131 comp->steps[comp->nbStep].value3 = value3; in xmlXPathCompExprAdd()
1132 if ((comp->dict != NULL) && in xmlXPathCompExprAdd()
1136 comp->steps[comp->nbStep].value4 = (xmlChar *) in xmlXPathCompExprAdd()
1137 (void *)xmlDictLookup(comp->dict, value4, -1); in xmlXPathCompExprAdd()
1140 comp->steps[comp->nbStep].value4 = NULL; in xmlXPathCompExprAdd()
1142 comp->steps[comp->nbStep].value5 = (xmlChar *) in xmlXPathCompExprAdd()
1143 (void *)xmlDictLookup(comp->dict, value5, -1); in xmlXPathCompExprAdd()
1146 comp->steps[comp->nbStep].value5 = NULL; in xmlXPathCompExprAdd()
1148 comp->steps[comp->nbStep].value4 = value4; in xmlXPathCompExprAdd()
1149 comp->steps[comp->nbStep].value5 = value5; in xmlXPathCompExprAdd()
1151 comp->steps[comp->nbStep].cache = NULL; in xmlXPathCompExprAdd()
1152 return(comp->nbStep++); in xmlXPathCompExprAdd()
1176 tmp = op->ch1; in xmlXPathCompSwap()
1177 op->ch1 = op->ch2; in xmlXPathCompSwap()
1178 op->ch2 = tmp; in xmlXPathCompSwap()
1185 xmlXPathCompExprAdd(ctxt, ctxt->comp->last, -1, \
1189 xmlXPathCompExprAdd(ctxt, -1, -1, (op), (val), (val2), 0 ,NULL ,NULL)
1192 xmlXPathCompExprAdd(ctxt, (ch), -1, (op), (val), (val2), 0 ,NULL ,NULL)
1206 #define XP_HAS_CACHE(c) ((c != NULL) && ((c)->cache != NULL))
1250 if ((cur->type == XML_DOCUMENT_NODE) || in xmlXPathDebugDumpNode()
1251 (cur->type == XML_HTML_DOCUMENT_NODE)) { in xmlXPathDebugDumpNode()
1254 } else if (cur->type == XML_ATTRIBUTE_NODE) in xmlXPathDebugDumpNode()
1277 cur = cur->next; in xmlXPathDebugDumpNodeList()
1299 fprintf(output, "Set contains %d nodes:\n", cur->nodeNr); in xmlXPathDebugDumpNodeSet()
1300 for (i = 0;i < cur->nodeNr;i++) { in xmlXPathDebugDumpNodeSet()
1303 xmlXPathDebugDumpNode(output, cur->nodeTab[i], depth + 1); in xmlXPathDebugDumpNodeSet()
1317 if ((cur == NULL) || (cur->nodeNr == 0) || (cur->nodeTab[0] == NULL)) { in xmlXPathDebugDumpValueTree()
1326 xmlXPathDebugDumpNodeList(output, cur->nodeTab[0]->children, depth + 1); in xmlXPathDebugDumpValueTree()
1345 for (i = 0;i < cur->locNr;i++) { in xmlXPathDebugDumpLocationSet()
1348 xmlXPathDebugDumpObject(output, cur->locTab[i], depth + 1); in xmlXPathDebugDumpLocationSet()
1379 switch(cur->type) { in xmlXPathDebugDumpObject()
1385 xmlXPathDebugDumpNodeSet(output, cur->nodesetval, depth); in xmlXPathDebugDumpObject()
1389 xmlXPathDebugDumpValueTree(output, cur->nodesetval, depth); in xmlXPathDebugDumpObject()
1393 if (cur->boolval) fprintf(output, "true\n"); in xmlXPathDebugDumpObject()
1397 switch (xmlXPathIsInf(cur->floatval)) { in xmlXPathDebugDumpObject()
1401 case -1: in xmlXPathDebugDumpObject()
1402 fprintf(output, "Object is a number : -Infinity\n"); in xmlXPathDebugDumpObject()
1405 if (xmlXPathIsNaN(cur->floatval)) { in xmlXPathDebugDumpObject()
1407 } else if (cur->floatval == 0) { in xmlXPathDebugDumpObject()
1411 fprintf(output, "Object is a number : %0g\n", cur->floatval); in xmlXPathDebugDumpObject()
1417 xmlDebugDumpString(output, cur->stringval); in xmlXPathDebugDumpObject()
1422 fprintf(output, "Object is a point : index %d in node", cur->index); in xmlXPathDebugDumpObject()
1423 xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, depth + 1); in xmlXPathDebugDumpObject()
1427 if ((cur->user2 == NULL) || in xmlXPathDebugDumpObject()
1428 ((cur->user2 == cur->user) && (cur->index == cur->index2))) { in xmlXPathDebugDumpObject()
1431 if (cur->index >= 0) in xmlXPathDebugDumpObject()
1432 fprintf(output, "index %d in ", cur->index); in xmlXPathDebugDumpObject()
1434 xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, in xmlXPathDebugDumpObject()
1440 if (cur->index >= 0) in xmlXPathDebugDumpObject()
1441 fprintf(output, "index %d in ", cur->index); in xmlXPathDebugDumpObject()
1443 xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, in xmlXPathDebugDumpObject()
1447 if (cur->index2 >= 0) in xmlXPathDebugDumpObject()
1448 fprintf(output, "index %d in ", cur->index2); in xmlXPathDebugDumpObject()
1450 xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user2, in xmlXPathDebugDumpObject()
1458 (xmlLocationSetPtr) cur->user, depth); in xmlXPathDebugDumpObject()
1482 switch (op->op) { in xmlXPathDebugDumpStepOp()
1490 if (op->value) in xmlXPathDebugDumpStepOp()
1496 if (op->value) in xmlXPathDebugDumpStepOp()
1500 if (!op->value2) in xmlXPathDebugDumpStepOp()
1504 if (op->value == 0) in xmlXPathDebugDumpStepOp()
1505 fprintf(output, "PLUS -"); in xmlXPathDebugDumpStepOp()
1506 else if (op->value == 1) in xmlXPathDebugDumpStepOp()
1508 else if (op->value == 2) in xmlXPathDebugDumpStepOp()
1509 fprintf(output, "PLUS unary -"); in xmlXPathDebugDumpStepOp()
1510 else if (op->value == 3) in xmlXPathDebugDumpStepOp()
1511 fprintf(output, "PLUS unary - -"); in xmlXPathDebugDumpStepOp()
1514 if (op->value == 0) in xmlXPathDebugDumpStepOp()
1516 else if (op->value == 1) in xmlXPathDebugDumpStepOp()
1530 xmlXPathAxisVal axis = (xmlXPathAxisVal)op->value; in xmlXPathDebugDumpStepOp()
1531 xmlXPathTestVal test = (xmlXPathTestVal)op->value2; in xmlXPathDebugDumpStepOp()
1532 xmlXPathTypeVal type = (xmlXPathTypeVal)op->value3; in xmlXPathDebugDumpStepOp()
1533 const xmlChar *prefix = op->value4; in xmlXPathDebugDumpStepOp()
1534 const xmlChar *name = op->value5; in xmlXPathDebugDumpStepOp()
1541 fprintf(output, " 'ancestors-or-self' "); break; in xmlXPathDebugDumpStepOp()
1549 fprintf(output, " 'descendant-or-self' "); break; in xmlXPathDebugDumpStepOp()
1553 fprintf(output, " 'following-siblings' "); break; in xmlXPathDebugDumpStepOp()
1561 fprintf(output, " 'preceding-sibling' "); break; in xmlXPathDebugDumpStepOp()
1597 xmlXPathObjectPtr object = (xmlXPathObjectPtr) op->value4; in xmlXPathDebugDumpStepOp()
1604 const xmlChar *prefix = op->value5; in xmlXPathDebugDumpStepOp()
1605 const xmlChar *name = op->value4; in xmlXPathDebugDumpStepOp()
1614 int nbargs = op->value; in xmlXPathDebugDumpStepOp()
1615 const xmlChar *prefix = op->value5; in xmlXPathDebugDumpStepOp()
1616 const xmlChar *name = op->value4; in xmlXPathDebugDumpStepOp()
1632 fprintf(output, "UNKNOWN %d\n", op->op); return; in xmlXPathDebugDumpStepOp()
1636 if (op->ch1 >= 0) in xmlXPathDebugDumpStepOp()
1637 xmlXPathDebugDumpStepOp(output, comp, &comp->steps[op->ch1], depth + 1); in xmlXPathDebugDumpStepOp()
1638 if (op->ch2 >= 0) in xmlXPathDebugDumpStepOp()
1639 xmlXPathDebugDumpStepOp(output, comp, &comp->steps[op->ch2], depth + 1); in xmlXPathDebugDumpStepOp()
1665 if (comp->stream) { in xmlXPathDebugDumpCompExpr()
1671 comp->nbStep); in xmlXPathDebugDumpCompExpr()
1672 i = comp->last; in xmlXPathDebugDumpCompExpr()
1673 xmlXPathDebugDumpStepOp(output, comp, &comp->steps[i], depth + 1); in xmlXPathDebugDumpCompExpr()
1703 ret->maxNodeset = 100; in xmlXPathNewCache()
1704 ret->maxString = 100; in xmlXPathNewCache()
1705 ret->maxBoolean = 100; in xmlXPathNewCache()
1706 ret->maxNumber = 100; in xmlXPathNewCache()
1707 ret->maxMisc = 100; in xmlXPathNewCache()
1720 for (i = 0; i < list->number; i++) { in xmlXPathCacheFreeObjectList()
1721 obj = list->items[i]; in xmlXPathCacheFreeObjectList()
1724 * look out for namespace nodes in the node-set. in xmlXPathCacheFreeObjectList()
1726 if (obj->nodesetval != NULL) { in xmlXPathCacheFreeObjectList()
1727 if (obj->nodesetval->nodeTab != NULL) in xmlXPathCacheFreeObjectList()
1728 xmlFree(obj->nodesetval->nodeTab); in xmlXPathCacheFreeObjectList()
1729 xmlFree(obj->nodesetval); in xmlXPathCacheFreeObjectList()
1741 if (cache->nodesetObjs) in xmlXPathFreeCache()
1742 xmlXPathCacheFreeObjectList(cache->nodesetObjs); in xmlXPathFreeCache()
1743 if (cache->stringObjs) in xmlXPathFreeCache()
1744 xmlXPathCacheFreeObjectList(cache->stringObjs); in xmlXPathFreeCache()
1745 if (cache->booleanObjs) in xmlXPathFreeCache()
1746 xmlXPathCacheFreeObjectList(cache->booleanObjs); in xmlXPathFreeCache()
1747 if (cache->numberObjs) in xmlXPathFreeCache()
1748 xmlXPathCacheFreeObjectList(cache->numberObjs); in xmlXPathFreeCache()
1749 if (cache->miscObjs) in xmlXPathFreeCache()
1750 xmlXPathCacheFreeObjectList(cache->miscObjs); in xmlXPathFreeCache()
1770 * There are 5 slots for: node-set, string, number, boolean, and
1774 * Returns 0 if the setting succeeded, and -1 on API or internal errors.
1783 return(-1); in xmlXPathContextSetCache()
1787 if (ctxt->cache == NULL) { in xmlXPathContextSetCache()
1788 ctxt->cache = xmlXPathNewCache(); in xmlXPathContextSetCache()
1789 if (ctxt->cache == NULL) in xmlXPathContextSetCache()
1790 return(-1); in xmlXPathContextSetCache()
1792 cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathContextSetCache()
1796 cache->maxNodeset = value; in xmlXPathContextSetCache()
1797 cache->maxString = value; in xmlXPathContextSetCache()
1798 cache->maxNumber = value; in xmlXPathContextSetCache()
1799 cache->maxBoolean = value; in xmlXPathContextSetCache()
1800 cache->maxMisc = value; in xmlXPathContextSetCache()
1802 } else if (ctxt->cache != NULL) { in xmlXPathContextSetCache()
1803 xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache); in xmlXPathContextSetCache()
1804 ctxt->cache = NULL; in xmlXPathContextSetCache()
1824 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheWrapNodeSet()
1826 (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheWrapNodeSet()
1828 if ((cache->miscObjs != NULL) && in xmlXPathCacheWrapNodeSet()
1829 (cache->miscObjs->number != 0)) in xmlXPathCacheWrapNodeSet()
1834 cache->miscObjs->items[--cache->miscObjs->number]; in xmlXPathCacheWrapNodeSet()
1835 ret->type = XPATH_NODESET; in xmlXPathCacheWrapNodeSet()
1836 ret->nodesetval = val; in xmlXPathCacheWrapNodeSet()
1858 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheWrapString()
1859 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheWrapString()
1861 if ((cache->stringObjs != NULL) && in xmlXPathCacheWrapString()
1862 (cache->stringObjs->number != 0)) in xmlXPathCacheWrapString()
1868 cache->stringObjs->items[--cache->stringObjs->number]; in xmlXPathCacheWrapString()
1869 ret->type = XPATH_STRING; in xmlXPathCacheWrapString()
1870 ret->stringval = val; in xmlXPathCacheWrapString()
1872 } else if ((cache->miscObjs != NULL) && in xmlXPathCacheWrapString()
1873 (cache->miscObjs->number != 0)) in xmlXPathCacheWrapString()
1877 * Fallback to misc-cache. in xmlXPathCacheWrapString()
1880 cache->miscObjs->items[--cache->miscObjs->number]; in xmlXPathCacheWrapString()
1882 ret->type = XPATH_STRING; in xmlXPathCacheWrapString()
1883 ret->stringval = val; in xmlXPathCacheWrapString()
1904 if ((ctxt != NULL) && (ctxt->cache)) { in xmlXPathCacheNewNodeSet()
1905 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewNodeSet()
1907 if ((cache->nodesetObjs != NULL) && in xmlXPathCacheNewNodeSet()
1908 (cache->nodesetObjs->number != 0)) in xmlXPathCacheNewNodeSet()
1912 * Use the nodeset-cache. in xmlXPathCacheNewNodeSet()
1915 cache->nodesetObjs->items[--cache->nodesetObjs->number]; in xmlXPathCacheNewNodeSet()
1916 ret->type = XPATH_NODESET; in xmlXPathCacheNewNodeSet()
1917 ret->boolval = 0; in xmlXPathCacheNewNodeSet()
1919 if ((ret->nodesetval->nodeMax == 0) || in xmlXPathCacheNewNodeSet()
1920 (val->type == XML_NAMESPACE_DECL)) in xmlXPathCacheNewNodeSet()
1923 xmlXPathNodeSetAddUnique(ret->nodesetval, val); in xmlXPathCacheNewNodeSet()
1925 ret->nodesetval->nodeTab[0] = val; in xmlXPathCacheNewNodeSet()
1926 ret->nodesetval->nodeNr = 1; in xmlXPathCacheNewNodeSet()
1930 } else if ((cache->miscObjs != NULL) && in xmlXPathCacheNewNodeSet()
1931 (cache->miscObjs->number != 0)) in xmlXPathCacheNewNodeSet()
1936 * Fallback to misc-cache. in xmlXPathCacheNewNodeSet()
1941 ctxt->lastError.domain = XML_FROM_XPATH; in xmlXPathCacheNewNodeSet()
1942 ctxt->lastError.code = XML_ERR_NO_MEMORY; in xmlXPathCacheNewNodeSet()
1947 cache->miscObjs->items[--cache->miscObjs->number]; in xmlXPathCacheNewNodeSet()
1949 ret->type = XPATH_NODESET; in xmlXPathCacheNewNodeSet()
1950 ret->boolval = 0; in xmlXPathCacheNewNodeSet()
1951 ret->nodesetval = set; in xmlXPathCacheNewNodeSet()
1971 if ((ctxt != NULL) && (ctxt->cache)) { in xmlXPathCacheNewString()
1972 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewString()
1974 if ((cache->stringObjs != NULL) && in xmlXPathCacheNewString()
1975 (cache->stringObjs->number != 0)) in xmlXPathCacheNewString()
1989 cache->stringObjs->items[--cache->stringObjs->number]; in xmlXPathCacheNewString()
1990 ret->type = XPATH_STRING; in xmlXPathCacheNewString()
1991 ret->stringval = copy; in xmlXPathCacheNewString()
1993 } else if ((cache->miscObjs != NULL) && in xmlXPathCacheNewString()
1994 (cache->miscObjs->number != 0)) in xmlXPathCacheNewString()
2008 cache->miscObjs->items[--cache->miscObjs->number]; in xmlXPathCacheNewString()
2010 ret->type = XPATH_STRING; in xmlXPathCacheNewString()
2011 ret->stringval = copy; in xmlXPathCacheNewString()
2047 if ((ctxt != NULL) && (ctxt->cache)) { in xmlXPathCacheNewBoolean()
2048 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewBoolean()
2050 if ((cache->booleanObjs != NULL) && in xmlXPathCacheNewBoolean()
2051 (cache->booleanObjs->number != 0)) in xmlXPathCacheNewBoolean()
2056 cache->booleanObjs->items[--cache->booleanObjs->number]; in xmlXPathCacheNewBoolean()
2057 ret->type = XPATH_BOOLEAN; in xmlXPathCacheNewBoolean()
2058 ret->boolval = (val != 0); in xmlXPathCacheNewBoolean()
2060 } else if ((cache->miscObjs != NULL) && in xmlXPathCacheNewBoolean()
2061 (cache->miscObjs->number != 0)) in xmlXPathCacheNewBoolean()
2066 cache->miscObjs->items[--cache->miscObjs->number]; in xmlXPathCacheNewBoolean()
2068 ret->type = XPATH_BOOLEAN; in xmlXPathCacheNewBoolean()
2069 ret->boolval = (val != 0); in xmlXPathCacheNewBoolean()
2089 if ((ctxt != NULL) && (ctxt->cache)) { in xmlXPathCacheNewFloat()
2090 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewFloat()
2092 if ((cache->numberObjs != NULL) && in xmlXPathCacheNewFloat()
2093 (cache->numberObjs->number != 0)) in xmlXPathCacheNewFloat()
2098 cache->numberObjs->items[--cache->numberObjs->number]; in xmlXPathCacheNewFloat()
2099 ret->type = XPATH_NUMBER; in xmlXPathCacheNewFloat()
2100 ret->floatval = val; in xmlXPathCacheNewFloat()
2102 } else if ((cache->miscObjs != NULL) && in xmlXPathCacheNewFloat()
2103 (cache->miscObjs->number != 0)) in xmlXPathCacheNewFloat()
2108 cache->miscObjs->items[--cache->miscObjs->number]; in xmlXPathCacheNewFloat()
2110 ret->type = XPATH_NUMBER; in xmlXPathCacheNewFloat()
2111 ret->floatval = val; in xmlXPathCacheNewFloat()
2137 switch (val->type) { in xmlXPathCacheConvertString()
2142 res = xmlXPathCastNodeSetToString(val->nodesetval); in xmlXPathCacheConvertString()
2147 res = xmlXPathCastBooleanToString(val->boolval); in xmlXPathCacheConvertString()
2150 res = xmlXPathCastNumberToString(val->floatval); in xmlXPathCacheConvertString()
2184 switch (val->type) { in xmlXPathCacheObjectCopy()
2187 xmlXPathNodeSetMerge(NULL, val->nodesetval))); in xmlXPathCacheObjectCopy()
2189 return(xmlXPathCacheNewString(ctxt, val->stringval)); in xmlXPathCacheObjectCopy()
2191 return(xmlXPathCacheNewBoolean(ctxt, val->boolval)); in xmlXPathCacheObjectCopy()
2193 return(xmlXPathCacheNewFloat(ctxt, val->floatval)); in xmlXPathCacheObjectCopy()
2218 if (val->type == XPATH_BOOLEAN) in xmlXPathCacheConvertBoolean()
2242 if (val->type == XPATH_NUMBER) in xmlXPathCacheConvertNumber()
2268 if ((ctxt == NULL) || (ctxt->valueNr <= 0)) in valuePop()
2271 ctxt->valueNr--; in valuePop()
2272 if (ctxt->valueNr > 0) in valuePop()
2273 ctxt->value = ctxt->valueTab[ctxt->valueNr - 1]; in valuePop()
2275 ctxt->value = NULL; in valuePop()
2276 ret = ctxt->valueTab[ctxt->valueNr]; in valuePop()
2277 ctxt->valueTab[ctxt->valueNr] = NULL; in valuePop()
2288 * Returns the number of items on the value stack, or -1 in case of error.
2295 if (ctxt == NULL) return(-1); in valuePush()
2299 * so we set ctxt->error here to propagate the error. in valuePush()
2301 ctxt->error = XPATH_MEMORY_ERROR; in valuePush()
2302 return(-1); in valuePush()
2304 if (ctxt->valueNr >= ctxt->valueMax) { in valuePush()
2307 if (ctxt->valueMax >= XPATH_MAX_STACK_DEPTH) { in valuePush()
2310 return (-1); in valuePush()
2312 tmp = (xmlXPathObjectPtr *) xmlRealloc(ctxt->valueTab, in valuePush()
2313 2 * ctxt->valueMax * in valuePush()
2314 sizeof(ctxt->valueTab[0])); in valuePush()
2318 return (-1); in valuePush()
2320 ctxt->valueMax *= 2; in valuePush()
2321 ctxt->valueTab = tmp; in valuePush()
2323 ctxt->valueTab[ctxt->valueNr] = value; in valuePush()
2324 ctxt->value = value; in valuePush()
2325 return (ctxt->valueNr++); in valuePush()
2347 if (obj->type != XPATH_BOOLEAN) in xmlXPathPopBoolean()
2350 ret = obj->boolval; in xmlXPathPopBoolean()
2351 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopBoolean()
2374 if (obj->type != XPATH_NUMBER) in xmlXPathPopNumber()
2377 ret = obj->floatval; in xmlXPathPopNumber()
2378 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopNumber()
2403 if (obj->stringval == ret) in xmlXPathPopString()
2404 obj->stringval = NULL; in xmlXPathPopString()
2405 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopString()
2413 * Pops a node-set from the stack, handling conversion if needed.
2416 * Returns the node-set
2424 if (ctxt->value == NULL) { in xmlXPathPopNodeSet()
2433 ret = obj->nodesetval; in xmlXPathPopNodeSet()
2435 /* to fix memory leak of not clearing obj->user */ in xmlXPathPopNodeSet()
2436 if (obj->boolval && obj->user != NULL) in xmlXPathPopNodeSet()
2437 xmlFreeNodeList((xmlNodePtr) obj->user); in xmlXPathPopNodeSet()
2439 obj->nodesetval = NULL; in xmlXPathPopNodeSet()
2440 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopNodeSet()
2458 if ((ctxt == NULL) || (ctxt->value == NULL)) { in xmlXPathPopExternal()
2462 if (ctxt->value->type != XPATH_USERS) { in xmlXPathPopExternal()
2467 ret = obj->user; in xmlXPathPopExternal()
2468 obj->user = NULL; in xmlXPathPopExternal()
2469 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopExternal()
2481 * in ISO-Latin or UTF-8.
2484 * running with UTF-8 encoding.
2490 * UTF-8 if we are using this mode. It returns an int.
2492 * in UTF-8 mode. It also pop-up unfinished entities on the fly.
2496 #define CUR (*ctxt->cur)
2497 #define SKIP(val) ctxt->cur += (val)
2498 #define NXT(val) ctxt->cur[(val)]
2499 #define CUR_PTR ctxt->cur
2506 #define NEXTL(l) ctxt->cur += l
2509 while (IS_BLANK_CH(*(ctxt->cur))) NEXT
2511 #define CURRENT (*ctxt->cur)
2512 #define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
2519 #define DBL_EPSILON 1E-9
2523 #define LOWER_DOUBLE 1E-5
2546 case -1: in xmlXPathFormatNumber()
2547 if (buffersize > (int)sizeof("-Infinity")) in xmlXPathFormatNumber()
2548 snprintf(buffer, buffersize, "-Infinity"); in xmlXPathFormatNumber()
2569 while ((*cur) && (ptr - buffer < buffersize)) { in xmlXPathFormatNumber()
2573 if (ptr - buffer < buffersize) { in xmlXPathFormatNumber()
2576 ptr--; in xmlXPathFormatNumber()
2599 * First choose format - scientific or regular floating point. in xmlXPathFormatNumber()
2608 fraction_place = DBL_DIG - 1; in xmlXPathFormatNumber()
2611 while ((size > 0) && (work[size] != 'e')) size--; in xmlXPathFormatNumber()
2619 fraction_place = DBL_DIG - integer_place - 1; in xmlXPathFormatNumber()
2621 fraction_place = DBL_DIG - integer_place; in xmlXPathFormatNumber()
2632 size--; in xmlXPathFormatNumber()
2638 while (*(--ptr) == '0') in xmlXPathFormatNumber()
2647 work[buffersize - 1] = 0; in xmlXPathFormatNumber()
2669 * Like for line information, the order is kept in the element->content
2670 * field, the value stored is actually - the node number (starting at -1)
2673 * Returns the number of elements found in the document or -1 in case
2682 return(-1); in xmlXPathOrderDocElems()
2683 cur = doc->children; in xmlXPathOrderDocElems()
2685 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathOrderDocElems()
2686 cur->content = (void *) (-(++count)); in xmlXPathOrderDocElems()
2687 if (cur->children != NULL) { in xmlXPathOrderDocElems()
2688 cur = cur->children; in xmlXPathOrderDocElems()
2692 if (cur->next != NULL) { in xmlXPathOrderDocElems()
2693 cur = cur->next; in xmlXPathOrderDocElems()
2697 cur = cur->parent; in xmlXPathOrderDocElems()
2704 if (cur->next != NULL) { in xmlXPathOrderDocElems()
2705 cur = cur->next; in xmlXPathOrderDocElems()
2720 * Returns -2 in case of error 1 if first point < second point, 0 if
2721 * it's the same node, -1 otherwise
2731 return(-2); in xmlXPathCmpNodes()
2737 if (node1->type == XML_ATTRIBUTE_NODE) { in xmlXPathCmpNodes()
2740 node1 = node1->parent; in xmlXPathCmpNodes()
2742 if (node2->type == XML_ATTRIBUTE_NODE) { in xmlXPathCmpNodes()
2745 node2 = node2->parent; in xmlXPathCmpNodes()
2751 cur = attrNode2->prev; in xmlXPathCmpNodes()
2755 cur = cur->prev; in xmlXPathCmpNodes()
2757 return (-1); in xmlXPathCmpNodes()
2763 return(-1); in xmlXPathCmpNodes()
2765 if ((node1->type == XML_NAMESPACE_DECL) || in xmlXPathCmpNodes()
2766 (node2->type == XML_NAMESPACE_DECL)) in xmlXPathCmpNodes()
2768 if (node1 == node2->prev) in xmlXPathCmpNodes()
2770 if (node1 == node2->next) in xmlXPathCmpNodes()
2771 return(-1); in xmlXPathCmpNodes()
2776 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2777 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2778 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodes()
2779 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodes()
2780 (node1->doc == node2->doc)) { in xmlXPathCmpNodes()
2783 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodes()
2784 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodes()
2788 return(-1); in xmlXPathCmpNodes()
2794 for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) { in xmlXPathCmpNodes()
2795 if (cur->parent == node1) in xmlXPathCmpNodes()
2800 for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) { in xmlXPathCmpNodes()
2801 if (cur->parent == node2) in xmlXPathCmpNodes()
2802 return(-1); in xmlXPathCmpNodes()
2806 * Distinct document (or distinct entities :-( ) case. in xmlXPathCmpNodes()
2809 return(-2); in xmlXPathCmpNodes()
2815 depth1--; in xmlXPathCmpNodes()
2816 node1 = node1->parent; in xmlXPathCmpNodes()
2819 depth2--; in xmlXPathCmpNodes()
2820 node2 = node2->parent; in xmlXPathCmpNodes()
2822 while (node1->parent != node2->parent) { in xmlXPathCmpNodes()
2823 node1 = node1->parent; in xmlXPathCmpNodes()
2824 node2 = node2->parent; in xmlXPathCmpNodes()
2827 return(-2); in xmlXPathCmpNodes()
2832 if (node1 == node2->prev) in xmlXPathCmpNodes()
2834 if (node1 == node2->next) in xmlXPathCmpNodes()
2835 return(-1); in xmlXPathCmpNodes()
2839 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2840 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2841 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodes()
2842 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodes()
2843 (node1->doc == node2->doc)) { in xmlXPathCmpNodes()
2846 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodes()
2847 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodes()
2851 return(-1); in xmlXPathCmpNodes()
2854 for (cur = node1->next;cur != NULL;cur = cur->next) in xmlXPathCmpNodes()
2857 return(-1); /* assume there is no sibling list corruption */ in xmlXPathCmpNodes()
2878 * Use the old Shell's sort implementation to sort the node-set in xmlXPathNodeSetSort()
2881 len = set->nodeNr; in xmlXPathNodeSetSort()
2884 j = i - incr; in xmlXPathNodeSetSort()
2887 if (xmlXPathCmpNodesExt(set->nodeTab[j], in xmlXPathNodeSetSort()
2888 set->nodeTab[j + incr]) == -1) in xmlXPathNodeSetSort()
2890 if (xmlXPathCmpNodes(set->nodeTab[j], in xmlXPathNodeSetSort()
2891 set->nodeTab[j + incr]) == -1) in xmlXPathNodeSetSort()
2894 tmp = set->nodeTab[j]; in xmlXPathNodeSetSort()
2895 set->nodeTab[j] = set->nodeTab[j + incr]; in xmlXPathNodeSetSort()
2896 set->nodeTab[j + incr] = tmp; in xmlXPathNodeSetSort()
2897 j -= incr; in xmlXPathNodeSetSort()
2904 libxml_domnode_tim_sort(set->nodeTab, set->nodeNr); in xmlXPathNodeSetSort()
2924 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) in xmlXPathNodeSetDupNs()
2926 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetDupNs()
2938 cur->type = XML_NAMESPACE_DECL; in xmlXPathNodeSetDupNs()
2939 if (ns->href != NULL) in xmlXPathNodeSetDupNs()
2940 cur->href = xmlStrdup(ns->href); in xmlXPathNodeSetDupNs()
2941 if (ns->prefix != NULL) in xmlXPathNodeSetDupNs()
2942 cur->prefix = xmlStrdup(ns->prefix); in xmlXPathNodeSetDupNs()
2943 cur->next = (xmlNsPtr) node; in xmlXPathNodeSetDupNs()
2957 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) in xmlXPathNodeSetFreeNs()
2960 if ((ns->next != NULL) && (ns->next->type != XML_NAMESPACE_DECL)) { in xmlXPathNodeSetFreeNs()
2961 if (ns->href != NULL) in xmlXPathNodeSetFreeNs()
2962 xmlFree((xmlChar *)ns->href); in xmlXPathNodeSetFreeNs()
2963 if (ns->prefix != NULL) in xmlXPathNodeSetFreeNs()
2964 xmlFree((xmlChar *)ns->prefix); in xmlXPathNodeSetFreeNs()
2988 ret->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetCreate()
2990 if (ret->nodeTab == NULL) { in xmlXPathNodeSetCreate()
2995 memset(ret->nodeTab, 0 , in xmlXPathNodeSetCreate()
2997 ret->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetCreate()
2998 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetCreate()
3000 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetCreate()
3006 ret->nodeTab[ret->nodeNr++] = nsNode; in xmlXPathNodeSetCreate()
3008 ret->nodeTab[ret->nodeNr++] = val; in xmlXPathNodeSetCreate()
3015 * @cur: the node-set
3027 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetContains()
3028 for (i = 0; i < cur->nodeNr; i++) { in xmlXPathNodeSetContains()
3029 if (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetContains()
3033 ns2 = (xmlNsPtr) cur->nodeTab[i]; in xmlXPathNodeSetContains()
3036 if ((ns1->next != NULL) && (ns2->next == ns1->next) && in xmlXPathNodeSetContains()
3037 (xmlStrEqual(ns1->prefix, ns2->prefix))) in xmlXPathNodeSetContains()
3042 for (i = 0; i < cur->nodeNr; i++) { in xmlXPathNodeSetContains()
3043 if (cur->nodeTab[i] == val) in xmlXPathNodeSetContains()
3058 * Returns 0 in case of success and -1 in case of error
3066 (ns->type != XML_NAMESPACE_DECL) || in xmlXPathNodeSetAddNs()
3067 (node->type != XML_ELEMENT_NODE)) in xmlXPathNodeSetAddNs()
3068 return(-1); in xmlXPathNodeSetAddNs()
3074 for (i = 0;i < cur->nodeNr;i++) { in xmlXPathNodeSetAddNs()
3075 if ((cur->nodeTab[i] != NULL) && in xmlXPathNodeSetAddNs()
3076 (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) && in xmlXPathNodeSetAddNs()
3077 (((xmlNsPtr)cur->nodeTab[i])->next == (xmlNsPtr) node) && in xmlXPathNodeSetAddNs()
3078 (xmlStrEqual(ns->prefix, ((xmlNsPtr)cur->nodeTab[i])->prefix))) in xmlXPathNodeSetAddNs()
3085 if (cur->nodeMax == 0) { in xmlXPathNodeSetAddNs()
3086 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetAddNs()
3088 if (cur->nodeTab == NULL) { in xmlXPathNodeSetAddNs()
3090 return(-1); in xmlXPathNodeSetAddNs()
3092 memset(cur->nodeTab, 0 , in xmlXPathNodeSetAddNs()
3094 cur->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetAddNs()
3095 } else if (cur->nodeNr == cur->nodeMax) { in xmlXPathNodeSetAddNs()
3098 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) { in xmlXPathNodeSetAddNs()
3100 return(-1); in xmlXPathNodeSetAddNs()
3102 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * in xmlXPathNodeSetAddNs()
3106 return(-1); in xmlXPathNodeSetAddNs()
3108 cur->nodeMax *= 2; in xmlXPathNodeSetAddNs()
3109 cur->nodeTab = temp; in xmlXPathNodeSetAddNs()
3113 return(-1); in xmlXPathNodeSetAddNs()
3114 cur->nodeTab[cur->nodeNr++] = nsNode; in xmlXPathNodeSetAddNs()
3125 * Returns 0 in case of success, and -1 in case of error
3131 if ((cur == NULL) || (val == NULL)) return(-1); in xmlXPathNodeSetAdd()
3137 for (i = 0;i < cur->nodeNr;i++) in xmlXPathNodeSetAdd()
3138 if (cur->nodeTab[i] == val) return(0); in xmlXPathNodeSetAdd()
3143 if (cur->nodeMax == 0) { in xmlXPathNodeSetAdd()
3144 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetAdd()
3146 if (cur->nodeTab == NULL) { in xmlXPathNodeSetAdd()
3148 return(-1); in xmlXPathNodeSetAdd()
3150 memset(cur->nodeTab, 0 , in xmlXPathNodeSetAdd()
3152 cur->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetAdd()
3153 } else if (cur->nodeNr == cur->nodeMax) { in xmlXPathNodeSetAdd()
3156 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) { in xmlXPathNodeSetAdd()
3158 return(-1); in xmlXPathNodeSetAdd()
3160 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * in xmlXPathNodeSetAdd()
3164 return(-1); in xmlXPathNodeSetAdd()
3166 cur->nodeMax *= 2; in xmlXPathNodeSetAdd()
3167 cur->nodeTab = temp; in xmlXPathNodeSetAdd()
3169 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetAdd()
3171 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetAdd()
3174 return(-1); in xmlXPathNodeSetAdd()
3175 cur->nodeTab[cur->nodeNr++] = nsNode; in xmlXPathNodeSetAdd()
3177 cur->nodeTab[cur->nodeNr++] = val; in xmlXPathNodeSetAdd()
3189 * Returns 0 in case of success and -1 in case of failure
3193 if ((cur == NULL) || (val == NULL)) return(-1); in xmlXPathNodeSetAddUnique()
3199 if (cur->nodeMax == 0) { in xmlXPathNodeSetAddUnique()
3200 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetAddUnique()
3202 if (cur->nodeTab == NULL) { in xmlXPathNodeSetAddUnique()
3204 return(-1); in xmlXPathNodeSetAddUnique()
3206 memset(cur->nodeTab, 0 , in xmlXPathNodeSetAddUnique()
3208 cur->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetAddUnique()
3209 } else if (cur->nodeNr == cur->nodeMax) { in xmlXPathNodeSetAddUnique()
3212 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) { in xmlXPathNodeSetAddUnique()
3214 return(-1); in xmlXPathNodeSetAddUnique()
3216 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * in xmlXPathNodeSetAddUnique()
3220 return(-1); in xmlXPathNodeSetAddUnique()
3222 cur->nodeTab = temp; in xmlXPathNodeSetAddUnique()
3223 cur->nodeMax *= 2; in xmlXPathNodeSetAddUnique()
3225 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetAddUnique()
3227 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetAddUnique()
3230 return(-1); in xmlXPathNodeSetAddUnique()
3231 cur->nodeTab[cur->nodeNr++] = nsNode; in xmlXPathNodeSetAddUnique()
3233 cur->nodeTab[cur->nodeNr++] = val; in xmlXPathNodeSetAddUnique()
3262 initNr = val1->nodeNr; in xmlXPathNodeSetMerge()
3264 for (i = 0;i < val2->nodeNr;i++) { in xmlXPathNodeSetMerge()
3265 n2 = val2->nodeTab[i]; in xmlXPathNodeSetMerge()
3271 n1 = val1->nodeTab[j]; in xmlXPathNodeSetMerge()
3275 } else if ((n1->type == XML_NAMESPACE_DECL) && in xmlXPathNodeSetMerge()
3276 (n2->type == XML_NAMESPACE_DECL)) { in xmlXPathNodeSetMerge()
3277 if ((((xmlNsPtr) n1)->next == ((xmlNsPtr) n2)->next) && in xmlXPathNodeSetMerge()
3278 (xmlStrEqual(((xmlNsPtr) n1)->prefix, in xmlXPathNodeSetMerge()
3279 ((xmlNsPtr) n2)->prefix))) in xmlXPathNodeSetMerge()
3292 if (val1->nodeMax == 0) { in xmlXPathNodeSetMerge()
3293 val1->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetMerge()
3295 if (val1->nodeTab == NULL) { in xmlXPathNodeSetMerge()
3299 memset(val1->nodeTab, 0 , in xmlXPathNodeSetMerge()
3301 val1->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetMerge()
3302 } else if (val1->nodeNr == val1->nodeMax) { in xmlXPathNodeSetMerge()
3305 if (val1->nodeMax >= XPATH_MAX_NODESET_LENGTH) { in xmlXPathNodeSetMerge()
3309 temp = (xmlNodePtr *) xmlRealloc(val1->nodeTab, val1->nodeMax * 2 * in xmlXPathNodeSetMerge()
3315 val1->nodeTab = temp; in xmlXPathNodeSetMerge()
3316 val1->nodeMax *= 2; in xmlXPathNodeSetMerge()
3318 if (n2->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetMerge()
3320 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetMerge()
3324 val1->nodeTab[val1->nodeNr++] = nsNode; in xmlXPathNodeSetMerge()
3326 val1->nodeTab[val1->nodeNr++] = n2; in xmlXPathNodeSetMerge()
3356 initNbSet1 = set1->nodeNr; in xmlXPathNodeSetMergeAndClear()
3357 for (i = 0;i < set2->nodeNr;i++) { in xmlXPathNodeSetMergeAndClear()
3358 n2 = set2->nodeTab[i]; in xmlXPathNodeSetMergeAndClear()
3363 n1 = set1->nodeTab[j]; in xmlXPathNodeSetMergeAndClear()
3366 } else if ((n1->type == XML_NAMESPACE_DECL) && in xmlXPathNodeSetMergeAndClear()
3367 (n2->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetMergeAndClear()
3369 if ((((xmlNsPtr) n1)->next == ((xmlNsPtr) n2)->next) && in xmlXPathNodeSetMergeAndClear()
3370 (xmlStrEqual(((xmlNsPtr) n1)->prefix, in xmlXPathNodeSetMergeAndClear()
3371 ((xmlNsPtr) n2)->prefix))) in xmlXPathNodeSetMergeAndClear()
3384 if (set1->nodeMax == 0) { in xmlXPathNodeSetMergeAndClear()
3385 set1->nodeTab = (xmlNodePtr *) xmlMalloc( in xmlXPathNodeSetMergeAndClear()
3387 if (set1->nodeTab == NULL) { in xmlXPathNodeSetMergeAndClear()
3391 memset(set1->nodeTab, 0, in xmlXPathNodeSetMergeAndClear()
3393 set1->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetMergeAndClear()
3394 } else if (set1->nodeNr >= set1->nodeMax) { in xmlXPathNodeSetMergeAndClear()
3397 if (set1->nodeMax >= XPATH_MAX_NODESET_LENGTH) { in xmlXPathNodeSetMergeAndClear()
3402 set1->nodeTab, set1->nodeMax * 2 * sizeof(xmlNodePtr)); in xmlXPathNodeSetMergeAndClear()
3407 set1->nodeTab = temp; in xmlXPathNodeSetMergeAndClear()
3408 set1->nodeMax *= 2; in xmlXPathNodeSetMergeAndClear()
3410 set1->nodeTab[set1->nodeNr++] = n2; in xmlXPathNodeSetMergeAndClear()
3412 set2->nodeTab[i] = NULL; in xmlXPathNodeSetMergeAndClear()
3415 set2->nodeNr = 0; in xmlXPathNodeSetMergeAndClear()
3443 for (i = 0;i < set2->nodeNr;i++) { in xmlXPathNodeSetMergeAndClearNoDupls()
3444 n2 = set2->nodeTab[i]; in xmlXPathNodeSetMergeAndClearNoDupls()
3445 if (set1->nodeMax == 0) { in xmlXPathNodeSetMergeAndClearNoDupls()
3446 set1->nodeTab = (xmlNodePtr *) xmlMalloc( in xmlXPathNodeSetMergeAndClearNoDupls()
3448 if (set1->nodeTab == NULL) { in xmlXPathNodeSetMergeAndClearNoDupls()
3452 memset(set1->nodeTab, 0, in xmlXPathNodeSetMergeAndClearNoDupls()
3454 set1->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetMergeAndClearNoDupls()
3455 } else if (set1->nodeNr >= set1->nodeMax) { in xmlXPathNodeSetMergeAndClearNoDupls()
3458 if (set1->nodeMax >= XPATH_MAX_NODESET_LENGTH) { in xmlXPathNodeSetMergeAndClearNoDupls()
3463 set1->nodeTab, set1->nodeMax * 2 * sizeof(xmlNodePtr)); in xmlXPathNodeSetMergeAndClearNoDupls()
3468 set1->nodeTab = temp; in xmlXPathNodeSetMergeAndClearNoDupls()
3469 set1->nodeMax *= 2; in xmlXPathNodeSetMergeAndClearNoDupls()
3471 set1->nodeTab[set1->nodeNr++] = n2; in xmlXPathNodeSetMergeAndClearNoDupls()
3472 set2->nodeTab[i] = NULL; in xmlXPathNodeSetMergeAndClearNoDupls()
3475 set2->nodeNr = 0; in xmlXPathNodeSetMergeAndClearNoDupls()
3501 for (i = 0;i < cur->nodeNr;i++) in xmlXPathNodeSetDel()
3502 if (cur->nodeTab[i] == val) break; in xmlXPathNodeSetDel()
3504 if (i >= cur->nodeNr) { /* not found */ in xmlXPathNodeSetDel()
3507 if ((cur->nodeTab[i] != NULL) && in xmlXPathNodeSetDel()
3508 (cur->nodeTab[i]->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetDel()
3509 xmlXPathNodeSetFreeNs((xmlNsPtr) cur->nodeTab[i]); in xmlXPathNodeSetDel()
3510 cur->nodeNr--; in xmlXPathNodeSetDel()
3511 for (;i < cur->nodeNr;i++) in xmlXPathNodeSetDel()
3512 cur->nodeTab[i] = cur->nodeTab[i + 1]; in xmlXPathNodeSetDel()
3513 cur->nodeTab[cur->nodeNr] = NULL; in xmlXPathNodeSetDel()
3526 if (val >= cur->nodeNr) return; in xmlXPathNodeSetRemove()
3527 if ((cur->nodeTab[val] != NULL) && in xmlXPathNodeSetRemove()
3528 (cur->nodeTab[val]->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetRemove()
3529 xmlXPathNodeSetFreeNs((xmlNsPtr) cur->nodeTab[val]); in xmlXPathNodeSetRemove()
3530 cur->nodeNr--; in xmlXPathNodeSetRemove()
3531 for (;val < cur->nodeNr;val++) in xmlXPathNodeSetRemove()
3532 cur->nodeTab[val] = cur->nodeTab[val + 1]; in xmlXPathNodeSetRemove()
3533 cur->nodeTab[cur->nodeNr] = NULL; in xmlXPathNodeSetRemove()
3545 if (obj->nodeTab != NULL) { in xmlXPathFreeNodeSet()
3549 for (i = 0;i < obj->nodeNr;i++) in xmlXPathFreeNodeSet()
3550 if ((obj->nodeTab[i] != NULL) && in xmlXPathFreeNodeSet()
3551 (obj->nodeTab[i]->type == XML_NAMESPACE_DECL)) in xmlXPathFreeNodeSet()
3552 xmlXPathNodeSetFreeNs((xmlNsPtr) obj->nodeTab[i]); in xmlXPathFreeNodeSet()
3553 xmlFree(obj->nodeTab); in xmlXPathFreeNodeSet()
3570 if ((set == NULL) || (pos >= set->nodeNr)) in xmlXPathNodeSetClearFromPos()
3576 for (i = pos; i < set->nodeNr; i++) { in xmlXPathNodeSetClearFromPos()
3577 node = set->nodeTab[i]; in xmlXPathNodeSetClearFromPos()
3579 (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetClearFromPos()
3583 set->nodeNr = pos; in xmlXPathNodeSetClearFromPos()
3614 if ((set == NULL) || (set->nodeNr <= 1)) in xmlXPathNodeSetKeepLast()
3616 for (i = 0; i < set->nodeNr - 1; i++) { in xmlXPathNodeSetKeepLast()
3617 node = set->nodeTab[i]; in xmlXPathNodeSetKeepLast()
3619 (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetKeepLast()
3622 set->nodeTab[0] = set->nodeTab[set->nodeNr-1]; in xmlXPathNodeSetKeepLast()
3623 set->nodeNr = 1; in xmlXPathNodeSetKeepLast()
3639 if (obj->nodeTab != NULL) { in xmlXPathFreeValueTree()
3640 for (i = 0;i < obj->nodeNr;i++) { in xmlXPathFreeValueTree()
3641 if (obj->nodeTab[i] != NULL) { in xmlXPathFreeValueTree()
3642 if (obj->nodeTab[i]->type == XML_NAMESPACE_DECL) { in xmlXPathFreeValueTree()
3643 xmlXPathNodeSetFreeNs((xmlNsPtr) obj->nodeTab[i]); in xmlXPathFreeValueTree()
3645 xmlFreeNodeList(obj->nodeTab[i]); in xmlXPathFreeValueTree()
3649 xmlFree(obj->nodeTab); in xmlXPathFreeValueTree()
3673 ret->type = XPATH_NODESET; in xmlXPathNewNodeSet()
3674 ret->boolval = 0; in xmlXPathNewNodeSet()
3676 ret->nodesetval = xmlXPathNodeSetCreate(val); in xmlXPathNewNodeSet()
3700 ret->type = XPATH_XSLT_TREE; in xmlXPathNewValueTree()
3701 ret->boolval = 0; in xmlXPathNewValueTree()
3702 ret->user = (void *) val; in xmlXPathNewValueTree()
3703 ret->nodesetval = xmlXPathNodeSetCreate(val); in xmlXPathNewValueTree()
3724 else if (val->nodeTab == NULL) in xmlXPathNewNodeSetList()
3727 ret = xmlXPathNewNodeSet(val->nodeTab[0]); in xmlXPathNewNodeSetList()
3729 for (i = 1; i < val->nodeNr; ++i) { in xmlXPathNewNodeSetList()
3731 if (xmlXPathNodeSetAddUnique(ret->nodesetval, val->nodeTab[i]) in xmlXPathNewNodeSetList()
3761 ret->type = XPATH_NODESET; in xmlXPathWrapNodeSet()
3762 ret->nodesetval = val; in xmlXPathWrapNodeSet()
3781 * @nodes1: a node-set
3782 * @nodes2: a node-set
3784 * Implements the EXSLT - Sets difference() function:
3785 * node-set set:difference (node-set, node-set)
3819 * @nodes1: a node-set
3820 * @nodes2: a node-set
3822 * Implements the EXSLT - Sets intersection() function:
3823 * node-set set:intersection (node-set, node-set)
3856 * @nodes: a node-set, sorted by document order
3858 * Implements the EXSLT - Sets distinct() function:
3859 * node-set set:distinct (node-set)
3905 * @nodes: a node-set
3907 * Implements the EXSLT - Sets distinct() function:
3908 * node-set set:distinct (node-set)
3910 * is called with the sorted node-set
3926 * @nodes1: a node-set
3927 * @nodes2: a node-set
3929 * Implements the EXSLT - Sets has-same-nodes function:
3930 * boolean set:has-same-node(node-set, node-set)
3955 * @nodes: a node-set, sorted by document order
3958 * Implements the EXSLT - Sets leading() function:
3959 * node-set set:leading (node-set, node-set)
3962 * @nodes if @node is NULL or an empty node-set if @nodes
3995 * @nodes: a node-set
3998 * Implements the EXSLT - Sets leading() function:
3999 * node-set set:leading (node-set, node-set)
4004 * @nodes if @node is NULL or an empty node-set if @nodes
4015 * @nodes1: a node-set, sorted by document order
4016 * @nodes2: a node-set, sorted by document order
4018 * Implements the EXSLT - Sets leading() function:
4019 * node-set set:leading (node-set, node-set)
4023 * an empty node-set if @nodes1 doesn't contain @nodes2
4035 * @nodes1: a node-set
4036 * @nodes2: a node-set
4038 * Implements the EXSLT - Sets leading() function:
4039 * node-set set:leading (node-set, node-set)
4045 * an empty node-set if @nodes1 doesn't contain @nodes2
4061 * @nodes: a node-set, sorted by document order
4064 * Implements the EXSLT - Sets trailing() function:
4065 * node-set set:trailing (node-set, node-set)
4068 * @nodes if @node is NULL or an empty node-set if @nodes
4088 for (i = l - 1; i >= 0; i--) { in xmlXPathNodeTrailingSorted()
4102 * @nodes: a node-set
4105 * Implements the EXSLT - Sets trailing() function:
4106 * node-set set:trailing (node-set, node-set)
4111 * @nodes if @node is NULL or an empty node-set if @nodes
4122 * @nodes1: a node-set, sorted by document order
4123 * @nodes2: a node-set, sorted by document order
4125 * Implements the EXSLT - Sets trailing() function:
4126 * node-set set:trailing (node-set, node-set)
4130 * an empty node-set if @nodes1 doesn't contain @nodes2
4142 * @nodes1: a node-set
4143 * @nodes2: a node-set
4145 * Implements the EXSLT - Sets trailing() function:
4146 * node-set set:trailing (node-set, node-set)
4152 * an empty node-set if @nodes1 doesn't contain @nodes2
4180 * Returns 0 in case of success, -1 in case of error
4197 * Returns 0 in case of success, -1 in case of error
4203 return(-1); in xmlXPathRegisterFuncNS()
4205 return(-1); in xmlXPathRegisterFuncNS()
4207 if (ctxt->funcHash == NULL) in xmlXPathRegisterFuncNS()
4208 ctxt->funcHash = xmlHashCreate(0); in xmlXPathRegisterFuncNS()
4209 if (ctxt->funcHash == NULL) in xmlXPathRegisterFuncNS()
4210 return(-1); in xmlXPathRegisterFuncNS()
4212 return(xmlHashRemoveEntry2(ctxt->funcHash, name, ns_uri, NULL)); in xmlXPathRegisterFuncNS()
4214 return(xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, (void *) f)); in xmlXPathRegisterFuncNS()
4232 ctxt->funcLookupFunc = f; in xmlXPathRegisterFuncLookup()
4233 ctxt->funcLookupData = funcCtxt; in xmlXPathRegisterFuncLookup()
4251 if (ctxt->funcLookupFunc != NULL) { in xmlXPathFunctionLookup()
4255 f = ctxt->funcLookupFunc; in xmlXPathFunctionLookup()
4256 ret = f(ctxt->funcLookupData, name, NULL); in xmlXPathFunctionLookup()
4284 if (ctxt->funcLookupFunc != NULL) { in xmlXPathFunctionLookupNS()
4287 f = ctxt->funcLookupFunc; in xmlXPathFunctionLookupNS()
4288 ret = f(ctxt->funcLookupData, name, ns_uri); in xmlXPathFunctionLookupNS()
4293 if (ctxt->funcHash == NULL) in xmlXPathFunctionLookupNS()
4297 ret = (xmlXPathFunction) xmlHashLookup2(ctxt->funcHash, name, ns_uri); in xmlXPathFunctionLookupNS()
4313 xmlHashFree(ctxt->funcHash, NULL); in xmlXPathRegisteredFuncsCleanup()
4314 ctxt->funcHash = NULL; in xmlXPathRegisteredFuncsCleanup()
4332 * Returns 0 in case of success, -1 in case of error
4350 * Returns 0 in case of success, -1 in case of error
4357 return(-1); in xmlXPathRegisterVariableNS()
4359 return(-1); in xmlXPathRegisterVariableNS()
4361 if (ctxt->varHash == NULL) in xmlXPathRegisterVariableNS()
4362 ctxt->varHash = xmlHashCreate(0); in xmlXPathRegisterVariableNS()
4363 if (ctxt->varHash == NULL) in xmlXPathRegisterVariableNS()
4364 return(-1); in xmlXPathRegisterVariableNS()
4366 return(xmlHashRemoveEntry2(ctxt->varHash, name, ns_uri, in xmlXPathRegisterVariableNS()
4368 return(xmlHashUpdateEntry2(ctxt->varHash, name, ns_uri, in xmlXPathRegisterVariableNS()
4385 ctxt->varLookupFunc = f; in xmlXPathRegisterVariableLookup()
4386 ctxt->varLookupData = data; in xmlXPathRegisterVariableLookup()
4404 if (ctxt->varLookupFunc != NULL) { in xmlXPathVariableLookup()
4407 ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc) in xmlXPathVariableLookup()
4408 (ctxt->varLookupData, name, NULL); in xmlXPathVariableLookup()
4431 if (ctxt->varLookupFunc != NULL) { in xmlXPathVariableLookupNS()
4434 ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc) in xmlXPathVariableLookupNS()
4435 (ctxt->varLookupData, name, ns_uri); in xmlXPathVariableLookupNS()
4439 if (ctxt->varHash == NULL) in xmlXPathVariableLookupNS()
4445 xmlHashLookup2(ctxt->varHash, name, ns_uri))); in xmlXPathVariableLookupNS()
4459 xmlHashFree(ctxt->varHash, xmlXPathFreeObjectEntry); in xmlXPathRegisteredVariablesCleanup()
4460 ctxt->varHash = NULL; in xmlXPathRegisteredVariablesCleanup()
4472 * Returns 0 in case of success, -1 in case of error
4480 return(-1); in xmlXPathRegisterNs()
4482 return(-1); in xmlXPathRegisterNs()
4484 return(-1); in xmlXPathRegisterNs()
4486 if (ctxt->nsHash == NULL) in xmlXPathRegisterNs()
4487 ctxt->nsHash = xmlHashCreate(10); in xmlXPathRegisterNs()
4488 if (ctxt->nsHash == NULL) in xmlXPathRegisterNs()
4489 return(-1); in xmlXPathRegisterNs()
4491 return(xmlHashRemoveEntry(ctxt->nsHash, prefix, in xmlXPathRegisterNs()
4496 return(-1); in xmlXPathRegisterNs()
4497 if (xmlHashUpdateEntry(ctxt->nsHash, prefix, copy, in xmlXPathRegisterNs()
4500 return(-1); in xmlXPathRegisterNs()
4528 if (ctxt->namespaces != NULL) { in xmlXPathNsLookup()
4531 for (i = 0;i < ctxt->nsNr;i++) { in xmlXPathNsLookup()
4532 if ((ctxt->namespaces[i] != NULL) && in xmlXPathNsLookup()
4533 (xmlStrEqual(ctxt->namespaces[i]->prefix, prefix))) in xmlXPathNsLookup()
4534 return(ctxt->namespaces[i]->href); in xmlXPathNsLookup()
4538 return((const xmlChar *) xmlHashLookup(ctxt->nsHash, prefix)); in xmlXPathNsLookup()
4552 xmlHashFree(ctxt->nsHash, xmlHashDefaultDeallocator); in xmlXPathRegisteredNsCleanup()
4553 ctxt->nsHash = NULL; in xmlXPathRegisteredNsCleanup()
4582 ret->type = XPATH_NUMBER; in xmlXPathNewFloat()
4583 ret->floatval = val; in xmlXPathNewFloat()
4605 ret->type = XPATH_BOOLEAN; in xmlXPathNewBoolean()
4606 ret->boolval = (val != 0); in xmlXPathNewBoolean()
4628 ret->type = XPATH_STRING; in xmlXPathNewString()
4631 ret->stringval = xmlStrdup(val); in xmlXPathNewString()
4632 if (ret->stringval == NULL) { in xmlXPathNewString()
4660 ret->type = XPATH_STRING; in xmlXPathWrapString()
4661 ret->stringval = val; in xmlXPathWrapString()
4709 ret->type = XPATH_USERS; in xmlXPathWrapExternal()
4710 ret->user = val; in xmlXPathWrapExternal()
4735 switch (val->type) { in xmlXPathObjectCopy()
4744 ret->stringval = xmlStrdup(val->stringval); in xmlXPathObjectCopy()
4745 if (ret->stringval == NULL) { in xmlXPathObjectCopy()
4753 Removed 11 July 2004 - the current handling of xslt tmpRVT nodes means that in xmlXPathObjectCopy()
4757 if ((val->nodesetval != NULL) && in xmlXPathObjectCopy()
4758 (val->nodesetval->nodeTab != NULL)) { in xmlXPathObjectCopy()
4762 ret->boolval = 1; in xmlXPathObjectCopy()
4764 top->name = (char *) in xmlXPathObjectCopy()
4765 xmlStrdup(val->nodesetval->nodeTab[0]->name); in xmlXPathObjectCopy()
4766 ret->user = top; in xmlXPathObjectCopy()
4768 top->doc = top; in xmlXPathObjectCopy()
4769 cur = val->nodesetval->nodeTab[0]->children; in xmlXPathObjectCopy()
4773 cur = cur->next; in xmlXPathObjectCopy()
4777 ret->nodesetval = xmlXPathNodeSetCreate((xmlNodePtr) top); in xmlXPathObjectCopy()
4779 ret->nodesetval = xmlXPathNodeSetCreate(NULL); in xmlXPathObjectCopy()
4785 ret->nodesetval = xmlXPathNodeSetMerge(NULL, val->nodesetval); in xmlXPathObjectCopy()
4787 ret->boolval = 0; in xmlXPathObjectCopy()
4792 xmlLocationSetPtr loc = val->user; in xmlXPathObjectCopy()
4793 ret->user = (void *) xmlXPtrLocationSetMerge(NULL, loc); in xmlXPathObjectCopy()
4798 ret->user = val->user; in xmlXPathObjectCopy()
4803 val->type); in xmlXPathObjectCopy()
4818 if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) { in xmlXPathFreeObject()
4819 if (obj->boolval) { in xmlXPathFreeObject()
4821 if (obj->user != NULL) { in xmlXPathFreeObject()
4822 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathFreeObject()
4823 xmlFreeNodeList((xmlNodePtr) obj->user); in xmlXPathFreeObject()
4826 obj->type = XPATH_XSLT_TREE; /* TODO: Just for debugging. */ in xmlXPathFreeObject()
4827 if (obj->nodesetval != NULL) in xmlXPathFreeObject()
4828 xmlXPathFreeValueTree(obj->nodesetval); in xmlXPathFreeObject()
4830 if (obj->nodesetval != NULL) in xmlXPathFreeObject()
4831 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathFreeObject()
4834 } else if (obj->type == XPATH_LOCATIONSET) { in xmlXPathFreeObject()
4835 if (obj->user != NULL) in xmlXPathFreeObject()
4836 xmlXPtrFreeLocationSet(obj->user); in xmlXPathFreeObject()
4838 } else if (obj->type == XPATH_STRING) { in xmlXPathFreeObject()
4839 if (obj->stringval != NULL) in xmlXPathFreeObject()
4840 xmlFree(obj->stringval); in xmlXPathFreeObject()
4862 if (xmlPointerListAddSize(sl, obj, 0) == -1) goto free_obj; in xmlXPathReleaseObject()
4864 #define XP_CACHE_WANTS(sl, n) ((sl == NULL) || ((sl)->number < n)) in xmlXPathReleaseObject()
4868 if ((ctxt == NULL) || (ctxt->cache == NULL)) { in xmlXPathReleaseObject()
4872 (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathReleaseObject()
4874 switch (obj->type) { in xmlXPathReleaseObject()
4877 if (obj->nodesetval != NULL) { in xmlXPathReleaseObject()
4878 if (obj->boolval) { in xmlXPathReleaseObject()
4884 obj->type = XPATH_XSLT_TREE; /* just for debugging */ in xmlXPathReleaseObject()
4885 xmlXPathFreeValueTree(obj->nodesetval); in xmlXPathReleaseObject()
4886 obj->nodesetval = NULL; in xmlXPathReleaseObject()
4887 } else if ((obj->nodesetval->nodeMax <= 40) && in xmlXPathReleaseObject()
4888 (XP_CACHE_WANTS(cache->nodesetObjs, in xmlXPathReleaseObject()
4889 cache->maxNodeset))) in xmlXPathReleaseObject()
4891 XP_CACHE_ADD(cache->nodesetObjs, obj); in xmlXPathReleaseObject()
4894 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathReleaseObject()
4895 obj->nodesetval = NULL; in xmlXPathReleaseObject()
4900 if (obj->stringval != NULL) in xmlXPathReleaseObject()
4901 xmlFree(obj->stringval); in xmlXPathReleaseObject()
4903 if (XP_CACHE_WANTS(cache->stringObjs, cache->maxString)) { in xmlXPathReleaseObject()
4904 XP_CACHE_ADD(cache->stringObjs, obj); in xmlXPathReleaseObject()
4909 if (XP_CACHE_WANTS(cache->booleanObjs, cache->maxBoolean)) { in xmlXPathReleaseObject()
4910 XP_CACHE_ADD(cache->booleanObjs, obj); in xmlXPathReleaseObject()
4915 if (XP_CACHE_WANTS(cache->numberObjs, cache->maxNumber)) { in xmlXPathReleaseObject()
4916 XP_CACHE_ADD(cache->numberObjs, obj); in xmlXPathReleaseObject()
4922 if (obj->user != NULL) { in xmlXPathReleaseObject()
4923 xmlXPtrFreeLocationSet(obj->user); in xmlXPathReleaseObject()
4932 * Fallback to adding to the misc-objects slot. in xmlXPathReleaseObject()
4934 if (XP_CACHE_WANTS(cache->miscObjs, cache->maxMisc)) { in xmlXPathReleaseObject()
4935 XP_CACHE_ADD(cache->miscObjs, obj); in xmlXPathReleaseObject()
4940 if (obj->nodesetval != NULL) { in xmlXPathReleaseObject()
4941 xmlNodeSetPtr tmpset = obj->nodesetval; in xmlXPathReleaseObject()
4944 * TODO: Due to those nasty ns-nodes, we need to traverse in xmlXPathReleaseObject()
4945 * the list and free the ns-nodes. in xmlXPathReleaseObject()
4949 if (tmpset->nodeNr > 1) { in xmlXPathReleaseObject()
4953 for (i = 0; i < tmpset->nodeNr; i++) { in xmlXPathReleaseObject()
4954 node = tmpset->nodeTab[i]; in xmlXPathReleaseObject()
4956 (node->type == XML_NAMESPACE_DECL)) in xmlXPathReleaseObject()
4961 } else if (tmpset->nodeNr == 1) { in xmlXPathReleaseObject()
4962 if ((tmpset->nodeTab[0] != NULL) && in xmlXPathReleaseObject()
4963 (tmpset->nodeTab[0]->type == XML_NAMESPACE_DECL)) in xmlXPathReleaseObject()
4964 xmlXPathNodeSetFreeNs((xmlNsPtr) tmpset->nodeTab[0]); in xmlXPathReleaseObject()
4966 tmpset->nodeNr = 0; in xmlXPathReleaseObject()
4968 obj->nodesetval = tmpset; in xmlXPathReleaseObject()
4978 if (obj->nodesetval != NULL) in xmlXPathReleaseObject()
4979 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathReleaseObject()
5025 case -1: in xmlXPathCastNumberToString()
5026 ret = xmlStrdup((const xmlChar *) "-Infinity"); in xmlXPathCastNumberToString()
5063 * @ns: a node-set
5065 * Converts a node-set to its string value.
5071 if ((ns == NULL) || (ns->nodeNr == 0) || (ns->nodeTab == NULL)) in xmlXPathCastNodeSetToString()
5074 if (ns->nodeNr > 1) in xmlXPathCastNodeSetToString()
5076 return(xmlXPathCastNodeToString(ns->nodeTab[0])); in xmlXPathCastNodeSetToString()
5094 switch (val->type) { in xmlXPathCastToString()
5100 ret = xmlXPathCastNodeSetToString(val->nodesetval); in xmlXPathCastToString()
5103 return(xmlStrdup(val->stringval)); in xmlXPathCastToString()
5105 ret = xmlXPathCastBooleanToString(val->boolval); in xmlXPathCastToString()
5108 ret = xmlXPathCastNumberToString(val->floatval); in xmlXPathCastToString()
5140 switch (val->type) { in xmlXPathConvertString()
5145 res = xmlXPathCastNodeSetToString(val->nodesetval); in xmlXPathConvertString()
5150 res = xmlXPathCastBooleanToString(val->boolval); in xmlXPathConvertString()
5153 res = xmlXPathCastNumberToString(val->floatval); in xmlXPathConvertString()
5224 * @ns: a node-set
5226 * Converts a node-set to its number value
5257 switch (val->type) { in xmlXPathCastToNumber()
5263 ret = xmlXPathCastNodeSetToNumber(val->nodesetval); in xmlXPathCastToNumber()
5266 ret = xmlXPathCastStringToNumber(val->stringval); in xmlXPathCastToNumber()
5269 ret = val->floatval; in xmlXPathCastToNumber()
5272 ret = xmlXPathCastBooleanToNumber(val->boolval); in xmlXPathCastToNumber()
5302 if (val->type == XPATH_NUMBER) in xmlXPathConvertNumber()
5341 * @ns: a node-set
5343 * Converts a node-set to its boolean value
5349 if ((ns == NULL) || (ns->nodeNr == 0)) in xmlXPathCastNodeSetToBoolean()
5368 switch (val->type) { in xmlXPathCastToBoolean()
5374 ret = xmlXPathCastNodeSetToBoolean(val->nodesetval); in xmlXPathCastToBoolean()
5377 ret = xmlXPathCastStringToBoolean(val->stringval); in xmlXPathCastToBoolean()
5380 ret = xmlXPathCastNumberToBoolean(val->floatval); in xmlXPathCastToBoolean()
5383 ret = val->boolval; in xmlXPathCastToBoolean()
5414 if (val->type == XPATH_BOOLEAN) in xmlXPathConvertBoolean()
5445 ret->doc = doc; in xmlXPathNewContext()
5446 ret->node = NULL; in xmlXPathNewContext()
5448 ret->varHash = NULL; in xmlXPathNewContext()
5450 ret->nb_types = 0; in xmlXPathNewContext()
5451 ret->max_types = 0; in xmlXPathNewContext()
5452 ret->types = NULL; in xmlXPathNewContext()
5454 ret->funcHash = xmlHashCreate(0); in xmlXPathNewContext()
5456 ret->nb_axis = 0; in xmlXPathNewContext()
5457 ret->max_axis = 0; in xmlXPathNewContext()
5458 ret->axis = NULL; in xmlXPathNewContext()
5460 ret->nsHash = NULL; in xmlXPathNewContext()
5461 ret->user = NULL; in xmlXPathNewContext()
5463 ret->contextSize = -1; in xmlXPathNewContext()
5464 ret->proximityPosition = -1; in xmlXPathNewContext()
5467 if (xmlXPathContextSetCache(ret, 1, -1, 0) == -1) { in xmlXPathNewContext()
5488 if (ctxt->cache != NULL) in xmlXPathFreeContext()
5489 xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache); in xmlXPathFreeContext()
5493 xmlResetError(&ctxt->lastError); in xmlXPathFreeContext()
5522 return(-1); \
5527 if ((ctxt == NULL) || (ctxt->doc == NULL) || \
5528 (ctxt->doc->children == NULL)) { \
5553 ret->cur = ret->base = str; in xmlXPathNewParserContext()
5554 ret->context = ctxt; in xmlXPathNewParserContext()
5556 ret->comp = xmlXPathNewCompExpr(); in xmlXPathNewParserContext()
5557 if (ret->comp == NULL) { in xmlXPathNewParserContext()
5558 xmlFree(ret->valueTab); in xmlXPathNewParserContext()
5562 if ((ctxt != NULL) && (ctxt->dict != NULL)) { in xmlXPathNewParserContext()
5563 ret->comp->dict = ctxt->dict; in xmlXPathNewParserContext()
5564 xmlDictReference(ret->comp->dict); in xmlXPathNewParserContext()
5591 ret->valueTab = (xmlXPathObjectPtr *) in xmlXPathCompParserContext()
5593 if (ret->valueTab == NULL) { in xmlXPathCompParserContext()
5598 ret->valueNr = 0; in xmlXPathCompParserContext()
5599 ret->valueMax = 10; in xmlXPathCompParserContext()
5600 ret->value = NULL; in xmlXPathCompParserContext()
5602 ret->context = ctxt; in xmlXPathCompParserContext()
5603 ret->comp = comp; in xmlXPathCompParserContext()
5618 if (ctxt->valueTab != NULL) { in xmlXPathFreeParserContext()
5619 for (i = 0; i < ctxt->valueNr; i++) { in xmlXPathFreeParserContext()
5620 if (ctxt->context) in xmlXPathFreeParserContext()
5621 xmlXPathReleaseObject(ctxt->context, ctxt->valueTab[i]); in xmlXPathFreeParserContext()
5623 xmlXPathFreeObject(ctxt->valueTab[i]); in xmlXPathFreeParserContext()
5625 xmlFree(ctxt->valueTab); in xmlXPathFreeParserContext()
5627 if (ctxt->comp != NULL) { in xmlXPathFreeParserContext()
5629 if (ctxt->comp->stream != NULL) { in xmlXPathFreeParserContext()
5630 xmlFreePatternList(ctxt->comp->stream); in xmlXPathFreeParserContext()
5631 ctxt->comp->stream = NULL; in xmlXPathFreeParserContext()
5634 xmlXPathFreeCompExpr(ctxt->comp); in xmlXPathFreeParserContext()
5664 if (node->type == XML_DOCUMENT_NODE) { in xmlXPathNodeValHash()
5667 node = node->children; in xmlXPathNodeValHash()
5675 switch (node->type) { in xmlXPathNodeValHash()
5680 string = node->content; in xmlXPathNodeValHash()
5687 string = ((xmlNsPtr)node)->href; in xmlXPathNodeValHash()
5694 tmp = ((xmlAttrPtr) node)->children; in xmlXPathNodeValHash()
5697 tmp = node->children; in xmlXPathNodeValHash()
5703 switch (tmp->type) { in xmlXPathNodeValHash()
5706 string = tmp->content; in xmlXPathNodeValHash()
5726 if ((tmp->children != NULL) && in xmlXPathNodeValHash()
5727 (tmp->type != XML_DTD_NODE) && in xmlXPathNodeValHash()
5728 (tmp->type != XML_ENTITY_REF_NODE) && in xmlXPathNodeValHash()
5729 (tmp->children->type != XML_ENTITY_DECL)) { in xmlXPathNodeValHash()
5730 tmp = tmp->children; in xmlXPathNodeValHash()
5736 if (tmp->next != NULL) { in xmlXPathNodeValHash()
5737 tmp = tmp->next; in xmlXPathNodeValHash()
5742 tmp = tmp->parent; in xmlXPathNodeValHash()
5749 if (tmp->next != NULL) { in xmlXPathNodeValHash()
5750 tmp = tmp->next; in xmlXPathNodeValHash()
5790 * If one object to be compared is a node-set and the other is a number,
5792 * node-set such that the result of performing the comparison on the number
5793 * to be compared and on the result of converting the string-value of that
5806 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSetFloat()
5807 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetFloat()
5808 xmlXPathReleaseObject(ctxt->context, f); in xmlXPathCompareNodeSetFloat()
5811 ns = arg->nodesetval; in xmlXPathCompareNodeSetFloat()
5813 for (i = 0;i < ns->nodeNr;i++) { in xmlXPathCompareNodeSetFloat()
5814 str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); in xmlXPathCompareNodeSetFloat()
5817 xmlXPathCacheNewString(ctxt->context, str2)); in xmlXPathCompareNodeSetFloat()
5820 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt->context, f)); in xmlXPathCompareNodeSetFloat()
5827 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetFloat()
5828 xmlXPathReleaseObject(ctxt->context, f); in xmlXPathCompareNodeSetFloat()
5846 * If one object to be compared is a node-set and the other is a string,
5848 * the node-set such that the result of performing the comparison on the
5849 * string-value of the node and the other string is true.
5861 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSetString()
5862 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetString()
5863 xmlXPathReleaseObject(ctxt->context, s); in xmlXPathCompareNodeSetString()
5866 ns = arg->nodesetval; in xmlXPathCompareNodeSetString()
5868 for (i = 0;i < ns->nodeNr;i++) { in xmlXPathCompareNodeSetString()
5869 str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); in xmlXPathCompareNodeSetString()
5872 xmlXPathCacheNewString(ctxt->context, str2)); in xmlXPathCompareNodeSetString()
5874 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt->context, s)); in xmlXPathCompareNodeSetString()
5881 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetString()
5882 xmlXPathReleaseObject(ctxt->context, s); in xmlXPathCompareNodeSetString()
5895 * If both objects to be compared are node-sets, then the comparison
5896 * will be true if and only if there is a node in the first node-set
5897 * and a node in the second node-set such that the result of performing
5898 * the comparison on the string-values of the two nodes is true.
5900 * When neither object to be compared is a node-set and the operator
5905 * - a string that consists of optional whitespace followed by an
5908 * to the IEEE 754 round-to-nearest rule) to the mathematical value
5925 ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSets()
5930 ((arg2->type != XPATH_NODESET) && (arg2->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSets()
5936 ns1 = arg1->nodesetval; in xmlXPathCompareNodeSets()
5937 ns2 = arg2->nodesetval; in xmlXPathCompareNodeSets()
5939 if ((ns1 == NULL) || (ns1->nodeNr <= 0)) { in xmlXPathCompareNodeSets()
5944 if ((ns2 == NULL) || (ns2->nodeNr <= 0)) { in xmlXPathCompareNodeSets()
5950 values2 = (double *) xmlMalloc(ns2->nodeNr * sizeof(double)); in xmlXPathCompareNodeSets()
5958 for (i = 0;i < ns1->nodeNr;i++) { in xmlXPathCompareNodeSets()
5959 val1 = xmlXPathCastNodeToNumber(ns1->nodeTab[i]); in xmlXPathCompareNodeSets()
5962 for (j = 0;j < ns2->nodeNr;j++) { in xmlXPathCompareNodeSets()
5964 values2[j] = xmlXPathCastNodeToNumber(ns2->nodeTab[j]); in xmlXPathCompareNodeSets()
6003 * If one object to be compared is a node-set and the other is a boolean,
6006 * the node-set to a boolean using the boolean function is true.
6014 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) in xmlXPathCompareNodeSetValue()
6017 switch(val->type) { in xmlXPathCompareNodeSetValue()
6034 val->type); in xmlXPathCompareNodeSetValue()
6035 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetValue()
6036 xmlXPathReleaseObject(ctxt->context, val); in xmlXPathCompareNodeSetValue()
6049 * If one object to be compared is a node-set and the other is a string,
6051 * the node-set such that the result of performing the comparison on the
6052 * string-value of the node and the other string is true.
6065 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSetString()
6067 ns = arg->nodesetval; in xmlXPathEqualNodeSetString()
6072 if ((ns == NULL) || (ns->nodeNr <= 0) ) in xmlXPathEqualNodeSetString()
6075 for (i = 0; i < ns->nodeNr; i++) { in xmlXPathEqualNodeSetString()
6076 if (xmlXPathNodeValHash(ns->nodeTab[i]) == hash) { in xmlXPathEqualNodeSetString()
6077 str2 = xmlNodeGetContent(ns->nodeTab[i]); in xmlXPathEqualNodeSetString()
6107 * If one object to be compared is a node-set and the other is a number,
6109 * the node-set such that the result of performing the comparison on the
6110 * number to be compared and on the result of converting the string-value
6125 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSetFloat()
6128 ns = arg->nodesetval; in xmlXPathEqualNodeSetFloat()
6130 for (i=0;i<ns->nodeNr;i++) { in xmlXPathEqualNodeSetFloat()
6131 str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); in xmlXPathEqualNodeSetFloat()
6133 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, str2)); in xmlXPathEqualNodeSetFloat()
6138 v = val->floatval; in xmlXPathEqualNodeSetFloat()
6139 xmlXPathReleaseObject(ctxt->context, val); in xmlXPathEqualNodeSetFloat()
6168 * If both objects to be compared are node-sets, then the comparison
6169 * will be true if and only if there is a node in the first node-set and
6170 * a node in the second node-set such that the result of performing the
6171 * comparison on the string-values of the two nodes is true.
6189 ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSets()
6192 ((arg2->type != XPATH_NODESET) && (arg2->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSets()
6195 ns1 = arg1->nodesetval; in xmlXPathEqualNodeSets()
6196 ns2 = arg2->nodesetval; in xmlXPathEqualNodeSets()
6198 if ((ns1 == NULL) || (ns1->nodeNr <= 0)) in xmlXPathEqualNodeSets()
6200 if ((ns2 == NULL) || (ns2->nodeNr <= 0)) in xmlXPathEqualNodeSets()
6207 for (i = 0;i < ns1->nodeNr;i++) in xmlXPathEqualNodeSets()
6208 for (j = 0;j < ns2->nodeNr;j++) in xmlXPathEqualNodeSets()
6209 if (ns1->nodeTab[i] == ns2->nodeTab[j]) in xmlXPathEqualNodeSets()
6212 values1 = (xmlChar **) xmlMalloc(ns1->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
6218 hashs1 = (unsigned int *) xmlMalloc(ns1->nodeNr * sizeof(unsigned int)); in xmlXPathEqualNodeSets()
6225 memset(values1, 0, ns1->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
6226 values2 = (xmlChar **) xmlMalloc(ns2->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
6234 hashs2 = (unsigned int *) xmlMalloc(ns2->nodeNr * sizeof(unsigned int)); in xmlXPathEqualNodeSets()
6243 memset(values2, 0, ns2->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
6244 for (i = 0;i < ns1->nodeNr;i++) { in xmlXPathEqualNodeSets()
6245 hashs1[i] = xmlXPathNodeValHash(ns1->nodeTab[i]); in xmlXPathEqualNodeSets()
6246 for (j = 0;j < ns2->nodeNr;j++) { in xmlXPathEqualNodeSets()
6248 hashs2[j] = xmlXPathNodeValHash(ns2->nodeTab[j]); in xmlXPathEqualNodeSets()
6257 values1[i] = xmlNodeGetContent(ns1->nodeTab[i]); in xmlXPathEqualNodeSets()
6259 values2[j] = xmlNodeGetContent(ns2->nodeTab[j]); in xmlXPathEqualNodeSets()
6268 for (i = 0;i < ns1->nodeNr;i++) in xmlXPathEqualNodeSets()
6271 for (j = 0;j < ns2->nodeNr;j++) in xmlXPathEqualNodeSets()
6289 switch (arg1->type) { in xmlXPathEqualValuesCommon()
6293 switch (arg2->type) { in xmlXPathEqualValuesCommon()
6297 ret = (arg1->boolval == arg2->boolval); in xmlXPathEqualValuesCommon()
6300 ret = (arg1->boolval == in xmlXPathEqualValuesCommon()
6301 xmlXPathCastNumberToBoolean(arg2->floatval)); in xmlXPathEqualValuesCommon()
6304 if ((arg2->stringval == NULL) || in xmlXPathEqualValuesCommon()
6305 (arg2->stringval[0] == 0)) ret = 0; in xmlXPathEqualValuesCommon()
6308 ret = (arg1->boolval == ret); in xmlXPathEqualValuesCommon()
6324 switch (arg2->type) { in xmlXPathEqualValuesCommon()
6328 ret = (arg2->boolval== in xmlXPathEqualValuesCommon()
6329 xmlXPathCastNumberToBoolean(arg1->floatval)); in xmlXPathEqualValuesCommon()
6335 if (ctxt->error) in xmlXPathEqualValuesCommon()
6340 if (xmlXPathIsNaN(arg1->floatval) || in xmlXPathEqualValuesCommon()
6341 xmlXPathIsNaN(arg2->floatval)) { in xmlXPathEqualValuesCommon()
6343 } else if (xmlXPathIsInf(arg1->floatval) == 1) { in xmlXPathEqualValuesCommon()
6344 if (xmlXPathIsInf(arg2->floatval) == 1) in xmlXPathEqualValuesCommon()
6348 } else if (xmlXPathIsInf(arg1->floatval) == -1) { in xmlXPathEqualValuesCommon()
6349 if (xmlXPathIsInf(arg2->floatval) == -1) in xmlXPathEqualValuesCommon()
6353 } else if (xmlXPathIsInf(arg2->floatval) == 1) { in xmlXPathEqualValuesCommon()
6354 if (xmlXPathIsInf(arg1->floatval) == 1) in xmlXPathEqualValuesCommon()
6358 } else if (xmlXPathIsInf(arg2->floatval) == -1) { in xmlXPathEqualValuesCommon()
6359 if (xmlXPathIsInf(arg1->floatval) == -1) in xmlXPathEqualValuesCommon()
6364 ret = (arg1->floatval == arg2->floatval); in xmlXPathEqualValuesCommon()
6381 switch (arg2->type) { in xmlXPathEqualValuesCommon()
6385 if ((arg1->stringval == NULL) || in xmlXPathEqualValuesCommon()
6386 (arg1->stringval[0] == 0)) ret = 0; in xmlXPathEqualValuesCommon()
6389 ret = (arg2->boolval == ret); in xmlXPathEqualValuesCommon()
6392 ret = xmlStrEqual(arg1->stringval, arg2->stringval); in xmlXPathEqualValuesCommon()
6398 if (ctxt->error) in xmlXPathEqualValuesCommon()
6401 if (xmlXPathIsNaN(arg1->floatval) || in xmlXPathEqualValuesCommon()
6402 xmlXPathIsNaN(arg2->floatval)) { in xmlXPathEqualValuesCommon()
6404 } else if (xmlXPathIsInf(arg1->floatval) == 1) { in xmlXPathEqualValuesCommon()
6405 if (xmlXPathIsInf(arg2->floatval) == 1) in xmlXPathEqualValuesCommon()
6409 } else if (xmlXPathIsInf(arg1->floatval) == -1) { in xmlXPathEqualValuesCommon()
6410 if (xmlXPathIsInf(arg2->floatval) == -1) in xmlXPathEqualValuesCommon()
6414 } else if (xmlXPathIsInf(arg2->floatval) == 1) { in xmlXPathEqualValuesCommon()
6415 if (xmlXPathIsInf(arg1->floatval) == 1) in xmlXPathEqualValuesCommon()
6419 } else if (xmlXPathIsInf(arg2->floatval) == -1) { in xmlXPathEqualValuesCommon()
6420 if (xmlXPathIsInf(arg1->floatval) == -1) in xmlXPathEqualValuesCommon()
6425 ret = (arg1->floatval == arg2->floatval); in xmlXPathEqualValuesCommon()
6453 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathEqualValuesCommon()
6454 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathEqualValuesCommon()
6471 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0); in xmlXPathEqualValues()
6476 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathEqualValues()
6478 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathEqualValues()
6490 if ((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE) || in xmlXPathEqualValues()
6491 (arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathEqualValues()
6495 if ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE)) { in xmlXPathEqualValues()
6500 switch (arg2->type) { in xmlXPathEqualValues()
6508 if ((arg1->nodesetval == NULL) || in xmlXPathEqualValues()
6509 (arg1->nodesetval->nodeNr == 0)) ret = 0; in xmlXPathEqualValues()
6512 ret = (ret == arg2->boolval); in xmlXPathEqualValues()
6515 ret = xmlXPathEqualNodeSetFloat(ctxt, arg1, arg2->floatval, 0); in xmlXPathEqualValues()
6518 ret = xmlXPathEqualNodeSetString(arg1, arg2->stringval, 0); in xmlXPathEqualValues()
6529 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathEqualValues()
6530 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathEqualValues()
6550 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0); in xmlXPathNotEqualValues()
6555 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathNotEqualValues()
6557 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathNotEqualValues()
6562 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathNotEqualValues()
6569 if ((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE) || in xmlXPathNotEqualValues()
6570 (arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathNotEqualValues()
6574 if ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE)) { in xmlXPathNotEqualValues()
6579 switch (arg2->type) { in xmlXPathNotEqualValues()
6587 if ((arg1->nodesetval == NULL) || in xmlXPathNotEqualValues()
6588 (arg1->nodesetval->nodeNr == 0)) ret = 0; in xmlXPathNotEqualValues()
6591 ret = (ret != arg2->boolval); in xmlXPathNotEqualValues()
6594 ret = xmlXPathEqualNodeSetFloat(ctxt, arg1, arg2->floatval, 1); in xmlXPathNotEqualValues()
6597 ret = xmlXPathEqualNodeSetString(arg1, arg2->stringval,1); in xmlXPathNotEqualValues()
6608 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathNotEqualValues()
6609 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathNotEqualValues()
6628 * When neither object to be compared is a node-set and the operator is
6645 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0); in xmlXPathCompareValues()
6650 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompareValues()
6652 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompareValues()
6656 if ((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE) || in xmlXPathCompareValues()
6657 (arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathCompareValues()
6663 if (((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE)) && in xmlXPathCompareValues()
6664 ((arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE))){ in xmlXPathCompareValues()
6667 if ((arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathCompareValues()
6678 if (arg1->type != XPATH_NUMBER) { in xmlXPathCompareValues()
6683 if (arg2->type != XPATH_NUMBER) { in xmlXPathCompareValues()
6688 if (ctxt->error) in xmlXPathCompareValues()
6695 if (xmlXPathIsNaN(arg1->floatval) || xmlXPathIsNaN(arg2->floatval)) { in xmlXPathCompareValues()
6698 arg1i=xmlXPathIsInf(arg1->floatval); in xmlXPathCompareValues()
6699 arg2i=xmlXPathIsInf(arg2->floatval); in xmlXPathCompareValues()
6701 if ((arg1i == -1 && arg2i != -1) || in xmlXPathCompareValues()
6705 ret = (arg1->floatval < arg2->floatval); in xmlXPathCompareValues()
6711 if (arg1i == -1 || arg2i == 1) { in xmlXPathCompareValues()
6714 ret = (arg1->floatval <= arg2->floatval); in xmlXPathCompareValues()
6721 (arg2i == -1 && arg1i != -1)) { in xmlXPathCompareValues()
6724 ret = (arg1->floatval > arg2->floatval); in xmlXPathCompareValues()
6730 if (arg1i == 1 || arg2i == -1) { in xmlXPathCompareValues()
6733 ret = (arg1->floatval >= arg2->floatval); in xmlXPathCompareValues()
6740 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompareValues()
6741 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompareValues()
6749 * Implement the unary - operation on an XPath object
6755 if ((ctxt == NULL) || (ctxt->context == NULL)) return; in xmlXPathValueFlipSign()
6758 ctxt->value->floatval = -ctxt->value->floatval; in xmlXPathValueFlipSign()
6778 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathAddValues()
6781 ctxt->value->floatval += val; in xmlXPathAddValues()
6801 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathSubValues()
6804 ctxt->value->floatval -= val; in xmlXPathSubValues()
6824 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathMultValues()
6827 ctxt->value->floatval *= val; in xmlXPathMultValues()
6838 ATTRIBUTE_NO_SANITIZE("float-divide-by-zero")
6848 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathDivValues()
6851 ctxt->value->floatval /= val; in xmlXPathDivValues()
6871 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathModValues()
6874 arg1 = ctxt->value->floatval; in xmlXPathModValues()
6876 ctxt->value->floatval = xmlXPathNAN; in xmlXPathModValues()
6878 ctxt->value->floatval = fmod(arg1, arg2); in xmlXPathModValues()
6926 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextSelf()
6928 return(ctxt->context->node); in xmlXPathNextSelf()
6944 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextChild()
6946 if (ctxt->context->node == NULL) return(NULL); in xmlXPathNextChild()
6947 switch (ctxt->context->node->type) { in xmlXPathNextChild()
6957 return(ctxt->context->node->children); in xmlXPathNextChild()
6962 return(((xmlDocPtr) ctxt->context->node)->children); in xmlXPathNextChild()
6974 if ((cur->type == XML_DOCUMENT_NODE) || in xmlXPathNextChild()
6975 (cur->type == XML_HTML_DOCUMENT_NODE)) in xmlXPathNextChild()
6977 return(cur->next); in xmlXPathNextChild()
6992 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextChildElement()
6994 cur = ctxt->context->node; in xmlXPathNextChildElement()
6999 switch (cur->type) { in xmlXPathNextChildElement()
7002 case XML_ENTITY_REF_NODE: /* URGENT TODO: entify-refs as well? */ in xmlXPathNextChildElement()
7004 cur = cur->children; in xmlXPathNextChildElement()
7006 if (cur->type == XML_ELEMENT_NODE) in xmlXPathNextChildElement()
7009 cur = cur->next; in xmlXPathNextChildElement()
7011 (cur->type != XML_ELEMENT_NODE)); in xmlXPathNextChildElement()
7026 switch (cur->type) { in xmlXPathNextChildElement()
7036 /* case XML_DTD_NODE: */ /* URGENT TODO: DTD-node as well? */ in xmlXPathNextChildElement()
7040 if (cur->next != NULL) { in xmlXPathNextChildElement()
7041 if (cur->next->type == XML_ELEMENT_NODE) in xmlXPathNextChildElement()
7042 return(cur->next); in xmlXPathNextChildElement()
7043 cur = cur->next; in xmlXPathNextChildElement()
7045 cur = cur->next; in xmlXPathNextChildElement()
7046 } while ((cur != NULL) && (cur->type != XML_ELEMENT_NODE)); in xmlXPathNextChildElement()
7058 * Traversal function for the "descendant-or-self" axis.
7072 switch (contextNode->type) {
7087 switch (cur->type) {
7094 if (cur->children != NULL) {
7095 cur = cur->children;
7112 if (cur->next != NULL) {
7113 cur = cur->next;
7115 cur = cur->parent;
7137 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextDescendant()
7139 if (ctxt->context->node == NULL) in xmlXPathNextDescendant()
7141 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextDescendant()
7142 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextDescendant()
7145 if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextDescendant()
7146 return(ctxt->context->doc->children); in xmlXPathNextDescendant()
7147 return(ctxt->context->node->children); in xmlXPathNextDescendant()
7150 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNextDescendant()
7152 if (cur->children != NULL) { in xmlXPathNextDescendant()
7156 if (cur->children->type != XML_ENTITY_DECL) { in xmlXPathNextDescendant()
7157 cur = cur->children; in xmlXPathNextDescendant()
7161 if (cur->type != XML_DTD_NODE) in xmlXPathNextDescendant()
7166 if (cur == ctxt->context->node) return(NULL); in xmlXPathNextDescendant()
7168 while (cur->next != NULL) { in xmlXPathNextDescendant()
7169 cur = cur->next; in xmlXPathNextDescendant()
7170 if ((cur->type != XML_ENTITY_DECL) && in xmlXPathNextDescendant()
7171 (cur->type != XML_DTD_NODE)) in xmlXPathNextDescendant()
7176 cur = cur->parent; in xmlXPathNextDescendant()
7178 if (cur == ctxt->context->node) return(NULL); in xmlXPathNextDescendant()
7179 if (cur->next != NULL) { in xmlXPathNextDescendant()
7180 cur = cur->next; in xmlXPathNextDescendant()
7192 * Traversal function for the "descendant-or-self" direction
7193 * the descendant-or-self axis contains the context node and the descendants
7202 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextDescendantOrSelf()
7204 return(ctxt->context->node); in xmlXPathNextDescendantOrSelf()
7206 if (ctxt->context->node == NULL) in xmlXPathNextDescendantOrSelf()
7208 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextDescendantOrSelf()
7209 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextDescendantOrSelf()
7227 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextParent()
7234 if (ctxt->context->node == NULL) return(NULL); in xmlXPathNextParent()
7235 switch (ctxt->context->node->type) { in xmlXPathNextParent()
7250 if (ctxt->context->node->parent == NULL) in xmlXPathNextParent()
7251 return((xmlNodePtr) ctxt->context->doc); in xmlXPathNextParent()
7252 if ((ctxt->context->node->parent->type == XML_ELEMENT_NODE) && in xmlXPathNextParent()
7253 ((ctxt->context->node->parent->name[0] == ' ') || in xmlXPathNextParent()
7254 (xmlStrEqual(ctxt->context->node->parent->name, in xmlXPathNextParent()
7257 return(ctxt->context->node->parent); in xmlXPathNextParent()
7259 xmlAttrPtr att = (xmlAttrPtr) ctxt->context->node; in xmlXPathNextParent()
7261 return(att->parent); in xmlXPathNextParent()
7269 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node; in xmlXPathNextParent()
7271 if ((ns->next != NULL) && in xmlXPathNextParent()
7272 (ns->next->type != XML_NAMESPACE_DECL)) in xmlXPathNextParent()
7273 return((xmlNodePtr) ns->next); in xmlXPathNextParent()
7297 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextAncestor()
7304 if (ctxt->context->node == NULL) return(NULL); in xmlXPathNextAncestor()
7305 switch (ctxt->context->node->type) { in xmlXPathNextAncestor()
7320 if (ctxt->context->node->parent == NULL) in xmlXPathNextAncestor()
7321 return((xmlNodePtr) ctxt->context->doc); in xmlXPathNextAncestor()
7322 if ((ctxt->context->node->parent->type == XML_ELEMENT_NODE) && in xmlXPathNextAncestor()
7323 ((ctxt->context->node->parent->name[0] == ' ') || in xmlXPathNextAncestor()
7324 (xmlStrEqual(ctxt->context->node->parent->name, in xmlXPathNextAncestor()
7327 return(ctxt->context->node->parent); in xmlXPathNextAncestor()
7329 xmlAttrPtr tmp = (xmlAttrPtr) ctxt->context->node; in xmlXPathNextAncestor()
7331 return(tmp->parent); in xmlXPathNextAncestor()
7339 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node; in xmlXPathNextAncestor()
7341 if ((ns->next != NULL) && in xmlXPathNextAncestor()
7342 (ns->next->type != XML_NAMESPACE_DECL)) in xmlXPathNextAncestor()
7343 return((xmlNodePtr) ns->next); in xmlXPathNextAncestor()
7350 if (cur == ctxt->context->doc->children) in xmlXPathNextAncestor()
7351 return((xmlNodePtr) ctxt->context->doc); in xmlXPathNextAncestor()
7352 if (cur == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextAncestor()
7354 switch (cur->type) { in xmlXPathNextAncestor()
7369 if (cur->parent == NULL) in xmlXPathNextAncestor()
7371 if ((cur->parent->type == XML_ELEMENT_NODE) && in xmlXPathNextAncestor()
7372 ((cur->parent->name[0] == ' ') || in xmlXPathNextAncestor()
7373 (xmlStrEqual(cur->parent->name, in xmlXPathNextAncestor()
7376 return(cur->parent); in xmlXPathNextAncestor()
7380 return(att->parent); in xmlXPathNextAncestor()
7385 if ((ns->next != NULL) && in xmlXPathNextAncestor()
7386 (ns->next->type != XML_NAMESPACE_DECL)) in xmlXPathNextAncestor()
7387 return((xmlNodePtr) ns->next); in xmlXPathNextAncestor()
7405 * Traversal function for the "ancestor-or-self" direction
7406 * he ancestor-or-self axis contains the context node and ancestors of
7415 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextAncestorOrSelf()
7417 return(ctxt->context->node); in xmlXPathNextAncestorOrSelf()
7426 * Traversal function for the "following-sibling" direction
7427 * The following-sibling axis contains the following siblings of the context
7434 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextFollowingSibling()
7435 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextFollowingSibling()
7436 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextFollowingSibling()
7438 if (cur == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextFollowingSibling()
7441 return(ctxt->context->node->next); in xmlXPathNextFollowingSibling()
7442 return(cur->next); in xmlXPathNextFollowingSibling()
7450 * Traversal function for the "preceding-sibling" direction
7451 * The preceding-sibling axis contains the preceding siblings of the context
7459 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextPrecedingSibling()
7460 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextPrecedingSibling()
7461 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextPrecedingSibling()
7463 if (cur == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextPrecedingSibling()
7466 return(ctxt->context->node->prev); in xmlXPathNextPrecedingSibling()
7467 if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) { in xmlXPathNextPrecedingSibling()
7468 cur = cur->prev; in xmlXPathNextPrecedingSibling()
7470 return(ctxt->context->node->prev); in xmlXPathNextPrecedingSibling()
7472 return(cur->prev); in xmlXPathNextPrecedingSibling()
7490 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextFollowing()
7491 if ((cur != NULL) && (cur->type != XML_ATTRIBUTE_NODE) && in xmlXPathNextFollowing()
7492 (cur->type != XML_NAMESPACE_DECL) && (cur->children != NULL)) in xmlXPathNextFollowing()
7493 return(cur->children); in xmlXPathNextFollowing()
7496 cur = ctxt->context->node; in xmlXPathNextFollowing()
7497 if (cur->type == XML_ATTRIBUTE_NODE) { in xmlXPathNextFollowing()
7498 cur = cur->parent; in xmlXPathNextFollowing()
7499 } else if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNextFollowing()
7502 if ((ns->next == NULL) || in xmlXPathNextFollowing()
7503 (ns->next->type == XML_NAMESPACE_DECL)) in xmlXPathNextFollowing()
7505 cur = (xmlNodePtr) ns->next; in xmlXPathNextFollowing()
7509 if (cur->next != NULL) return(cur->next) ; in xmlXPathNextFollowing()
7511 cur = cur->parent; in xmlXPathNextFollowing()
7513 if (cur == (xmlNodePtr) ctxt->context->doc) return(NULL); in xmlXPathNextFollowing()
7514 if (cur->next != NULL) return(cur->next); in xmlXPathNextFollowing()
7531 if (node->type == XML_NAMESPACE_DECL) in xmlXPathIsAncestor()
7533 if (ancestor->type == XML_NAMESPACE_DECL) in xmlXPathIsAncestor()
7536 if (ancestor->doc != node->doc) return(0); in xmlXPathIsAncestor()
7538 if (ancestor == (xmlNodePtr) node->doc) return(1); in xmlXPathIsAncestor()
7539 if (node == (xmlNodePtr) ancestor->doc) return(0); in xmlXPathIsAncestor()
7540 while (node->parent != NULL) { in xmlXPathIsAncestor()
7541 if (node->parent == ancestor) in xmlXPathIsAncestor()
7543 node = node->parent; in xmlXPathIsAncestor()
7564 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextPreceding()
7566 cur = ctxt->context->node; in xmlXPathNextPreceding()
7567 if (cur->type == XML_ATTRIBUTE_NODE) { in xmlXPathNextPreceding()
7568 cur = cur->parent; in xmlXPathNextPreceding()
7569 } else if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNextPreceding()
7572 if ((ns->next == NULL) || in xmlXPathNextPreceding()
7573 (ns->next->type == XML_NAMESPACE_DECL)) in xmlXPathNextPreceding()
7575 cur = (xmlNodePtr) ns->next; in xmlXPathNextPreceding()
7578 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) in xmlXPathNextPreceding()
7580 if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) in xmlXPathNextPreceding()
7581 cur = cur->prev; in xmlXPathNextPreceding()
7583 if (cur->prev != NULL) { in xmlXPathNextPreceding()
7584 for (cur = cur->prev; cur->last != NULL; cur = cur->last) ; in xmlXPathNextPreceding()
7588 cur = cur->parent; in xmlXPathNextPreceding()
7591 if (cur == ctxt->context->doc->children) in xmlXPathNextPreceding()
7593 } while (xmlXPathIsAncestor(cur, ctxt->context->node)); in xmlXPathNextPreceding()
7608 * state kept in the parser context: ctxt->ancestor.
7616 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextPrecedingInternal()
7618 cur = ctxt->context->node; in xmlXPathNextPrecedingInternal()
7621 if (cur->type == XML_ATTRIBUTE_NODE) { in xmlXPathNextPrecedingInternal()
7622 cur = cur->parent; in xmlXPathNextPrecedingInternal()
7623 } else if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNextPrecedingInternal()
7626 if ((ns->next == NULL) || in xmlXPathNextPrecedingInternal()
7627 (ns->next->type == XML_NAMESPACE_DECL)) in xmlXPathNextPrecedingInternal()
7629 cur = (xmlNodePtr) ns->next; in xmlXPathNextPrecedingInternal()
7631 ctxt->ancestor = cur->parent; in xmlXPathNextPrecedingInternal()
7633 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNextPrecedingInternal()
7635 if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) in xmlXPathNextPrecedingInternal()
7636 cur = cur->prev; in xmlXPathNextPrecedingInternal()
7637 while (cur->prev == NULL) { in xmlXPathNextPrecedingInternal()
7638 cur = cur->parent; in xmlXPathNextPrecedingInternal()
7641 if (cur == ctxt->context->doc->children) in xmlXPathNextPrecedingInternal()
7643 if (cur != ctxt->ancestor) in xmlXPathNextPrecedingInternal()
7645 ctxt->ancestor = cur->parent; in xmlXPathNextPrecedingInternal()
7647 cur = cur->prev; in xmlXPathNextPrecedingInternal()
7648 while (cur->last != NULL) in xmlXPathNextPrecedingInternal()
7649 cur = cur->last; in xmlXPathNextPrecedingInternal()
7660 * the order of nodes on this axis is implementation-defined; the axis will
7669 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextNamespace()
7670 if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL); in xmlXPathNextNamespace()
7672 if (ctxt->context->tmpNsList != NULL) in xmlXPathNextNamespace()
7673 xmlFree(ctxt->context->tmpNsList); in xmlXPathNextNamespace()
7674 ctxt->context->tmpNsList = in xmlXPathNextNamespace()
7675 xmlGetNsList(ctxt->context->doc, ctxt->context->node); in xmlXPathNextNamespace()
7676 ctxt->context->tmpNsNr = 0; in xmlXPathNextNamespace()
7677 if (ctxt->context->tmpNsList != NULL) { in xmlXPathNextNamespace()
7678 while (ctxt->context->tmpNsList[ctxt->context->tmpNsNr] != NULL) { in xmlXPathNextNamespace()
7679 ctxt->context->tmpNsNr++; in xmlXPathNextNamespace()
7684 if (ctxt->context->tmpNsNr > 0) { in xmlXPathNextNamespace()
7685 return (xmlNodePtr)ctxt->context->tmpNsList[--ctxt->context->tmpNsNr]; in xmlXPathNextNamespace()
7687 if (ctxt->context->tmpNsList != NULL) in xmlXPathNextNamespace()
7688 xmlFree(ctxt->context->tmpNsList); in xmlXPathNextNamespace()
7689 ctxt->context->tmpNsList = NULL; in xmlXPathNextNamespace()
7706 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextAttribute()
7707 if (ctxt->context->node == NULL) in xmlXPathNextAttribute()
7709 if (ctxt->context->node->type != XML_ELEMENT_NODE) in xmlXPathNextAttribute()
7712 if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextAttribute()
7714 return((xmlNodePtr)ctxt->context->node->properties); in xmlXPathNextAttribute()
7716 return((xmlNodePtr)cur->next); in xmlXPathNextAttribute()
7742 if ((ctxt == NULL) || (ctxt->context == NULL)) in xmlXPathRoot()
7744 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathRoot()
7745 (xmlNodePtr) ctxt->context->doc)); in xmlXPathRoot()
7751 *http://www.w3.org/Style/XSL/Group/1999/07/xpath-19990705.html#corelib *
7768 if (ctxt->context->contextSize >= 0) { in xmlXPathLastFunction()
7770 xmlXPathCacheNewFloat(ctxt->context, in xmlXPathLastFunction()
7771 (double) ctxt->context->contextSize)); in xmlXPathLastFunction()
7791 if (ctxt->context->proximityPosition >= 0) { in xmlXPathPositionFunction()
7793 xmlXPathCacheNewFloat(ctxt->context, in xmlXPathPositionFunction()
7794 (double) ctxt->context->proximityPosition)); in xmlXPathPositionFunction()
7806 * number count(node-set)
7813 if ((ctxt->value == NULL) || in xmlXPathCountFunction()
7814 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathCountFunction()
7815 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathCountFunction()
7819 if ((cur == NULL) || (cur->nodesetval == NULL)) in xmlXPathCountFunction()
7820 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, (double) 0)); in xmlXPathCountFunction()
7822 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, in xmlXPathCountFunction()
7823 (double) cur->nodesetval->nodeNr)); in xmlXPathCountFunction()
7824 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathCountFunction()
7834 * Returns a node-set of selected elements.
7855 ID = xmlStrndup(ids, cur - ids); in xmlXPathGetElementsByIds()
7866 if (attr->type == XML_ATTRIBUTE_NODE) in xmlXPathGetElementsByIds()
7867 elem = attr->parent; in xmlXPathGetElementsByIds()
7868 else if (attr->type == XML_ELEMENT_NODE) in xmlXPathGetElementsByIds()
7891 * node-set id(object)
7893 * (see [5.2.1 Unique IDs]). When the argument to id is of type node-set,
7895 * string value of each of the nodes in the argument node-set. When the
7898 * into a whitespace-separated list of tokens (whitespace is any sequence
7899 * of characters matching the production S); the result is a node-set
7912 if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) { in xmlXPathIdFunction()
7919 if (obj->nodesetval != NULL) { in xmlXPathIdFunction()
7920 for (i = 0; i < obj->nodesetval->nodeNr; i++) { in xmlXPathIdFunction()
7922 xmlXPathCastNodeToString(obj->nodesetval->nodeTab[i]); in xmlXPathIdFunction()
7923 ns = xmlXPathGetElementsByIds(ctxt->context->doc, tokens); in xmlXPathIdFunction()
7931 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathIdFunction()
7932 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt->context, ret)); in xmlXPathIdFunction()
7935 obj = xmlXPathCacheConvertString(ctxt->context, obj); in xmlXPathIdFunction()
7937 ret = xmlXPathGetElementsByIds(ctxt->context->doc, obj->stringval); in xmlXPathIdFunction()
7938 valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt->context, ret)); in xmlXPathIdFunction()
7939 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathIdFunction()
7948 * Implement the local-name() XPath function
7949 * string local-name(node-set?)
7950 * The local-name function returns a string containing the local part
7951 * of the name of the node in the argument node-set that is first in
7952 * document order. If the node-set is empty or the first node has no
7963 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathLocalNameFunction()
7964 ctxt->context->node)); in xmlXPathLocalNameFunction()
7969 if ((ctxt->value == NULL) || in xmlXPathLocalNameFunction()
7970 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathLocalNameFunction()
7971 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathLocalNameFunction()
7975 if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { in xmlXPathLocalNameFunction()
7976 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathLocalNameFunction()
7979 switch (cur->nodesetval->nodeTab[i]->type) { in xmlXPathLocalNameFunction()
7983 if (cur->nodesetval->nodeTab[i]->name[0] == ' ') in xmlXPathLocalNameFunction()
7984 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathLocalNameFunction()
7987 xmlXPathCacheNewString(ctxt->context, in xmlXPathLocalNameFunction()
7988 cur->nodesetval->nodeTab[i]->name)); in xmlXPathLocalNameFunction()
7991 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, in xmlXPathLocalNameFunction()
7992 ((xmlNsPtr)cur->nodesetval->nodeTab[i])->prefix)); in xmlXPathLocalNameFunction()
7995 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathLocalNameFunction()
7998 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathLocalNameFunction()
8006 * Implement the namespace-uri() XPath function
8007 * string namespace-uri(node-set?)
8008 * The namespace-uri function returns a string containing the
8010 * node-set that is first in document order. If the node-set is empty,
8022 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathNamespaceURIFunction()
8023 ctxt->context->node)); in xmlXPathNamespaceURIFunction()
8027 if ((ctxt->value == NULL) || in xmlXPathNamespaceURIFunction()
8028 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathNamespaceURIFunction()
8029 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathNamespaceURIFunction()
8033 if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { in xmlXPathNamespaceURIFunction()
8034 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathNamespaceURIFunction()
8037 switch (cur->nodesetval->nodeTab[i]->type) { in xmlXPathNamespaceURIFunction()
8040 if (cur->nodesetval->nodeTab[i]->ns == NULL) in xmlXPathNamespaceURIFunction()
8041 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathNamespaceURIFunction()
8043 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, in xmlXPathNamespaceURIFunction()
8044 cur->nodesetval->nodeTab[i]->ns->href)); in xmlXPathNamespaceURIFunction()
8047 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathNamespaceURIFunction()
8050 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathNamespaceURIFunction()
8059 * string name(node-set?)
8061 * the name of the node in the argument node-set that is first in document
8081 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathNameFunction()
8082 ctxt->context->node)); in xmlXPathNameFunction()
8087 if ((ctxt->value == NULL) || in xmlXPathNameFunction()
8088 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathNameFunction()
8089 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathNameFunction()
8093 if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { in xmlXPathNameFunction()
8094 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathNameFunction()
8098 switch (cur->nodesetval->nodeTab[i]->type) { in xmlXPathNameFunction()
8101 if (cur->nodesetval->nodeTab[i]->name[0] == ' ') in xmlXPathNameFunction()
8103 xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathNameFunction()
8104 else if ((cur->nodesetval->nodeTab[i]->ns == NULL) || in xmlXPathNameFunction()
8105 (cur->nodesetval->nodeTab[i]->ns->prefix == NULL)) { in xmlXPathNameFunction()
8107 xmlXPathCacheNewString(ctxt->context, in xmlXPathNameFunction()
8108 cur->nodesetval->nodeTab[i]->name)); in xmlXPathNameFunction()
8112 fullname = xmlBuildQName(cur->nodesetval->nodeTab[i]->name, in xmlXPathNameFunction()
8113 cur->nodesetval->nodeTab[i]->ns->prefix, in xmlXPathNameFunction()
8115 if (fullname == cur->nodesetval->nodeTab[i]->name) in xmlXPathNameFunction()
8116 fullname = xmlStrdup(cur->nodesetval->nodeTab[i]->name); in xmlXPathNameFunction()
8120 ctxt->context, fullname)); in xmlXPathNameFunction()
8124 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathNameFunction()
8125 cur->nodesetval->nodeTab[i])); in xmlXPathNameFunction()
8129 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathNameFunction()
8141 * - A node-set is converted to a string by returning the value of
8142 * the node in the node-set that is first in document order.
8143 * If the node-set is empty, an empty string is returned.
8144 * - A number is converted to a string as follows
8149 * + negative infinity is converted to the string -Infinity
8152 * zeros, preceded by a minus sign (-) if the number is negative
8156 * decimal point, preceded by a minus sign (-) if the number
8163 * - The boolean false value is converted to the string false.
8166 * If the argument is omitted, it defaults to a node-set with the
8176 xmlXPathCacheWrapString(ctxt->context, in xmlXPathStringFunction()
8177 xmlXPathCastNodeToString(ctxt->context->node))); in xmlXPathStringFunction()
8184 valuePush(ctxt, xmlXPathCacheConvertString(ctxt->context, cur)); in xmlXPathStringFunction()
8192 * Implement the string-length() XPath function
8193 * number string-length(string?)
8194 * The string-length returns the number of characters in the string
8204 if ((ctxt == NULL) || (ctxt->context == NULL)) in xmlXPathStringLengthFunction()
8206 if (ctxt->context->node == NULL) { in xmlXPathStringLengthFunction()
8207 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, 0)); in xmlXPathStringLengthFunction()
8211 content = xmlXPathCastNodeToString(ctxt->context->node); in xmlXPathStringLengthFunction()
8212 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, in xmlXPathStringLengthFunction()
8222 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, in xmlXPathStringLengthFunction()
8223 xmlUTF8Strlen(cur->stringval))); in xmlXPathStringLengthFunction()
8224 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathStringLengthFunction()
8248 if ((cur == NULL) || (cur->type != XPATH_STRING)) { in xmlXPathConcatFunction()
8249 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathConcatFunction()
8252 nargs--; in xmlXPathConcatFunction()
8257 if ((newobj == NULL) || (newobj->type != XPATH_STRING)) { in xmlXPathConcatFunction()
8258 xmlXPathReleaseObject(ctxt->context, newobj); in xmlXPathConcatFunction()
8259 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathConcatFunction()
8262 tmp = xmlStrcat(newobj->stringval, cur->stringval); in xmlXPathConcatFunction()
8263 newobj->stringval = cur->stringval; in xmlXPathConcatFunction()
8264 cur->stringval = tmp; in xmlXPathConcatFunction()
8265 xmlXPathReleaseObject(ctxt->context, newobj); in xmlXPathConcatFunction()
8266 nargs--; in xmlXPathConcatFunction()
8292 if ((hay == NULL) || (hay->type != XPATH_STRING)) { in xmlXPathContainsFunction()
8293 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathContainsFunction()
8294 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathContainsFunction()
8297 if (xmlStrstr(hay->stringval, needle->stringval)) in xmlXPathContainsFunction()
8298 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 1)); in xmlXPathContainsFunction()
8300 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0)); in xmlXPathContainsFunction()
8301 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathContainsFunction()
8302 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathContainsFunction()
8310 * Implement the starts-with() XPath function
8311 * boolean starts-with(string, string)
8312 * The starts-with function returns true if the first argument string
8327 if ((hay == NULL) || (hay->type != XPATH_STRING)) { in xmlXPathStartsWithFunction()
8328 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathStartsWithFunction()
8329 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathStartsWithFunction()
8332 n = xmlStrlen(needle->stringval); in xmlXPathStartsWithFunction()
8333 if (xmlStrncmp(hay->stringval, needle->stringval, n)) in xmlXPathStartsWithFunction()
8334 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0)); in xmlXPathStartsWithFunction()
8336 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 1)); in xmlXPathStartsWithFunction()
8337 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathStartsWithFunction()
8338 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathStartsWithFunction()
8362 * - substring("12345", 1.5, 2.6) returns "234"
8363 * - substring("12345", 0, 3) returns "12"
8364 * - substring("12345", 0 div 0, 3) returns ""
8365 * - substring("12345", 1, 0 div 0) returns ""
8366 * - substring("12345", -42, 1 div 0) returns "12345"
8367 * - substring("12345", -1 div 0, 1 div 0) returns ""
8388 le = len->floatval; in xmlXPathSubstringFunction()
8389 xmlXPathReleaseObject(ctxt->context, len); in xmlXPathSubstringFunction()
8395 in = start->floatval; in xmlXPathSubstringFunction()
8396 xmlXPathReleaseObject(ctxt->context, start); in xmlXPathSubstringFunction()
8405 if (in - floor(in) >= 0.5) in xmlXPathSubstringFunction()
8413 if (in - rin >= 0.5) in xmlXPathSubstringFunction()
8417 if (le - rle >= 0.5) in xmlXPathSubstringFunction()
8429 xmlChar *ret = xmlUTF8Strsub(str->stringval, i - 1, j - i); in xmlXPathSubstringFunction()
8430 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, ret)); in xmlXPathSubstringFunction()
8433 valuePush(ctxt, xmlXPathCacheNewCString(ctxt->context, "")); in xmlXPathSubstringFunction()
8436 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathSubstringFunction()
8444 * Implement the substring-before() XPath function
8445 * string substring-before(string, string)
8446 * The substring-before function returns the substring of the first
8450 * string. For example, substring-before("1999/04/01","/") returns 1999.
8468 point = xmlStrstr(str->stringval, find->stringval); in xmlXPathSubstringBeforeFunction()
8470 offset = point - str->stringval; in xmlXPathSubstringBeforeFunction()
8471 xmlBufAdd(target, str->stringval, offset); in xmlXPathSubstringBeforeFunction()
8473 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, in xmlXPathSubstringBeforeFunction()
8477 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathSubstringBeforeFunction()
8478 xmlXPathReleaseObject(ctxt->context, find); in xmlXPathSubstringBeforeFunction()
8486 * Implement the substring-after() XPath function
8487 * string substring-after(string, string)
8488 * The substring-after function returns the substring of the first
8492 * string. For example, substring-after("1999/04/01","/") returns 04/01,
8493 * and substring-after("1999/04/01","19") returns 99/04/01.
8511 point = xmlStrstr(str->stringval, find->stringval); in xmlXPathSubstringAfterFunction()
8513 offset = point - str->stringval + xmlStrlen(find->stringval); in xmlXPathSubstringAfterFunction()
8514 xmlBufAdd(target, &str->stringval[offset], in xmlXPathSubstringAfterFunction()
8515 xmlStrlen(str->stringval) - offset); in xmlXPathSubstringAfterFunction()
8517 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, in xmlXPathSubstringAfterFunction()
8521 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathSubstringAfterFunction()
8522 xmlXPathReleaseObject(ctxt->context, find); in xmlXPathSubstringAfterFunction()
8530 * Implement the normalize-space() XPath function
8531 * string normalize-space(string?)
8532 * The normalize-space function returns the argument string with white
8548 xmlXPathCacheWrapString(ctxt->context, in xmlXPathNormalizeFunction()
8549 xmlXPathCastNodeToString(ctxt->context->node))); in xmlXPathNormalizeFunction()
8556 source = ctxt->value->stringval; in xmlXPathNormalizeFunction()
8597 * string are removed. For example, translate("--aaa--","abc-","ABC")
8625 max = xmlUTF8Strlen(to->stringval); in xmlXPathTranslateFunction()
8626 for (cptr = str->stringval; (ch=*cptr); ) { in xmlXPathTranslateFunction()
8627 offset = xmlUTF8Strloc(from->stringval, cptr); in xmlXPathTranslateFunction()
8630 point = xmlUTF8Strpos(to->stringval, offset); in xmlXPathTranslateFunction()
8660 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, in xmlXPathTranslateFunction()
8663 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathTranslateFunction()
8664 xmlXPathReleaseObject(ctxt->context, from); in xmlXPathTranslateFunction()
8665 xmlXPathReleaseObject(ctxt->context, to); in xmlXPathTranslateFunction()
8676 * - a number is true if and only if it is neither positive or
8678 * - a node-set is true if and only if it is non-empty
8679 * - a string is true if and only if its length is non-zero
8688 cur = xmlXPathCacheConvertBoolean(ctxt->context, cur); in xmlXPathBooleanFunction()
8707 ctxt->value->boolval = ! ctxt->value->boolval; in xmlXPathNotFunction()
8721 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 1)); in xmlXPathTrueFunction()
8735 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0)); in xmlXPathFalseFunction()
8755 * or if there is some suffix starting with - such that the attribute
8771 lang = val->stringval; in xmlXPathLangFunction()
8772 theLang = xmlNodeGetLang(ctxt->context->node); in xmlXPathLangFunction()
8777 if ((theLang[i] == 0) || (theLang[i] == '-')) in xmlXPathLangFunction()
8784 xmlXPathReleaseObject(ctxt->context, val); in xmlXPathLangFunction()
8785 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, ret)); in xmlXPathLangFunction()
8803 if (ctxt->context->node == NULL) { in xmlXPathNumberFunction()
8804 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, 0.0)); in xmlXPathNumberFunction()
8806 xmlChar* content = xmlNodeGetContent(ctxt->context->node); in xmlXPathNumberFunction()
8809 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, res)); in xmlXPathNumberFunction()
8817 valuePush(ctxt, xmlXPathCacheConvertNumber(ctxt->context, cur)); in xmlXPathNumberFunction()
8826 * number sum(node-set)
8828 * the argument node-set.
8837 if ((ctxt->value == NULL) || in xmlXPathSumFunction()
8838 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathSumFunction()
8839 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathSumFunction()
8843 if ((cur->nodesetval != NULL) && (cur->nodesetval->nodeNr != 0)) { in xmlXPathSumFunction()
8844 for (i = 0; i < cur->nodesetval->nodeNr; i++) { in xmlXPathSumFunction()
8845 res += xmlXPathCastNodeToNumber(cur->nodesetval->nodeTab[i]); in xmlXPathSumFunction()
8848 valuePush(ctxt, xmlXPathCacheNewFloat(ctxt->context, res)); in xmlXPathSumFunction()
8849 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathSumFunction()
8868 ctxt->value->floatval = floor(ctxt->value->floatval); in xmlXPathFloorFunction()
8889 ctxt->value->floatval = copysign(ceil(ctxt->value->floatval), ctxt->value->floatval); in xmlXPathCeilingFunction()
8891 ctxt->value->floatval = ceil(ctxt->value->floatval); in xmlXPathCeilingFunction()
8914 f = ctxt->value->floatval; in xmlXPathRoundFunction()
8916 if ((f >= -0.5) && (f < 0.5)) { in xmlXPathRoundFunction()
8918 ctxt->value->floatval *= 0.0; in xmlXPathRoundFunction()
8922 if (f - rounded >= 0.5) in xmlXPathRoundFunction()
8924 ctxt->value->floatval = rounded; in xmlXPathRoundFunction()
8951 * The current char value, if using UTF-8 this may actually span multiple
8965 cur = ctxt->cur; in xmlXPathCurrentChar()
8969 * From rfc2044: encoding of the Unicode values on UTF-8: in xmlXPathCurrentChar()
8971 * UCS-4 range (hex.) UTF-8 octet sequence (binary) in xmlXPathCurrentChar()
8972 * 0000 0000-0000 007F 0xxxxxxx in xmlXPathCurrentChar()
8973 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx in xmlXPathCurrentChar()
8974 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx in xmlXPathCurrentChar()
8990 /* 4-byte code */ in xmlXPathCurrentChar()
8997 /* 3-byte code */ in xmlXPathCurrentChar()
9004 /* 2-byte code */ in xmlXPathCurrentChar()
9014 /* 1-byte code */ in xmlXPathCurrentChar()
9023 * to ISO-Latin-1 (if you don't like this policy, just declare the in xmlXPathCurrentChar()
9038 * [NS 4] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
9050 if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL); in xmlXPathParseNCName()
9054 in = ctxt->cur; in xmlXPathParseNCName()
9063 (*in == '-')) in xmlXPathParseNCName()
9068 count = in - ctxt->cur; in xmlXPathParseNCName()
9071 ret = xmlStrndup(ctxt->cur, count); in xmlXPathParseNCName()
9072 ctxt->cur = in; in xmlXPathParseNCName()
9117 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
9131 if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL); in xmlXPathParseName()
9135 in = ctxt->cur; in xmlXPathParseName()
9143 (*in == '_') || (*in == '-') || in xmlXPathParseName()
9147 count = in - ctxt->cur; in xmlXPathParseName()
9149 ctxt->cur = in; in xmlXPathParseName()
9152 ret = xmlStrndup(ctxt->cur, count); in xmlXPathParseName()
9153 ctxt->cur = in; in xmlXPathParseName()
9180 (c == '.') || (c == '-') || in xmlXPathParseNameComplex()
9204 (c == '.') || (c == '-') || in xmlXPathParseNameComplex()
9245 * [31] Digits ::= [0-9]+
9249 * negative values : '-' Number.
9267 if (*cur == '-') { in xmlXPathStringEvalNumber()
9283 tmp = (*cur - '0'); in xmlXPathStringEvalNumber()
9292 ret = ret * 10 + (*cur - '0'); in xmlXPathStringEvalNumber()
9312 v = (*cur - '0'); in xmlXPathStringEvalNumber()
9324 if (*cur == '-') { in xmlXPathStringEvalNumber()
9332 exponent = exponent * 10 + (*cur - '0'); in xmlXPathStringEvalNumber()
9338 if (isneg) ret = -ret; in xmlXPathStringEvalNumber()
9339 if (is_exponent_negative) exponent = -exponent; in xmlXPathStringEvalNumber()
9350 * [31] Digits ::= [0-9]+
9380 tmp = (CUR - '0'); in xmlXPathCompNumber()
9389 ret = ret * 10 + (CUR - '0'); in xmlXPathCompNumber()
9408 v = (CUR - '0'); in xmlXPathCompNumber()
9420 if (CUR == '-') { in xmlXPathCompNumber()
9428 exponent = exponent * 10 + (CUR - '0'); in xmlXPathCompNumber()
9432 exponent = -exponent; in xmlXPathCompNumber()
9435 num = xmlXPathCacheNewFloat(ctxt->context, ret); in xmlXPathCompNumber()
9437 ctxt->error = XPATH_MEMORY_ERROR; in xmlXPathCompNumber()
9439 NULL) == -1) { in xmlXPathCompNumber()
9440 xmlXPathReleaseObject(ctxt->context, num); in xmlXPathCompNumber()
9468 ret = xmlStrndup(q, CUR_PTR - q); in xmlXPathParseLiteral()
9479 ret = xmlStrndup(q, CUR_PTR - q); in xmlXPathParseLiteral()
9513 ret = xmlStrndup(q, CUR_PTR - q); in xmlXPathCompLiteral()
9524 ret = xmlStrndup(q, CUR_PTR - q); in xmlXPathCompLiteral()
9534 lit = xmlXPathCacheNewString(ctxt->context, ret); in xmlXPathCompLiteral()
9536 ctxt->error = XPATH_MEMORY_ERROR; in xmlXPathCompLiteral()
9538 NULL) == -1) { in xmlXPathCompLiteral()
9539 xmlXPathReleaseObject(ctxt->context, lit); in xmlXPathCompLiteral()
9576 ctxt->comp->last = -1; in xmlXPathCompVariableReference()
9577 if (PUSH_LONG_EXPR(XPATH_OP_VARIABLE, 0, 0, 0, name, prefix) == -1) { in xmlXPathCompVariableReference()
9582 if ((ctxt->context != NULL) && (ctxt->context->flags & XML_XPATH_NOVAR)) { in xmlXPathCompVariableReference()
9595 * | 'processing-instruction'
9611 if (xmlStrEqual(name, BAD_CAST "processing-instruction")) in xmlXPathIsNodeType()
9649 * Optimization for count(): we don't need the node-set to be sorted. in xmlXPathCompFunctionCall()
9656 ctxt->comp->last = -1; in xmlXPathCompFunctionCall()
9659 int op1 = ctxt->comp->last; in xmlXPathCompFunctionCall()
9660 ctxt->comp->last = -1; in xmlXPathCompFunctionCall()
9662 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompFunctionCall()
9667 PUSH_BINARY_EXPR(XPATH_OP_ARG, op1, ctxt->comp->last, 0, 0); in xmlXPathCompFunctionCall()
9679 if (PUSH_LONG_EXPR(XPATH_OP_FUNCTION, nbargs, 0, 0, name, prefix) == -1) { in xmlXPathCompFunctionCall()
9733 * be filtered does not evaluate to a node-set. The context node list
9734 * used for evaluating the expression in square brackets is the node-set
9759 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
9776 cur = ctxt->cur; in xmlXPathScanName()
9787 (c == '.') || (c == '-') || in xmlXPathScanName()
9794 ret = xmlStrndup(cur, ctxt->cur - cur); in xmlXPathScanName()
9795 ctxt->cur = cur; in xmlXPathScanName()
9811 * does not evaluate to a node-set.
9814 * /descendant-or-self::node()/.
9843 * - a nodetype in xmlXPathCompPathExpr()
9844 * - a function call in which case it's followed by '(' in xmlXPathCompPathExpr()
9845 * - an axis in which case it's followed by ':' in xmlXPathCompPathExpr()
9846 * - a element name in xmlXPathCompPathExpr()
9877 } else if (ctxt->xptr && in xmlXPathCompPathExpr()
9878 xmlStrEqual(name, BAD_CAST "range-to")) { in xmlXPathCompPathExpr()
9951 int op1 = ctxt->comp->last; in xmlXPathCompUnionExpr()
9958 PUSH_BINARY_EXPR(XPATH_OP_UNION, op1, ctxt->comp->last, 0, 0); in xmlXPathCompUnionExpr()
9969 * | '-' UnaryExpr
9980 while (CUR == '-') { in xmlXPathCompUnaryExpr()
9981 minus = 1 - minus; in xmlXPathCompUnaryExpr()
9991 PUSH_UNARY_EXPR(XPATH_OP_PLUS, ctxt->comp->last, 2, 0); in xmlXPathCompUnaryExpr()
9993 PUSH_UNARY_EXPR(XPATH_OP_PLUS, ctxt->comp->last, 3, 0); in xmlXPathCompUnaryExpr()
10018 int op = -1; in xmlXPathCompMultiplicativeExpr()
10019 int op1 = ctxt->comp->last; in xmlXPathCompMultiplicativeExpr()
10034 PUSH_BINARY_EXPR(XPATH_OP_MULT, op1, ctxt->comp->last, op, 0); in xmlXPathCompMultiplicativeExpr()
10045 * | AdditiveExpr '-' MultiplicativeExpr
10056 while ((CUR == '+') || (CUR == '-')) { in xmlXPathCompAdditiveExpr()
10058 int op1 = ctxt->comp->last; in xmlXPathCompAdditiveExpr()
10066 PUSH_BINARY_EXPR(XPATH_OP_PLUS, op1, ctxt->comp->last, plus, 0); in xmlXPathCompAdditiveExpr()
10096 int op1 = ctxt->comp->last; in xmlXPathCompRelationalExpr()
10107 PUSH_BINARY_EXPR(XPATH_OP_CMP, op1, ctxt->comp->last, inf, strict); in xmlXPathCompRelationalExpr()
10135 int op1 = ctxt->comp->last; in xmlXPathCompEqualityExpr()
10144 PUSH_BINARY_EXPR(XPATH_OP_EQUAL, op1, ctxt->comp->last, eq, 0); in xmlXPathCompEqualityExpr()
10165 int op1 = ctxt->comp->last; in xmlXPathCompAndExpr()
10170 PUSH_BINARY_EXPR(XPATH_OP_AND, op1, ctxt->comp->last, 0, 0); in xmlXPathCompAndExpr()
10187 xmlXPathContextPtr xpctxt = ctxt->context; in xmlXPathCompileExpr()
10190 if (xpctxt->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompileExpr()
10196 xpctxt->depth += 10; in xmlXPathCompileExpr()
10203 int op1 = ctxt->comp->last; in xmlXPathCompileExpr()
10208 PUSH_BINARY_EXPR(XPATH_OP_OR, op1, ctxt->comp->last, 0, 0); in xmlXPathCompileExpr()
10211 if ((sort) && (ctxt->comp->steps[ctxt->comp->last].op != XPATH_OP_VALUE)) { in xmlXPathCompileExpr()
10215 * operations which don't require a sorted node-set. in xmlXPathCompileExpr()
10218 PUSH_UNARY_EXPR(XPATH_OP_SORT, ctxt->comp->last , 0, 0); in xmlXPathCompileExpr()
10222 xpctxt->depth -= 10; in xmlXPathCompileExpr()
10237 int op1 = ctxt->comp->last; in xmlXPathCompPredicate()
10246 ctxt->comp->last = -1; in xmlXPathCompPredicate()
10267 PUSH_BINARY_EXPR(XPATH_OP_FILTER, op1, ctxt->comp->last, 0, 0); in xmlXPathCompPredicate()
10269 PUSH_BINARY_EXPR(XPATH_OP_PREDICATE, op1, ctxt->comp->last, 0, 0); in xmlXPathCompPredicate()
10284 * | 'processing-instruction' '(' Literal ')'
10291 * | 'processing-instruction'
10337 else if (xmlStrEqual(name, BAD_CAST "processing-instruction")) in xmlXPathCompNodeTest()
10386 *prefix = xmlXPathNsLookup(ctxt->context, name); in xmlXPathCompNodeTest()
10418 * | 'ancestor-or-self'
10422 * | 'descendant-or-self'
10424 * | 'following-sibling'
10428 * | 'preceding-sibling'
10440 if (xmlStrEqual(name, BAD_CAST "ancestor-or-self")) in xmlXPathIsAxisName()
10452 if (xmlStrEqual(name, BAD_CAST "descendant-or-self")) in xmlXPathIsAxisName()
10458 if (xmlStrEqual(name, BAD_CAST "following-sibling")) in xmlXPathIsAxisName()
10470 if (xmlStrEqual(name, BAD_CAST "preceding-sibling")) in xmlXPathIsAxisName()
10499 * | 'range-to' '(' Expr ')' Predicate*
10505 * self::node()/descendant-or-self::node()/child::para
10517 int op2 = -1; in xmlXPathCompStep()
10541 if (ctxt->xptr) { in xmlXPathCompStep()
10543 if ((name != NULL) && (xmlStrEqual(name, BAD_CAST "range-to"))) { in xmlXPathCompStep()
10544 op2 = ctxt->comp->last; in xmlXPathCompStep()
10554 /* PUSH_BINARY_EXPR(XPATH_OP_RANGETO, op2, ctxt->comp->last, 0, 0); */ in xmlXPathCompStep()
10581 /* an element name can conflict with an axis one :-\ */ in xmlXPathCompStep()
10595 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompStep()
10604 if ((prefix != NULL) && (ctxt->context != NULL) && in xmlXPathCompStep()
10605 (ctxt->context->flags & XML_XPATH_CHECKNS)) { in xmlXPathCompStep()
10606 if (xmlXPathNsLookup(ctxt->context, prefix) == NULL) { in xmlXPathCompStep()
10614 op1 = ctxt->comp->last; in xmlXPathCompStep()
10615 ctxt->comp->last = -1; in xmlXPathCompStep()
10627 if (PUSH_FULL_EXPR(XPATH_OP_COLLECT, op1, ctxt->comp->last, axis, in xmlXPathCompStep()
10628 test, type, (void *)prefix, (void *)name) == -1) { in xmlXPathCompStep()
10691 * // is short for /descendant-or-self::node()/. For example,
10692 * //para is short for /descendant-or-self::node()/child::para and
10696 * short for div/descendant-or-self::node()/child::para and so will
10739 * @minPos: minimum position in the filtered set (1-based)
10740 * @maxPos: maximum position in the filtered set (1-based)
10761 if ((set == NULL) || (set->nodeNr == 0)) in xmlXPathNodeSetFilter()
10768 if (set->nodeNr < minPos) { in xmlXPathNodeSetFilter()
10773 xpctxt = ctxt->context; in xmlXPathNodeSetFilter()
10774 oldnode = xpctxt->node; in xmlXPathNodeSetFilter()
10775 olddoc = xpctxt->doc; in xmlXPathNodeSetFilter()
10776 oldcs = xpctxt->contextSize; in xmlXPathNodeSetFilter()
10777 oldpp = xpctxt->proximityPosition; in xmlXPathNodeSetFilter()
10778 filterOp = &ctxt->comp->steps[filterOpIndex]; in xmlXPathNodeSetFilter()
10780 xpctxt->contextSize = set->nodeNr; in xmlXPathNodeSetFilter()
10782 for (i = 0, j = 0, pos = 1; i < set->nodeNr; i++) { in xmlXPathNodeSetFilter()
10783 xmlNodePtr node = set->nodeTab[i]; in xmlXPathNodeSetFilter()
10786 xpctxt->node = node; in xmlXPathNodeSetFilter()
10787 xpctxt->proximityPosition = i + 1; in xmlXPathNodeSetFilter()
10795 if ((node->type != XML_NAMESPACE_DECL) && in xmlXPathNodeSetFilter()
10796 (node->doc != NULL)) in xmlXPathNodeSetFilter()
10797 xpctxt->doc = node->doc; in xmlXPathNodeSetFilter()
10801 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathNodeSetFilter()
10811 set->nodeTab[j] = node; in xmlXPathNodeSetFilter()
10812 set->nodeTab[i] = NULL; in xmlXPathNodeSetFilter()
10818 set->nodeTab[i] = NULL; in xmlXPathNodeSetFilter()
10819 if (node->type == XML_NAMESPACE_DECL) in xmlXPathNodeSetFilter()
10835 for (; i < set->nodeNr; i++) { in xmlXPathNodeSetFilter()
10836 xmlNodePtr node = set->nodeTab[i]; in xmlXPathNodeSetFilter()
10837 if ((node != NULL) && (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetFilter()
10842 set->nodeNr = j; in xmlXPathNodeSetFilter()
10845 if ((set->nodeMax > XML_NODESET_DEFAULT) && in xmlXPathNodeSetFilter()
10846 (set->nodeNr < set->nodeMax / 2)) { in xmlXPathNodeSetFilter()
10848 int nodeMax = set->nodeNr; in xmlXPathNodeSetFilter()
10852 tmp = (xmlNodePtr *) xmlRealloc(set->nodeTab, in xmlXPathNodeSetFilter()
10857 set->nodeTab = tmp; in xmlXPathNodeSetFilter()
10858 set->nodeMax = nodeMax; in xmlXPathNodeSetFilter()
10862 xpctxt->node = oldnode; in xmlXPathNodeSetFilter()
10863 xpctxt->doc = olddoc; in xmlXPathNodeSetFilter()
10864 xpctxt->contextSize = oldcs; in xmlXPathNodeSetFilter()
10865 xpctxt->proximityPosition = oldpp; in xmlXPathNodeSetFilter()
10874 * @minPos: minimum position in the filtered set (1-based)
10875 * @maxPos: maximum position in the filtered set (1-based)
10894 if ((locset == NULL) || (locset->locNr == 0) || (filterOpIndex == -1)) in xmlXPathLocationSetFilter()
10897 xpctxt = ctxt->context; in xmlXPathLocationSetFilter()
10898 oldnode = xpctxt->node; in xmlXPathLocationSetFilter()
10899 olddoc = xpctxt->doc; in xmlXPathLocationSetFilter()
10900 oldcs = xpctxt->contextSize; in xmlXPathLocationSetFilter()
10901 oldpp = xpctxt->proximityPosition; in xmlXPathLocationSetFilter()
10902 filterOp = &ctxt->comp->steps[filterOpIndex]; in xmlXPathLocationSetFilter()
10904 xpctxt->contextSize = locset->locNr; in xmlXPathLocationSetFilter()
10906 for (i = 0, j = 0, pos = 1; i < locset->locNr; i++) { in xmlXPathLocationSetFilter()
10907 xmlNodePtr contextNode = locset->locTab[i]->user; in xmlXPathLocationSetFilter()
10910 xpctxt->node = contextNode; in xmlXPathLocationSetFilter()
10911 xpctxt->proximityPosition = i + 1; in xmlXPathLocationSetFilter()
10919 if ((contextNode->type != XML_NAMESPACE_DECL) && in xmlXPathLocationSetFilter()
10920 (contextNode->doc != NULL)) in xmlXPathLocationSetFilter()
10921 xpctxt->doc = contextNode->doc; in xmlXPathLocationSetFilter()
10925 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathLocationSetFilter()
10935 locset->locTab[j] = locset->locTab[i]; in xmlXPathLocationSetFilter()
10936 locset->locTab[i] = NULL; in xmlXPathLocationSetFilter()
10942 xmlXPathFreeObject(locset->locTab[i]); in xmlXPathLocationSetFilter()
10943 locset->locTab[i] = NULL; in xmlXPathLocationSetFilter()
10957 for (; i < locset->locNr; i++) in xmlXPathLocationSetFilter()
10958 xmlXPathFreeObject(locset->locTab[i]); in xmlXPathLocationSetFilter()
10960 locset->locNr = j; in xmlXPathLocationSetFilter()
10963 if ((locset->locMax > XML_NODESET_DEFAULT) && in xmlXPathLocationSetFilter()
10964 (locset->locNr < locset->locMax / 2)) { in xmlXPathLocationSetFilter()
10966 int locMax = locset->locNr; in xmlXPathLocationSetFilter()
10970 tmp = (xmlXPathObjectPtr *) xmlRealloc(locset->locTab, in xmlXPathLocationSetFilter()
10975 locset->locTab = tmp; in xmlXPathLocationSetFilter()
10976 locset->locMax = locMax; in xmlXPathLocationSetFilter()
10980 xpctxt->node = oldnode; in xmlXPathLocationSetFilter()
10981 xpctxt->doc = olddoc; in xmlXPathLocationSetFilter()
10982 xpctxt->contextSize = oldcs; in xmlXPathLocationSetFilter()
10983 xpctxt->proximityPosition = oldpp; in xmlXPathLocationSetFilter()
10992 * @minPos: minimum position in the filtered set (1-based)
10993 * @maxPos: maximum position in the filtered set (1-based)
11007 if (op->ch1 != -1) { in xmlXPathCompOpEvalPredicate()
11008 xmlXPathCompExprPtr comp = ctxt->comp; in xmlXPathCompOpEvalPredicate()
11010 * Process inner predicates first. in xmlXPathCompOpEvalPredicate()
11012 if (comp->steps[op->ch1].op != XPATH_OP_PREDICATE) { in xmlXPathCompOpEvalPredicate()
11017 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEvalPredicate()
11019 ctxt->context->depth += 1; in xmlXPathCompOpEvalPredicate()
11020 xmlXPathCompOpEvalPredicate(ctxt, &comp->steps[op->ch1], set, in xmlXPathCompOpEvalPredicate()
11021 1, set->nodeNr, hasNsNodes); in xmlXPathCompOpEvalPredicate()
11022 ctxt->context->depth -= 1; in xmlXPathCompOpEvalPredicate()
11026 if (op->ch2 != -1) in xmlXPathCompOpEvalPredicate()
11027 xmlXPathNodeSetFilter(ctxt, set, op->ch2, minPos, maxPos, hasNsNodes); in xmlXPathCompOpEvalPredicate()
11043 * If not -1, then ch1 will point to: in xmlXPathIsPositionalPredicate()
11044 * 1) For predicates (XPATH_OP_PREDICATE): in xmlXPathIsPositionalPredicate()
11045 * - an inner predicate operator in xmlXPathIsPositionalPredicate()
11047 * - an inner filter operator OR in xmlXPathIsPositionalPredicate()
11048 * - an expression selecting the node set. in xmlXPathIsPositionalPredicate()
11051 if ((op->op != XPATH_OP_PREDICATE) && (op->op != XPATH_OP_FILTER)) in xmlXPathIsPositionalPredicate()
11054 if (op->ch2 != -1) { in xmlXPathIsPositionalPredicate()
11055 exprOp = &ctxt->comp->steps[op->ch2]; in xmlXPathIsPositionalPredicate()
11060 (exprOp->op == XPATH_OP_VALUE) && in xmlXPathIsPositionalPredicate()
11061 (exprOp->value4 != NULL) && in xmlXPathIsPositionalPredicate()
11062 (((xmlXPathObjectPtr) exprOp->value4)->type == XPATH_NUMBER)) in xmlXPathIsPositionalPredicate()
11064 double floatval = ((xmlXPathObjectPtr) exprOp->value4)->floatval; in xmlXPathIsPositionalPredicate()
11072 * "[position() = 1]"; thus - obviously - a position-range, in xmlXPathIsPositionalPredicate()
11097 ctxt->error = XPATH_MEMORY_ERROR; \ in xmlXPathNodeCollectAndTest()
11101 ctxt->error = XPATH_MEMORY_ERROR; \ in xmlXPathNodeCollectAndTest()
11108 if (xmlXPathNodeSetAddNs(seq, xpctxt->node, (xmlNsPtr) cur) < 0) \ in xmlXPathNodeCollectAndTest()
11109 ctxt->error = XPATH_MEMORY_ERROR; \ in xmlXPathNodeCollectAndTest()
11113 if (xmlXPathNodeSetAddNs(seq, xpctxt->node, (xmlNsPtr) cur) < 0) \ in xmlXPathNodeCollectAndTest()
11114 ctxt->error = XPATH_MEMORY_ERROR; \ in xmlXPathNodeCollectAndTest()
11117 xmlXPathAxisVal axis = (xmlXPathAxisVal) op->value; in xmlXPathNodeCollectAndTest()
11118 xmlXPathTestVal test = (xmlXPathTestVal) op->value2; in xmlXPathNodeCollectAndTest()
11119 xmlXPathTypeVal type = (xmlXPathTypeVal) op->value3; in xmlXPathNodeCollectAndTest()
11120 const xmlChar *prefix = op->value4; in xmlXPathNodeCollectAndTest()
11121 const xmlChar *name = op->value5; in xmlXPathNodeCollectAndTest()
11149 xmlXPathContextPtr xpctxt = ctxt->context; in xmlXPathNodeCollectAndTest()
11168 * - If the nodes to be traversed wrt to the initial nodes and in xmlXPathNodeCollectAndTest()
11173 * not in the ancestor-or-self axis of the other, then we could safely in xmlXPathNodeCollectAndTest()
11174 * avoid a duplicate-aware merge, if the axis to be traversed is e.g. in xmlXPathNodeCollectAndTest()
11175 * the descendant-or-self axis. in xmlXPathNodeCollectAndTest()
11252 contextSeq = obj->nodesetval; in xmlXPathNodeCollectAndTest()
11253 if ((contextSeq == NULL) || (contextSeq->nodeNr <= 0)) { in xmlXPathNodeCollectAndTest()
11259 * Predicate optimization --------------------------------------------- in xmlXPathNodeCollectAndTest()
11262 * the short-hand form, i.e., "[n]". in xmlXPathNodeCollectAndTest()
11264 * Example - expression "/foo[parent::bar][1]": in xmlXPathNodeCollectAndTest()
11266 * COLLECT 'child' 'name' 'node' foo -- op (we are here) in xmlXPathNodeCollectAndTest()
11267 * ROOT -- op->ch1 in xmlXPathNodeCollectAndTest()
11268 * PREDICATE -- op->ch2 (predOp) in xmlXPathNodeCollectAndTest()
11269 * PREDICATE -- predOp->ch1 = [parent::bar] in xmlXPathNodeCollectAndTest()
11273 * ELEM Object is a number : 1 -- predOp->ch2 = [1] in xmlXPathNodeCollectAndTest()
11280 if (op->ch2 != -1) { in xmlXPathNodeCollectAndTest()
11284 predOp = &ctxt->comp->steps[op->ch2]; in xmlXPathNodeCollectAndTest()
11286 if (predOp->ch1 != -1) { in xmlXPathNodeCollectAndTest()
11290 predOp = &ctxt->comp->steps[predOp->ch1]; in xmlXPathNodeCollectAndTest()
11303 * Axis traversal ----------------------------------------------------- in xmlXPathNodeCollectAndTest()
11307 * - For the attribute axis, the principal node type is attribute. in xmlXPathNodeCollectAndTest()
11308 * - For the namespace axis, the principal node type is namespace. in xmlXPathNodeCollectAndTest()
11309 * - For other axes, the principal node type is element. in xmlXPathNodeCollectAndTest()
11315 oldContextNode = xpctxt->node; in xmlXPathNodeCollectAndTest()
11323 while (((contextIdx < contextSeq->nodeNr) || (contextNode != NULL)) && in xmlXPathNodeCollectAndTest()
11324 (ctxt->error == XPATH_EXPRESSION_OK)) { in xmlXPathNodeCollectAndTest()
11325 xpctxt->node = contextSeq->nodeTab[contextIdx++]; in xmlXPathNodeCollectAndTest()
11388 switch (cur->type) { in xmlXPathNodeCollectAndTest()
11411 } else if (cur->type == (xmlElementType) type) { in xmlXPathNodeCollectAndTest()
11412 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNodeCollectAndTest()
11417 (cur->type == XML_CDATA_SECTION_NODE)) in xmlXPathNodeCollectAndTest()
11423 if ((cur->type == XML_PI_NODE) && in xmlXPathNodeCollectAndTest()
11424 ((name == NULL) || xmlStrEqual(name, cur->name))) in xmlXPathNodeCollectAndTest()
11431 if (cur->type == XML_ATTRIBUTE_NODE) in xmlXPathNodeCollectAndTest()
11436 } else if ((cur->ns != NULL) && in xmlXPathNodeCollectAndTest()
11437 (xmlStrEqual(URI, cur->ns->href))) in xmlXPathNodeCollectAndTest()
11443 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNodeCollectAndTest()
11448 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathNodeCollectAndTest()
11453 } else if ((cur->ns != NULL) && in xmlXPathNodeCollectAndTest()
11454 (xmlStrEqual(URI, cur->ns->href))) in xmlXPathNodeCollectAndTest()
11467 if (cur->type != XML_ATTRIBUTE_NODE) in xmlXPathNodeCollectAndTest()
11470 if (cur->type != XML_NAMESPACE_DECL) in xmlXPathNodeCollectAndTest()
11473 if (cur->type != XML_ELEMENT_NODE) in xmlXPathNodeCollectAndTest()
11476 switch (cur->type) { in xmlXPathNodeCollectAndTest()
11478 if (xmlStrEqual(name, cur->name)) { in xmlXPathNodeCollectAndTest()
11480 if (cur->ns == NULL) in xmlXPathNodeCollectAndTest()
11485 if ((cur->ns != NULL) && in xmlXPathNodeCollectAndTest()
11486 (xmlStrEqual(URI, cur->ns->href))) in xmlXPathNodeCollectAndTest()
11496 if (xmlStrEqual(name, attr->name)) { in xmlXPathNodeCollectAndTest()
11498 if ((attr->ns == NULL) || in xmlXPathNodeCollectAndTest()
11499 (attr->ns->prefix == NULL)) in xmlXPathNodeCollectAndTest()
11504 if ((attr->ns != NULL) && in xmlXPathNodeCollectAndTest()
11506 attr->ns->href))) in xmlXPathNodeCollectAndTest()
11515 if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNodeCollectAndTest()
11518 if ((ns->prefix != NULL) && (name != NULL) in xmlXPathNodeCollectAndTest()
11519 && (xmlStrEqual(ns->prefix, name))) in xmlXPathNodeCollectAndTest()
11530 } while ((cur != NULL) && (ctxt->error == XPATH_EXPRESSION_OK)); in xmlXPathNodeCollectAndTest()
11534 axis_range_end: /* ----------------------------------------------------- */ in xmlXPathNodeCollectAndTest()
11538 * a duplicate-aware merge is still needed. in xmlXPathNodeCollectAndTest()
11554 first_hit: /* ---------------------------------------------------------- */ in xmlXPathNodeCollectAndTest()
11557 * no predicates existed and a node test succeeded. in xmlXPathNodeCollectAndTest()
11567 apply_predicates: /* --------------------------------------------------- */ in xmlXPathNodeCollectAndTest()
11568 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathNodeCollectAndTest()
11572 * Apply predicates. in xmlXPathNodeCollectAndTest()
11574 if ((predOp != NULL) && (seq->nodeNr > 0)) { in xmlXPathNodeCollectAndTest()
11580 * account location-sets. in xmlXPathNodeCollectAndTest()
11581 * (E.g. ctxt->value->type == XPATH_LOCATIONSET) in xmlXPathNodeCollectAndTest()
11584 * does not indicate that a location-set will be processed in xmlXPathNodeCollectAndTest()
11588 * Iterate over all predicates, starting with the outermost in xmlXPathNodeCollectAndTest()
11590 * TODO: Problem: we cannot execute the inner predicates first in xmlXPathNodeCollectAndTest()
11607 xmlXPathCompOpEvalPredicate(ctxt, predOp, seq, 1, seq->nodeNr, in xmlXPathNodeCollectAndTest()
11610 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathNodeCollectAndTest()
11616 if (seq->nodeNr > 0) { in xmlXPathNodeCollectAndTest()
11634 if ((obj->boolval) && (obj->user != NULL)) { in xmlXPathNodeCollectAndTest()
11640 ctxt->value->boolval = 1; in xmlXPathNodeCollectAndTest()
11641 ctxt->value->user = obj->user; in xmlXPathNodeCollectAndTest()
11642 obj->user = NULL; in xmlXPathNodeCollectAndTest()
11643 obj->boolval = 0; in xmlXPathNodeCollectAndTest()
11651 if ((seq != NULL) && (seq->nodeNr == 0)) in xmlXPathNodeCollectAndTest()
11668 xpctxt->node = oldContextNode; in xmlXPathNodeCollectAndTest()
11673 if (xpctxt->tmpNsList != NULL) { in xmlXPathNodeCollectAndTest()
11674 xmlFree(xpctxt->tmpNsList); in xmlXPathNodeCollectAndTest()
11675 xpctxt->tmpNsList = NULL; in xmlXPathNodeCollectAndTest()
11707 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEvalFirst()
11709 ctxt->context->depth += 1; in xmlXPathCompOpEvalFirst()
11710 comp = ctxt->comp; in xmlXPathCompOpEvalFirst()
11711 switch (op->op) { in xmlXPathCompOpEvalFirst()
11716 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1], in xmlXPathCompOpEvalFirst()
11719 if ((ctxt->value != NULL) in xmlXPathCompOpEvalFirst()
11720 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalFirst()
11721 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalFirst()
11722 && (ctxt->value->nodesetval->nodeNr >= 1)) { in xmlXPathCompOpEvalFirst()
11730 * OPTIMIZE TODO: How do we know if the node-list wasn't in xmlXPathCompOpEvalFirst()
11733 if (ctxt->value->nodesetval->nodeNr > 1) in xmlXPathCompOpEvalFirst()
11734 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalFirst()
11735 *first = ctxt->value->nodesetval->nodeTab[0]; in xmlXPathCompOpEvalFirst()
11738 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch2], in xmlXPathCompOpEvalFirst()
11744 if ((arg1 == NULL) || (arg1->type != XPATH_NODESET) || in xmlXPathCompOpEvalFirst()
11745 (arg2 == NULL) || (arg2->type != XPATH_NODESET)) { in xmlXPathCompOpEvalFirst()
11746 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalFirst()
11747 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalFirst()
11750 if ((ctxt->context->opLimit != 0) && in xmlXPathCompOpEvalFirst()
11751 (((arg1->nodesetval != NULL) && in xmlXPathCompOpEvalFirst()
11753 arg1->nodesetval->nodeNr) < 0)) || in xmlXPathCompOpEvalFirst()
11754 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEvalFirst()
11756 arg2->nodesetval->nodeNr) < 0)))) { in xmlXPathCompOpEvalFirst()
11757 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalFirst()
11758 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalFirst()
11763 arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, in xmlXPathCompOpEvalFirst()
11764 arg2->nodesetval); in xmlXPathCompOpEvalFirst()
11766 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalFirst()
11776 if (op->ch1 != -1) in xmlXPathCompOpEvalFirst()
11777 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalFirst()
11779 if (op->ch2 != -1) in xmlXPathCompOpEvalFirst()
11780 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEvalFirst()
11782 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathCompOpEvalFirst()
11783 ctxt->context->node)); in xmlXPathCompOpEvalFirst()
11786 if (op->ch1 == -1) in xmlXPathCompOpEvalFirst()
11789 total = xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalFirst()
11797 xmlXPathCacheObjectCopy(ctxt->context, in xmlXPathCompOpEvalFirst()
11798 (xmlXPathObjectPtr) op->value4)); in xmlXPathCompOpEvalFirst()
11801 if (op->ch1 != -1) in xmlXPathCompOpEvalFirst()
11803 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1], in xmlXPathCompOpEvalFirst()
11806 if ((ctxt->value != NULL) in xmlXPathCompOpEvalFirst()
11807 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalFirst()
11808 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalFirst()
11809 && (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEvalFirst()
11810 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalFirst()
11822 ctxt->context->depth -= 1; in xmlXPathCompOpEvalFirst()
11848 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEvalLast()
11850 ctxt->context->depth += 1; in xmlXPathCompOpEvalLast()
11851 comp = ctxt->comp; in xmlXPathCompOpEvalLast()
11852 switch (op->op) { in xmlXPathCompOpEvalLast()
11857 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], last); in xmlXPathCompOpEvalLast()
11859 if ((ctxt->value != NULL) in xmlXPathCompOpEvalLast()
11860 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalLast()
11861 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalLast()
11862 && (ctxt->value->nodesetval->nodeNr >= 1)) { in xmlXPathCompOpEvalLast()
11866 if (ctxt->value->nodesetval->nodeNr > 1) in xmlXPathCompOpEvalLast()
11867 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalLast()
11869 ctxt->value->nodesetval->nodeTab[ctxt->value-> in xmlXPathCompOpEvalLast()
11870 nodesetval->nodeNr - in xmlXPathCompOpEvalLast()
11874 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch2], last); in xmlXPathCompOpEvalLast()
11876 if ((ctxt->value != NULL) in xmlXPathCompOpEvalLast()
11877 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalLast()
11878 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalLast()
11879 && (ctxt->value->nodesetval->nodeNr >= 1)) { /* TODO: NOP ? */ in xmlXPathCompOpEvalLast()
11884 if ((arg1 == NULL) || (arg1->type != XPATH_NODESET) || in xmlXPathCompOpEvalLast()
11885 (arg2 == NULL) || (arg2->type != XPATH_NODESET)) { in xmlXPathCompOpEvalLast()
11886 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalLast()
11887 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalLast()
11890 if ((ctxt->context->opLimit != 0) && in xmlXPathCompOpEvalLast()
11891 (((arg1->nodesetval != NULL) && in xmlXPathCompOpEvalLast()
11893 arg1->nodesetval->nodeNr) < 0)) || in xmlXPathCompOpEvalLast()
11894 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEvalLast()
11896 arg2->nodesetval->nodeNr) < 0)))) { in xmlXPathCompOpEvalLast()
11897 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalLast()
11898 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalLast()
11903 arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, in xmlXPathCompOpEvalLast()
11904 arg2->nodesetval); in xmlXPathCompOpEvalLast()
11906 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalLast()
11916 if (op->ch1 != -1) in xmlXPathCompOpEvalLast()
11917 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalLast()
11919 if (op->ch2 != -1) in xmlXPathCompOpEvalLast()
11920 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEvalLast()
11922 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathCompOpEvalLast()
11923 ctxt->context->node)); in xmlXPathCompOpEvalLast()
11926 if (op->ch1 == -1) in xmlXPathCompOpEvalLast()
11929 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalLast()
11937 xmlXPathCacheObjectCopy(ctxt->context, in xmlXPathCompOpEvalLast()
11938 (xmlXPathObjectPtr) op->value4)); in xmlXPathCompOpEvalLast()
11941 if (op->ch1 != -1) in xmlXPathCompOpEvalLast()
11943 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], in xmlXPathCompOpEvalLast()
11946 if ((ctxt->value != NULL) in xmlXPathCompOpEvalLast()
11947 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalLast()
11948 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalLast()
11949 && (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEvalLast()
11950 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalLast()
11957 ctxt->context->depth -= 1; in xmlXPathCompOpEvalLast()
11972 comp = ctxt->comp; in xmlXPathCompOpEvalFilterFirst()
11976 if ((op->ch1 != -1) && (op->ch2 != -1) && in xmlXPathCompOpEvalFilterFirst()
11977 (comp->steps[op->ch1].op == XPATH_OP_SORT) && in xmlXPathCompOpEvalFilterFirst()
11978 (comp->steps[op->ch2].op == XPATH_OP_SORT)) { in xmlXPathCompOpEvalFilterFirst()
11979 int f = comp->steps[op->ch2].ch1; in xmlXPathCompOpEvalFilterFirst()
11981 if ((f != -1) && in xmlXPathCompOpEvalFilterFirst()
11982 (comp->steps[f].op == XPATH_OP_FUNCTION) && in xmlXPathCompOpEvalFilterFirst()
11983 (comp->steps[f].value5 == NULL) && in xmlXPathCompOpEvalFilterFirst()
11984 (comp->steps[f].value == 0) && in xmlXPathCompOpEvalFilterFirst()
11985 (comp->steps[f].value4 != NULL) && in xmlXPathCompOpEvalFilterFirst()
11987 (comp->steps[f].value4, BAD_CAST "last"))) { in xmlXPathCompOpEvalFilterFirst()
11992 &comp->steps[op->ch1], in xmlXPathCompOpEvalFilterFirst()
11999 if ((ctxt->value != NULL) && in xmlXPathCompOpEvalFilterFirst()
12000 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEvalFilterFirst()
12001 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEvalFilterFirst()
12002 (ctxt->value->nodesetval->nodeTab != NULL) && in xmlXPathCompOpEvalFilterFirst()
12003 (ctxt->value->nodesetval->nodeNr > 1)) { in xmlXPathCompOpEvalFilterFirst()
12004 xmlXPathNodeSetKeepLast(ctxt->value->nodesetval); in xmlXPathCompOpEvalFilterFirst()
12005 *first = *(ctxt->value->nodesetval->nodeTab); in xmlXPathCompOpEvalFilterFirst()
12011 if (op->ch1 != -1) in xmlXPathCompOpEvalFilterFirst()
12012 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalFilterFirst()
12014 if (op->ch2 == -1) in xmlXPathCompOpEvalFilterFirst()
12016 if (ctxt->value == NULL) in xmlXPathCompOpEvalFilterFirst()
12023 if (ctxt->value->type == XPATH_LOCATIONSET) { in xmlXPathCompOpEvalFilterFirst()
12024 xmlLocationSetPtr locset = ctxt->value->user; in xmlXPathCompOpEvalFilterFirst()
12027 xmlXPathLocationSetFilter(ctxt, locset, op->ch2, 1, 1); in xmlXPathCompOpEvalFilterFirst()
12028 if (locset->locNr > 0) in xmlXPathCompOpEvalFilterFirst()
12029 *first = (xmlNodePtr) locset->locTab[0]->user; in xmlXPathCompOpEvalFilterFirst()
12043 set = obj->nodesetval; in xmlXPathCompOpEvalFilterFirst()
12045 xmlXPathNodeSetFilter(ctxt, set, op->ch2, 1, 1, 1); in xmlXPathCompOpEvalFilterFirst()
12046 if (set->nodeNr > 0) in xmlXPathCompOpEvalFilterFirst()
12047 *first = set->nodeTab[0]; in xmlXPathCompOpEvalFilterFirst()
12074 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEval()
12076 ctxt->context->depth += 1; in xmlXPathCompOpEval()
12077 comp = ctxt->comp; in xmlXPathCompOpEval()
12078 switch (op->op) { in xmlXPathCompOpEval()
12082 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12085 if ((ctxt->value == NULL) || (ctxt->value->boolval == 0)) in xmlXPathCompOpEval()
12088 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12089 if (ctxt->error) { in xmlXPathCompOpEval()
12094 if (ctxt->value != NULL) in xmlXPathCompOpEval()
12095 ctxt->value->boolval &= arg2->boolval; in xmlXPathCompOpEval()
12096 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
12099 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12102 if ((ctxt->value == NULL) || (ctxt->value->boolval == 1)) in xmlXPathCompOpEval()
12105 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12106 if (ctxt->error) { in xmlXPathCompOpEval()
12111 if (ctxt->value != NULL) in xmlXPathCompOpEval()
12112 ctxt->value->boolval |= arg2->boolval; in xmlXPathCompOpEval()
12113 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
12116 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12118 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12120 if (op->value) in xmlXPathCompOpEval()
12124 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, equal)); in xmlXPathCompOpEval()
12127 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12129 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12131 ret = xmlXPathCompareValues(ctxt, op->value, op->value2); in xmlXPathCompOpEval()
12132 valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, ret)); in xmlXPathCompOpEval()
12135 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12137 if (op->ch2 != -1) { in xmlXPathCompOpEval()
12138 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12141 if (op->value == 0) in xmlXPathCompOpEval()
12143 else if (op->value == 1) in xmlXPathCompOpEval()
12145 else if (op->value == 2) in xmlXPathCompOpEval()
12147 else if (op->value == 3) { in xmlXPathCompOpEval()
12153 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12155 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12157 if (op->value == 0) in xmlXPathCompOpEval()
12159 else if (op->value == 1) in xmlXPathCompOpEval()
12161 else if (op->value == 2) in xmlXPathCompOpEval()
12165 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12167 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12172 if ((arg1 == NULL) || (arg1->type != XPATH_NODESET) || in xmlXPathCompOpEval()
12173 (arg2 == NULL) || (arg2->type != XPATH_NODESET)) { in xmlXPathCompOpEval()
12174 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEval()
12175 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
12178 if ((ctxt->context->opLimit != 0) && in xmlXPathCompOpEval()
12179 (((arg1->nodesetval != NULL) && in xmlXPathCompOpEval()
12181 arg1->nodesetval->nodeNr) < 0)) || in xmlXPathCompOpEval()
12182 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEval()
12184 arg2->nodesetval->nodeNr) < 0)))) { in xmlXPathCompOpEval()
12185 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEval()
12186 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
12190 if ((arg1->nodesetval == NULL) || in xmlXPathCompOpEval()
12191 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEval()
12192 (arg2->nodesetval->nodeNr != 0))) in xmlXPathCompOpEval()
12195 arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, in xmlXPathCompOpEval()
12196 arg2->nodesetval); in xmlXPathCompOpEval()
12200 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
12206 if (op->ch1 != -1) in xmlXPathCompOpEval()
12207 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12209 if (op->ch2 != -1) in xmlXPathCompOpEval()
12210 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12212 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathCompOpEval()
12213 ctxt->context->node)); in xmlXPathCompOpEval()
12216 if (op->ch1 == -1) in xmlXPathCompOpEval()
12219 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12227 xmlXPathCacheObjectCopy(ctxt->context, in xmlXPathCompOpEval()
12228 (xmlXPathObjectPtr) op->value4)); in xmlXPathCompOpEval()
12233 if (op->ch1 != -1) in xmlXPathCompOpEval()
12235 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12236 if (op->value5 == NULL) { in xmlXPathCompOpEval()
12237 val = xmlXPathVariableLookup(ctxt->context, op->value4); in xmlXPathCompOpEval()
12244 URI = xmlXPathNsLookup(ctxt->context, op->value5); in xmlXPathCompOpEval()
12248 (char *) op->value4, (char *)op->value5); in xmlXPathCompOpEval()
12249 ctxt->error = XPATH_UNDEF_PREFIX_ERROR; in xmlXPathCompOpEval()
12252 val = xmlXPathVariableLookupNS(ctxt->context, in xmlXPathCompOpEval()
12253 op->value4, URI); in xmlXPathCompOpEval()
12266 frame = ctxt->valueNr; in xmlXPathCompOpEval()
12267 if (op->ch1 != -1) { in xmlXPathCompOpEval()
12269 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12270 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEval()
12273 if (ctxt->valueNr < frame + op->value) { in xmlXPathCompOpEval()
12276 ctxt->error = XPATH_INVALID_OPERAND; in xmlXPathCompOpEval()
12279 for (i = 0; i < op->value; i++) { in xmlXPathCompOpEval()
12280 if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) { in xmlXPathCompOpEval()
12283 ctxt->error = XPATH_INVALID_OPERAND; in xmlXPathCompOpEval()
12287 if (op->cache != NULL) in xmlXPathCompOpEval()
12288 func = op->cache; in xmlXPathCompOpEval()
12292 if (op->value5 == NULL) in xmlXPathCompOpEval()
12294 xmlXPathFunctionLookup(ctxt->context, in xmlXPathCompOpEval()
12295 op->value4); in xmlXPathCompOpEval()
12297 URI = xmlXPathNsLookup(ctxt->context, op->value5); in xmlXPathCompOpEval()
12301 (char *)op->value4, (char *)op->value5); in xmlXPathCompOpEval()
12302 ctxt->error = XPATH_UNDEF_PREFIX_ERROR; in xmlXPathCompOpEval()
12305 func = xmlXPathFunctionLookupNS(ctxt->context, in xmlXPathCompOpEval()
12306 op->value4, URI); in xmlXPathCompOpEval()
12311 (char *)op->value4); in xmlXPathCompOpEval()
12314 op->cache = func; in xmlXPathCompOpEval()
12315 op->cacheURI = (void *) URI; in xmlXPathCompOpEval()
12317 oldFunc = ctxt->context->function; in xmlXPathCompOpEval()
12318 oldFuncURI = ctxt->context->functionURI; in xmlXPathCompOpEval()
12319 ctxt->context->function = op->value4; in xmlXPathCompOpEval()
12320 ctxt->context->functionURI = op->cacheURI; in xmlXPathCompOpEval()
12321 func(ctxt, op->value); in xmlXPathCompOpEval()
12322 ctxt->context->function = oldFunc; in xmlXPathCompOpEval()
12323 ctxt->context->functionURI = oldFuncURI; in xmlXPathCompOpEval()
12324 if ((ctxt->error == XPATH_EXPRESSION_OK) && in xmlXPathCompOpEval()
12325 (ctxt->valueNr != frame + 1)) in xmlXPathCompOpEval()
12330 if (op->ch1 != -1) { in xmlXPathCompOpEval()
12331 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12334 if (op->ch2 != -1) { in xmlXPathCompOpEval()
12335 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12347 if ((op->ch1 != -1) && (op->ch2 != -1) && in xmlXPathCompOpEval()
12355 * to assume anything, so it would be more robust and in xmlXPathCompOpEval()
12358 ((comp->steps[op->ch1].op == XPATH_OP_SORT) || /* 18 */ in xmlXPathCompOpEval()
12359 (comp->steps[op->ch1].op == XPATH_OP_FILTER)) && /* 17 */ in xmlXPathCompOpEval()
12361 (comp->steps[op->ch1].op == XPATH_OP_SORT) && in xmlXPathCompOpEval()
12363 (comp->steps[op->ch2].op == XPATH_OP_VALUE)) { /* 12 */ in xmlXPathCompOpEval()
12366 val = comp->steps[op->ch2].value4; in xmlXPathCompOpEval()
12367 if ((val != NULL) && (val->type == XPATH_NUMBER) && in xmlXPathCompOpEval()
12368 (val->floatval == 1.0)) { in xmlXPathCompOpEval()
12373 &comp->steps[op->ch1], in xmlXPathCompOpEval()
12380 if ((ctxt->value != NULL) && in xmlXPathCompOpEval()
12381 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEval()
12382 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEval()
12383 (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEval()
12384 xmlXPathNodeSetClearFromPos(ctxt->value->nodesetval, in xmlXPathCompOpEval()
12392 if ((op->ch1 != -1) && (op->ch2 != -1) && in xmlXPathCompOpEval()
12393 (comp->steps[op->ch1].op == XPATH_OP_SORT) && in xmlXPathCompOpEval()
12394 (comp->steps[op->ch2].op == XPATH_OP_SORT)) { in xmlXPathCompOpEval()
12395 int f = comp->steps[op->ch2].ch1; in xmlXPathCompOpEval()
12397 if ((f != -1) && in xmlXPathCompOpEval()
12398 (comp->steps[f].op == XPATH_OP_FUNCTION) && in xmlXPathCompOpEval()
12399 (comp->steps[f].value5 == NULL) && in xmlXPathCompOpEval()
12400 (comp->steps[f].value == 0) && in xmlXPathCompOpEval()
12401 (comp->steps[f].value4 != NULL) && in xmlXPathCompOpEval()
12403 (comp->steps[f].value4, BAD_CAST "last"))) { in xmlXPathCompOpEval()
12408 &comp->steps[op->ch1], in xmlXPathCompOpEval()
12415 if ((ctxt->value != NULL) && in xmlXPathCompOpEval()
12416 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEval()
12417 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEval()
12418 (ctxt->value->nodesetval->nodeTab != NULL) && in xmlXPathCompOpEval()
12419 (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEval()
12420 xmlXPathNodeSetKeepLast(ctxt->value->nodesetval); in xmlXPathCompOpEval()
12425 * Process inner predicates first. in xmlXPathCompOpEval()
12428 * PREDICATE <-- we are here "[1]" in xmlXPathCompOpEval()
12429 * PREDICATE <-- process "[parent::book]" first in xmlXPathCompOpEval()
12435 if (op->ch1 != -1) in xmlXPathCompOpEval()
12437 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12439 if (op->ch2 == -1) in xmlXPathCompOpEval()
12441 if (ctxt->value == NULL) in xmlXPathCompOpEval()
12448 if (ctxt->value->type == XPATH_LOCATIONSET) { in xmlXPathCompOpEval()
12449 xmlLocationSetPtr locset = ctxt->value->user; in xmlXPathCompOpEval()
12450 xmlXPathLocationSetFilter(ctxt, locset, op->ch2, in xmlXPathCompOpEval()
12451 1, locset->locNr); in xmlXPathCompOpEval()
12464 set = obj->nodesetval; in xmlXPathCompOpEval()
12466 xmlXPathNodeSetFilter(ctxt, set, op->ch2, in xmlXPathCompOpEval()
12467 1, set->nodeNr, 1); in xmlXPathCompOpEval()
12472 if (op->ch1 != -1) in xmlXPathCompOpEval()
12473 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12475 if ((ctxt->value != NULL) && in xmlXPathCompOpEval()
12476 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEval()
12477 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEval()
12478 (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEval()
12480 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEval()
12491 xmlNodePtr oldnode = ctxt->context->node; in xmlXPathCompOpEval()
12492 int oldcs = ctxt->context->contextSize; in xmlXPathCompOpEval()
12493 int oldpp = ctxt->context->proximityPosition; in xmlXPathCompOpEval()
12496 if (op->ch1 != -1) { in xmlXPathCompOpEval()
12498 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
12501 if (ctxt->value == NULL) { in xmlXPathCompOpEval()
12504 if (op->ch2 == -1) in xmlXPathCompOpEval()
12507 if (ctxt->value->type == XPATH_LOCATIONSET) { in xmlXPathCompOpEval()
12515 if ((ctxt->value->user == NULL) || in xmlXPathCompOpEval()
12516 (((xmlLocationSetPtr) ctxt->value->user)->locNr == 0)) in xmlXPathCompOpEval()
12520 oldlocset = obj->user; in xmlXPathCompOpEval()
12524 for (i = 0; i < oldlocset->locNr; i++) { in xmlXPathCompOpEval()
12529 ctxt->context->node = oldlocset->locTab[i]->user; in xmlXPathCompOpEval()
12530 ctxt->context->contextSize = oldlocset->locNr; in xmlXPathCompOpEval()
12531 ctxt->context->proximityPosition = i + 1; in xmlXPathCompOpEval()
12532 tmp = xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathCompOpEval()
12533 ctxt->context->node); in xmlXPathCompOpEval()
12536 if (op->ch2 != -1) in xmlXPathCompOpEval()
12539 &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12540 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompOpEval()
12546 if (res->type == XPATH_LOCATIONSET) { in xmlXPathCompOpEval()
12548 (xmlLocationSetPtr)res->user; in xmlXPathCompOpEval()
12549 for (j=0; j<rloc->locNr; j++) { in xmlXPathCompOpEval()
12551 oldlocset->locTab[i]->user, in xmlXPathCompOpEval()
12552 oldlocset->locTab[i]->index, in xmlXPathCompOpEval()
12553 rloc->locTab[j]->user2, in xmlXPathCompOpEval()
12554 rloc->locTab[j]->index2); in xmlXPathCompOpEval()
12561 (xmlNodePtr)oldlocset->locTab[i]->user, res); in xmlXPathCompOpEval()
12571 xmlXPathReleaseObject(ctxt->context, res); in xmlXPathCompOpEval()
12573 if (ctxt->value == tmp) { in xmlXPathCompOpEval()
12575 xmlXPathReleaseObject(ctxt->context, res); in xmlXPathCompOpEval()
12581 oldset = obj->nodesetval; in xmlXPathCompOpEval()
12586 for (i = 0; i < oldset->nodeNr; i++) { in xmlXPathCompOpEval()
12591 ctxt->context->node = oldset->nodeTab[i]; in xmlXPathCompOpEval()
12595 tmp = xmlXPathCacheNewNodeSet(ctxt->context, in xmlXPathCompOpEval()
12596 ctxt->context->node); in xmlXPathCompOpEval()
12599 if (op->ch2 != -1) in xmlXPathCompOpEval()
12602 &comp->steps[op->ch2]); in xmlXPathCompOpEval()
12603 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompOpEval()
12610 xmlXPtrNewRangeNodeObject(oldset->nodeTab[i], in xmlXPathCompOpEval()
12620 xmlXPathReleaseObject(ctxt->context, res); in xmlXPathCompOpEval()
12622 if (ctxt->value == tmp) { in xmlXPathCompOpEval()
12624 xmlXPathReleaseObject(ctxt->context, res); in xmlXPathCompOpEval()
12635 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathCompOpEval()
12636 ctxt->context->node = oldnode; in xmlXPathCompOpEval()
12637 ctxt->context->contextSize = oldcs; in xmlXPathCompOpEval()
12638 ctxt->context->proximityPosition = oldpp; in xmlXPathCompOpEval()
12644 "XPath: unknown precompiled operation %d\n", op->op); in xmlXPathCompOpEval()
12645 ctxt->error = XPATH_INVALID_OPERAND; in xmlXPathCompOpEval()
12649 ctxt->context->depth -= 1; in xmlXPathCompOpEval()
12659 * Returns 1 if true, 0 if false and -1 on API or internal errors.
12671 /* comp = ctxt->comp; */ in xmlXPathCompOpEvalToBoolean()
12672 switch (op->op) { in xmlXPathCompOpEvalToBoolean()
12676 resObj = (xmlXPathObjectPtr) op->value4; in xmlXPathCompOpEvalToBoolean()
12684 if (op->ch1 != -1) { in xmlXPathCompOpEvalToBoolean()
12685 op = &ctxt->comp->steps[op->ch1]; in xmlXPathCompOpEvalToBoolean()
12690 if (op->ch1 == -1) in xmlXPathCompOpEvalToBoolean()
12693 xmlXPathCompOpEval(ctxt, &ctxt->comp->steps[op->ch1]); in xmlXPathCompOpEvalToBoolean()
12694 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEvalToBoolean()
12695 return(-1); in xmlXPathCompOpEvalToBoolean()
12698 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEvalToBoolean()
12699 return(-1); in xmlXPathCompOpEvalToBoolean()
12703 return(-1); in xmlXPathCompOpEvalToBoolean()
12710 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEvalToBoolean()
12711 return(-1); in xmlXPathCompOpEvalToBoolean()
12715 return(-1); in xmlXPathCompOpEvalToBoolean()
12722 if (resObj->type == XPATH_BOOLEAN) { in xmlXPathCompOpEvalToBoolean()
12723 res = resObj->boolval; in xmlXPathCompOpEvalToBoolean()
12726 * For predicates a result of type "number" is handled in xmlXPathCompOpEvalToBoolean()
12737 xmlXPathReleaseObject(ctxt->context, resObj); in xmlXPathCompOpEvalToBoolean()
12763 return(-1); in xmlXPathRunStreamEval()
12765 if (max_depth == -1) in xmlXPathRunStreamEval()
12766 return(-1); in xmlXPathRunStreamEval()
12767 if (max_depth == -2) in xmlXPathRunStreamEval()
12770 if (min_depth == -1) in xmlXPathRunStreamEval()
12771 return(-1); in xmlXPathRunStreamEval()
12774 return(-1); in xmlXPathRunStreamEval()
12781 return(-1); in xmlXPathRunStreamEval()
12784 return(-1); in xmlXPathRunStreamEval()
12796 xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, in xmlXPathRunStreamEval()
12797 (xmlNodePtr) ctxt->doc); in xmlXPathRunStreamEval()
12803 xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, ctxt->node); in xmlXPathRunStreamEval()
12811 cur = (xmlNodePtr)ctxt->doc; in xmlXPathRunStreamEval()
12812 } else if (ctxt->node != NULL) { in xmlXPathRunStreamEval()
12813 switch (ctxt->node->type) { in xmlXPathRunStreamEval()
12818 cur = ctxt->node; in xmlXPathRunStreamEval()
12861 xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, cur); in xmlXPathRunStreamEval()
12868 if (ctxt->opLimit != 0) { in xmlXPathRunStreamEval()
12869 if (ctxt->opCount >= ctxt->opLimit) { in xmlXPathRunStreamEval()
12873 return(-1); in xmlXPathRunStreamEval()
12875 ctxt->opCount++; in xmlXPathRunStreamEval()
12878 switch (cur->type) { in xmlXPathRunStreamEval()
12884 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathRunStreamEval()
12885 ret = xmlStreamPush(patstream, cur->name, in xmlXPathRunStreamEval()
12886 (cur->ns ? cur->ns->href : NULL)); in xmlXPathRunStreamEval()
12888 ret = xmlStreamPushNode(patstream, NULL, NULL, cur->type); in xmlXPathRunStreamEval()
12897 if (xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, cur) in xmlXPathRunStreamEval()
12899 ctxt->lastError.domain = XML_FROM_XPATH; in xmlXPathRunStreamEval()
12900 ctxt->lastError.code = XML_ERR_NO_MEMORY; in xmlXPathRunStreamEval()
12903 if ((cur->children == NULL) || (depth >= max_depth)) { in xmlXPathRunStreamEval()
12905 while (cur->next != NULL) { in xmlXPathRunStreamEval()
12906 cur = cur->next; in xmlXPathRunStreamEval()
12907 if ((cur->type != XML_ENTITY_DECL) && in xmlXPathRunStreamEval()
12908 (cur->type != XML_DTD_NODE)) in xmlXPathRunStreamEval()
12917 if (cur->type == XML_NAMESPACE_DECL) break; in xmlXPathRunStreamEval()
12918 if ((cur->children != NULL) && (depth < max_depth)) { in xmlXPathRunStreamEval()
12922 if (cur->children->type != XML_ENTITY_DECL) { in xmlXPathRunStreamEval()
12923 cur = cur->children; in xmlXPathRunStreamEval()
12928 if (cur->type != XML_DTD_NODE) in xmlXPathRunStreamEval()
12936 while (cur->next != NULL) { in xmlXPathRunStreamEval()
12937 cur = cur->next; in xmlXPathRunStreamEval()
12938 if ((cur->type != XML_ENTITY_DECL) && in xmlXPathRunStreamEval()
12939 (cur->type != XML_DTD_NODE)) in xmlXPathRunStreamEval()
12944 cur = cur->parent; in xmlXPathRunStreamEval()
12945 depth--; in xmlXPathRunStreamEval()
12947 (cur->type == XML_DOCUMENT_NODE)) in xmlXPathRunStreamEval()
12949 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathRunStreamEval()
12952 ((cur->type == XML_TEXT_NODE) || in xmlXPathRunStreamEval()
12953 (cur->type == XML_CDATA_SECTION_NODE) || in xmlXPathRunStreamEval()
12954 (cur->type == XML_COMMENT_NODE) || in xmlXPathRunStreamEval()
12955 (cur->type == XML_PI_NODE))) in xmlXPathRunStreamEval()
12959 if (cur->next != NULL) { in xmlXPathRunStreamEval()
12960 cur = cur->next; in xmlXPathRunStreamEval()
12993 if ((ctxt == NULL) || (ctxt->comp == NULL)) in xmlXPathRunEval()
12994 return(-1); in xmlXPathRunEval()
12996 if (ctxt->valueTab == NULL) { in xmlXPathRunEval()
12998 ctxt->valueTab = (xmlXPathObjectPtr *) in xmlXPathRunEval()
13000 if (ctxt->valueTab == NULL) { in xmlXPathRunEval()
13002 return(-1); in xmlXPathRunEval()
13004 ctxt->valueNr = 0; in xmlXPathRunEval()
13005 ctxt->valueMax = 10; in xmlXPathRunEval()
13006 ctxt->value = NULL; in xmlXPathRunEval()
13009 if (ctxt->comp->stream) { in xmlXPathRunEval()
13016 res = xmlXPathRunStreamEval(ctxt->context, in xmlXPathRunEval()
13017 ctxt->comp->stream, NULL, 1); in xmlXPathRunEval()
13018 if (res != -1) in xmlXPathRunEval()
13026 res = xmlXPathRunStreamEval(ctxt->context, in xmlXPathRunEval()
13027 ctxt->comp->stream, &resObj, 0); in xmlXPathRunEval()
13029 if ((res != -1) && (resObj != NULL)) { in xmlXPathRunEval()
13034 xmlXPathReleaseObject(ctxt->context, resObj); in xmlXPathRunEval()
13038 * if res == -1. Is this intended? in xmlXPathRunEval()
13042 comp = ctxt->comp; in xmlXPathRunEval()
13043 if (comp->last < 0) { in xmlXPathRunEval()
13046 return(-1); in xmlXPathRunEval()
13048 oldDepth = ctxt->context->depth; in xmlXPathRunEval()
13051 &comp->steps[comp->last], 0)); in xmlXPathRunEval()
13053 xmlXPathCompOpEval(ctxt, &comp->steps[comp->last]); in xmlXPathRunEval()
13054 ctxt->context->depth = oldDepth; in xmlXPathRunEval()
13084 switch (res->type) { in xmlXPathEvalPredicate()
13086 return(res->boolval); in xmlXPathEvalPredicate()
13088 return(res->floatval == ctxt->proximityPosition); in xmlXPathEvalPredicate()
13091 if (res->nodesetval == NULL) in xmlXPathEvalPredicate()
13093 return(res->nodesetval->nodeNr != 0); in xmlXPathEvalPredicate()
13095 return((res->stringval != NULL) && in xmlXPathEvalPredicate()
13096 (xmlStrlen(res->stringval) != 0)); in xmlXPathEvalPredicate()
13123 switch (res->type) { in xmlXPathEvaluatePredicateResult()
13125 return(res->boolval); in xmlXPathEvaluatePredicateResult()
13128 return((res->floatval == ctxt->context->proximityPosition) && in xmlXPathEvaluatePredicateResult()
13129 (!xmlXPathIsNaN(res->floatval))); /* MSC pbm Mark Vakoc !*/ in xmlXPathEvaluatePredicateResult()
13131 return(res->floatval == ctxt->context->proximityPosition); in xmlXPathEvaluatePredicateResult()
13135 if (res->nodesetval == NULL) in xmlXPathEvaluatePredicateResult()
13137 return(res->nodesetval->nodeNr != 0); in xmlXPathEvaluatePredicateResult()
13139 return((res->stringval != NULL) && (res->stringval[0] != 0)); in xmlXPathEvaluatePredicateResult()
13142 xmlLocationSetPtr ptr = res->user; in xmlXPathEvaluatePredicateResult()
13145 return (ptr->locNr != 0); in xmlXPathEvaluatePredicateResult()
13192 ((ctxt == NULL) || (ctxt->nsNr == 0) || (tmp[1] == ':'))) in xmlXPathTryStreamCompile()
13196 dict = ctxt->dict; in xmlXPathTryStreamCompile()
13197 if (ctxt->nsNr > 0) { in xmlXPathTryStreamCompile()
13198 namespaces = xmlMalloc(2 * (ctxt->nsNr + 1) * sizeof(xmlChar*)); in xmlXPathTryStreamCompile()
13203 for (i = 0, j = 0; (j < ctxt->nsNr); j++) { in xmlXPathTryStreamCompile()
13204 ns = ctxt->namespaces[j]; in xmlXPathTryStreamCompile()
13205 namespaces[i++] = ns->href; in xmlXPathTryStreamCompile()
13206 namespaces[i++] = ns->prefix; in xmlXPathTryStreamCompile()
13224 comp->stream = stream; in xmlXPathTryStreamCompile()
13225 comp->dict = dict; in xmlXPathTryStreamCompile()
13226 if (comp->dict) in xmlXPathTryStreamCompile()
13227 xmlDictReference(comp->dict); in xmlXPathTryStreamCompile()
13240 xmlXPathCompExprPtr comp = pctxt->comp; in xmlXPathOptimizeExpression()
13244 * Try to rewrite "descendant-or-self::node()/foo" to an optimized in xmlXPathOptimizeExpression()
13248 if ((op->op == XPATH_OP_COLLECT /* 11 */) && in xmlXPathOptimizeExpression()
13249 (op->ch1 != -1) && in xmlXPathOptimizeExpression()
13250 (op->ch2 == -1 /* no predicate */)) in xmlXPathOptimizeExpression()
13252 xmlXPathStepOpPtr prevop = &comp->steps[op->ch1]; in xmlXPathOptimizeExpression()
13254 if ((prevop->op == XPATH_OP_COLLECT /* 11 */) && in xmlXPathOptimizeExpression()
13255 ((xmlXPathAxisVal) prevop->value == in xmlXPathOptimizeExpression()
13257 (prevop->ch2 == -1) && in xmlXPathOptimizeExpression()
13258 ((xmlXPathTestVal) prevop->value2 == NODE_TEST_TYPE) && in xmlXPathOptimizeExpression()
13259 ((xmlXPathTypeVal) prevop->value3 == NODE_TYPE_NODE)) in xmlXPathOptimizeExpression()
13262 * This is a "descendant-or-self::node()" without predicates. in xmlXPathOptimizeExpression()
13266 switch ((xmlXPathAxisVal) op->value) { in xmlXPathOptimizeExpression()
13270 * Convert "descendant-or-self::node()/child::" or in xmlXPathOptimizeExpression()
13271 * "descendant-or-self::node()/descendant::" to in xmlXPathOptimizeExpression()
13274 op->ch1 = prevop->ch1; in xmlXPathOptimizeExpression()
13275 op->value = AXIS_DESCENDANT; in xmlXPathOptimizeExpression()
13280 * Convert "descendant-or-self::node()/self::" or in xmlXPathOptimizeExpression()
13281 * "descendant-or-self::node()/descendant-or-self::" to in xmlXPathOptimizeExpression()
13282 * to "descendant-or-self::" in xmlXPathOptimizeExpression()
13284 op->ch1 = prevop->ch1; in xmlXPathOptimizeExpression()
13285 op->value = AXIS_DESCENDANT_OR_SELF; in xmlXPathOptimizeExpression()
13294 if (op->op == XPATH_OP_VALUE) in xmlXPathOptimizeExpression()
13298 ctxt = pctxt->context; in xmlXPathOptimizeExpression()
13300 if (ctxt->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathOptimizeExpression()
13302 ctxt->depth += 1; in xmlXPathOptimizeExpression()
13304 if (op->ch1 != -1) in xmlXPathOptimizeExpression()
13305 xmlXPathOptimizeExpression(pctxt, &comp->steps[op->ch1]); in xmlXPathOptimizeExpression()
13306 if (op->ch2 != -1) in xmlXPathOptimizeExpression()
13307 xmlXPathOptimizeExpression(pctxt, &comp->steps[op->ch2]); in xmlXPathOptimizeExpression()
13309 ctxt->depth -= 1; in xmlXPathOptimizeExpression()
13340 oldDepth = ctxt->depth; in xmlXPathCtxtCompile()
13343 ctxt->depth = oldDepth; in xmlXPathCtxtCompile()
13345 if( pctxt->error != XPATH_EXPRESSION_OK ) in xmlXPathCtxtCompile()
13351 if (*pctxt->cur != 0) { in xmlXPathCtxtCompile()
13356 * out in other places. It's not critical so we leave it as-is for now in xmlXPathCtxtCompile()
13361 comp = pctxt->comp; in xmlXPathCtxtCompile()
13362 if ((comp->nbStep > 1) && (comp->last >= 0)) { in xmlXPathCtxtCompile()
13364 oldDepth = ctxt->depth; in xmlXPathCtxtCompile()
13365 xmlXPathOptimizeExpression(pctxt, &comp->steps[comp->last]); in xmlXPathCtxtCompile()
13367 ctxt->depth = oldDepth; in xmlXPathCtxtCompile()
13369 pctxt->comp = NULL; in xmlXPathCtxtCompile()
13374 comp->expr = xmlStrdup(str); in xmlXPathCtxtCompile()
13422 return(-1); in xmlXPathCompiledEvalInternal()
13433 return(-1); in xmlXPathCompiledEvalInternal()
13436 if (pctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompiledEvalInternal()
13444 } else if (pctxt->valueNr > 0) { in xmlXPathCompiledEvalInternal()
13447 pctxt->valueNr); in xmlXPathCompiledEvalInternal()
13456 pctxt->comp = NULL; in xmlXPathCompiledEvalInternal()
13459 reentance--; in xmlXPathCompiledEvalInternal()
13493 * -1 in API and internal errors.
13519 comp = xmlXPathTryStreamCompile(ctxt->context, ctxt->base); in xmlXPathEvalExpr()
13521 if (ctxt->comp != NULL) in xmlXPathEvalExpr()
13522 xmlXPathFreeCompExpr(ctxt->comp); in xmlXPathEvalExpr()
13523 ctxt->comp = comp; in xmlXPathEvalExpr()
13527 if (ctxt->context != NULL) in xmlXPathEvalExpr()
13528 oldDepth = ctxt->context->depth; in xmlXPathEvalExpr()
13530 if (ctxt->context != NULL) in xmlXPathEvalExpr()
13531 ctxt->context->depth = oldDepth; in xmlXPathEvalExpr()
13535 if (*ctxt->cur != 0) in xmlXPathEvalExpr()
13538 if ((ctxt->comp->nbStep > 1) && (ctxt->comp->last >= 0)) { in xmlXPathEvalExpr()
13539 if (ctxt->context != NULL) in xmlXPathEvalExpr()
13540 oldDepth = ctxt->context->depth; in xmlXPathEvalExpr()
13542 &ctxt->comp->steps[ctxt->comp->last]); in xmlXPathEvalExpr()
13543 if (ctxt->context != NULL) in xmlXPathEvalExpr()
13544 ctxt->context->depth = oldDepth; in xmlXPathEvalExpr()
13575 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathEval()
13582 } else if (ctxt->valueNr > 0) { in xmlXPathEval()
13585 ctxt->valueNr); in xmlXPathEval()
13601 * Returns -1 in case of error or 0 if successful
13606 return(-1); in xmlXPathSetContextNode()
13608 if (node->doc == ctx->doc) { in xmlXPathSetContextNode()
13609 ctx->node = node; in xmlXPathSetContextNode()
13612 return(-1); in xmlXPathSetContextNode()
13661 * Implement the escape-uri() XPath function
13662 * string escape-uri(string $str, bool $escape-reserved)
13665 * 2396] to the string supplied as $uri-part, which typically represents all
13669 * represent the character in UTF-8.
13672 * boolean argument $escape-reserved.
13674 * If $escape-reserved is true, all characters are escaped other than lower
13675 * case letters a-z, upper case letters A-Z, digits 0-9, and the characters
13676 * referred to in [RFC 2396] as "marks": specifically, "-" | "_" | "." | "!"
13678 * if it is not followed by two hexadecimal digits (that is, 0-9, a-f, and
13679 * A-F).
13681 * If $escape-reserved is false, the behavior differs in that characters
13688 * the upper-case letters A-F.
13690 * Generally, $escape-reserved should be set to true when escaping a string
13694 * In the case of non-ascii characters, the string is encoded according to
13695 * utf-8 and then converted according to RFC 2396.
13698 …* xf:escape-uri ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"), t…
13700 …* xf:escape-uri ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"), f…
13725 for (cptr = str->stringval; *cptr; cptr++) { in xmlXPathEscapeUriFunction()
13729 *cptr == '-' || *cptr == '_' || *cptr == '.' || in xmlXPathEscapeUriFunction()
13749 escape[1] = 'A' - 10 + (*cptr >> 4); in xmlXPathEscapeUriFunction()
13753 escape[2] = 'A' - 10 + (*cptr & 0xF); in xmlXPathEscapeUriFunction()
13759 valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, in xmlXPathEscapeUriFunction()
13762 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathEscapeUriFunction()
13794 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"local-name", in xmlXPathRegisterAllFunctions()
13800 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"namespace-uri", in xmlXPathRegisterAllFunctions()
13802 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"normalize-space", in xmlXPathRegisterAllFunctions()
13812 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"string-length", in xmlXPathRegisterAllFunctions()
13814 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"starts-with", in xmlXPathRegisterAllFunctions()
13818 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring-before", in xmlXPathRegisterAllFunctions()
13820 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring-after", in xmlXPathRegisterAllFunctions()
13829 xmlXPathRegisterFuncNS(ctxt, (const xmlChar *)"escape-uri", in xmlXPathRegisterAllFunctions()
13830 (const xmlChar *)"http://www.w3.org/2002/08/xquery-functions", in xmlXPathRegisterAllFunctions()