• 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")
71 * non-element nodes; actually it will speed up comparison only if
161 ATTRIBUTE_NO_SANITIZE("float-divide-by-zero")
167 xmlXPathNINF = -INFINITY; in xmlInitXPathInternal()
173 xmlXPathNINF = -xmlXPathPINF; in xmlInitXPathInternal()
200 * Returns 1 if the value is +Infinite, -1 if -Infinite, 0 otherwise
205 return isinf(val) ? (val > 0 ? 1 : -1) : 0; in xmlXPathIsInf()
209 if (val <= -xmlXPathPINF) in xmlXPathIsInf()
210 return -1; in xmlXPathIsInf()
251 * This one is optimized for handling of non-element nodes.
253 * Returns -2 in case of error 1 if first point < second point, 0 if
254 * it's the same node, -1 otherwise
265 return(-2); in xmlXPathCmpNodesExt()
273 switch (node1->type) { in xmlXPathCmpNodesExt()
275 if (node2->type == XML_ELEMENT_NODE) { in xmlXPathCmpNodesExt()
276 if ((0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodesExt()
277 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodesExt()
278 (node1->doc == node2->doc)) in xmlXPathCmpNodesExt()
280 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodesExt()
281 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodesExt()
285 return(-1); in xmlXPathCmpNodesExt()
293 node1 = node1->parent; in xmlXPathCmpNodesExt()
304 if (node1->prev != NULL) { in xmlXPathCmpNodesExt()
306 node1 = node1->prev; in xmlXPathCmpNodesExt()
307 if (node1->type == XML_ELEMENT_NODE) { in xmlXPathCmpNodesExt()
308 precedence1 = 3; /* element in prev-sibl axis */ in xmlXPathCmpNodesExt()
311 if (node1->prev == NULL) { in xmlXPathCmpNodesExt()
317 node1 = node1->parent; in xmlXPathCmpNodesExt()
323 node1 = node1->parent; in xmlXPathCmpNodesExt()
325 if ((node1 == NULL) || (node1->type != XML_ELEMENT_NODE) || in xmlXPathCmpNodesExt()
326 (0 <= (ptrdiff_t) node1->content)) { in xmlXPathCmpNodesExt()
344 switch (node2->type) { in xmlXPathCmpNodesExt()
350 node2 = node2->parent; in xmlXPathCmpNodesExt()
358 if (node2->prev != NULL) { in xmlXPathCmpNodesExt()
360 node2 = node2->prev; in xmlXPathCmpNodesExt()
361 if (node2->type == XML_ELEMENT_NODE) { in xmlXPathCmpNodesExt()
362 precedence2 = 3; /* element in prev-sibl axis */ in xmlXPathCmpNodesExt()
365 if (node2->prev == NULL) { in xmlXPathCmpNodesExt()
367 node2 = node2->parent; in xmlXPathCmpNodesExt()
373 node2 = node2->parent; in xmlXPathCmpNodesExt()
375 if ((node2 == NULL) || (node2->type != XML_ELEMENT_NODE) || in xmlXPathCmpNodesExt()
376 (0 <= (ptrdiff_t) node2->content)) in xmlXPathCmpNodesExt()
394 * adjacent non-element nodes around. in xmlXPathCmpNodesExt()
396 cur = miscNode2->prev; in xmlXPathCmpNodesExt()
400 if (cur->type == XML_ELEMENT_NODE) in xmlXPathCmpNodesExt()
401 return(-1); in xmlXPathCmpNodesExt()
402 cur = cur->prev; in xmlXPathCmpNodesExt()
404 return (-1); in xmlXPathCmpNodesExt()
414 return(-1); in xmlXPathCmpNodesExt()
418 * Special case: One of the helper-elements is contained by the other. in xmlXPathCmpNodesExt()
421 * <node1>Text-1(precedence1 == 2)</node1> in xmlXPathCmpNodesExt()
423 * Text-6(precedence2 == 3) in xmlXPathCmpNodesExt()
427 cur = node1->parent; in xmlXPathCmpNodesExt()
431 cur = cur->parent; in xmlXPathCmpNodesExt()
435 cur = node2->parent; in xmlXPathCmpNodesExt()
438 return(-1); in xmlXPathCmpNodesExt()
439 cur = cur->parent; in xmlXPathCmpNodesExt()
447 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
448 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
449 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodesExt()
450 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodesExt()
451 (node1->doc == node2->doc)) { in xmlXPathCmpNodesExt()
453 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodesExt()
454 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodesExt()
458 return(-1); in xmlXPathCmpNodesExt()
463 if (node1 == node2->prev) in xmlXPathCmpNodesExt()
465 if (node1 == node2->next) in xmlXPathCmpNodesExt()
466 return(-1); in xmlXPathCmpNodesExt()
470 for (depth2 = 0, cur = node2; cur->parent != NULL; cur = cur->parent) { in xmlXPathCmpNodesExt()
471 if (cur->parent == node1) in xmlXPathCmpNodesExt()
476 for (depth1 = 0, cur = node1; cur->parent != NULL; cur = cur->parent) { in xmlXPathCmpNodesExt()
477 if (cur->parent == node2) in xmlXPathCmpNodesExt()
478 return(-1); in xmlXPathCmpNodesExt()
482 * Distinct document (or distinct entities :-( ) case. in xmlXPathCmpNodesExt()
485 return(-2); in xmlXPathCmpNodesExt()
491 depth1--; in xmlXPathCmpNodesExt()
492 node1 = node1->parent; in xmlXPathCmpNodesExt()
495 depth2--; in xmlXPathCmpNodesExt()
496 node2 = node2->parent; in xmlXPathCmpNodesExt()
498 while (node1->parent != node2->parent) { in xmlXPathCmpNodesExt()
499 node1 = node1->parent; in xmlXPathCmpNodesExt()
500 node2 = node2->parent; in xmlXPathCmpNodesExt()
503 return(-2); in xmlXPathCmpNodesExt()
508 if (node1 == node2->prev) in xmlXPathCmpNodesExt()
510 if (node1 == node2->next) in xmlXPathCmpNodesExt()
511 return(-1); in xmlXPathCmpNodesExt()
515 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
516 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodesExt()
517 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodesExt()
518 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodesExt()
519 (node1->doc == node2->doc)) { in xmlXPathCmpNodesExt()
521 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodesExt()
522 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodesExt()
526 return(-1); in xmlXPathCmpNodesExt()
529 for (cur = node1->next;cur != NULL;cur = cur->next) in xmlXPathCmpNodesExt()
532 return(-1); /* assume there is no sibling list corruption */ in xmlXPathCmpNodesExt()
549 * Returns -2 in case of error -1 if first point < second point, 0 if
558 return res == -2 ? res : -res; in wrap_cmp()
564 return res == -2 ? res : -res; in wrap_cmp()
620 sizeof(xmlXPathErrorMessages[0])) - 1)
632 xmlRaiseMemoryError(ctxt->error, NULL, ctxt->userData, XML_FROM_XPATH, in xmlXPathErrMemory()
633 &ctxt->lastError); in xmlXPathErrMemory()
647 ctxt->error = XPATH_MEMORY_ERROR; in xmlXPathPErrMemory()
648 xmlXPathErrMemory(ctxt->context); in xmlXPathPErrMemory()
672 if (ctxt->error != 0) in xmlXPathErr()
675 ctxt->error = code; in xmlXPathErr()
677 if (ctxt->context != NULL) { in xmlXPathErr()
678 xmlErrorPtr err = &ctxt->context->lastError; in xmlXPathErr()
681 if (err->code == XML_ERR_NO_MEMORY) in xmlXPathErr()
687 err->domain = XML_FROM_XPATH; in xmlXPathErr()
688 err->code = code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK; in xmlXPathErr()
689 err->level = XML_ERR_ERROR; in xmlXPathErr()
690 if (ctxt->base != NULL) { in xmlXPathErr()
691 err->str1 = (char *) xmlStrdup(ctxt->base); in xmlXPathErr()
692 if (err->str1 == NULL) { in xmlXPathErr()
697 err->int1 = ctxt->cur - ctxt->base; in xmlXPathErr()
698 err->node = ctxt->context->debugNode; in xmlXPathErr()
700 schannel = ctxt->context->error; in xmlXPathErr()
701 data = ctxt->context->userData; in xmlXPathErr()
702 node = ctxt->context->debugNode; in xmlXPathErr()
711 code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, in xmlXPathErr()
713 (const char *) ctxt->base, NULL, NULL, in xmlXPathErr()
714 ctxt->cur - ctxt->base, 0, in xmlXPathErr()
740 * Adds opCount to the running total of operations and returns -1 if the
745 xmlXPathContextPtr xpctxt = ctxt->context; in xmlXPathCheckOpLimit()
747 if ((opCount > xpctxt->opLimit) || in xmlXPathCheckOpLimit()
748 (xpctxt->opCount > xpctxt->opLimit - opCount)) { in xmlXPathCheckOpLimit()
749 xpctxt->opCount = xpctxt->opLimit; in xmlXPathCheckOpLimit()
751 return(-1); in xmlXPathCheckOpLimit()
754 xpctxt->opCount += opCount; in xmlXPathCheckOpLimit()
759 ((ctxt->context->opLimit != 0) && (xmlXPathCheckOpLimit(ctxt, n) < 0))
890 cur->maxStep = 10; in xmlXPathNewCompExpr()
891 cur->nbStep = 0; in xmlXPathNewCompExpr()
892 cur->steps = (xmlXPathStepOp *) xmlMalloc(cur->maxStep * in xmlXPathNewCompExpr()
894 if (cur->steps == NULL) { in xmlXPathNewCompExpr()
898 memset(cur->steps, 0, cur->maxStep * sizeof(xmlXPathStepOp)); in xmlXPathNewCompExpr()
899 cur->last = -1; in xmlXPathNewCompExpr()
917 if (comp->dict == NULL) { in xmlXPathFreeCompExpr()
918 for (i = 0; i < comp->nbStep; i++) { in xmlXPathFreeCompExpr()
919 op = &comp->steps[i]; in xmlXPathFreeCompExpr()
920 if (op->value4 != NULL) { in xmlXPathFreeCompExpr()
921 if (op->op == XPATH_OP_VALUE) in xmlXPathFreeCompExpr()
922 xmlXPathFreeObject(op->value4); in xmlXPathFreeCompExpr()
924 xmlFree(op->value4); in xmlXPathFreeCompExpr()
926 if (op->value5 != NULL) in xmlXPathFreeCompExpr()
927 xmlFree(op->value5); in xmlXPathFreeCompExpr()
930 for (i = 0; i < comp->nbStep; i++) { in xmlXPathFreeCompExpr()
931 op = &comp->steps[i]; in xmlXPathFreeCompExpr()
932 if (op->value4 != NULL) { in xmlXPathFreeCompExpr()
933 if (op->op == XPATH_OP_VALUE) in xmlXPathFreeCompExpr()
934 xmlXPathFreeObject(op->value4); in xmlXPathFreeCompExpr()
937 xmlDictFree(comp->dict); in xmlXPathFreeCompExpr()
939 if (comp->steps != NULL) { in xmlXPathFreeCompExpr()
940 xmlFree(comp->steps); in xmlXPathFreeCompExpr()
943 if (comp->stream != NULL) { in xmlXPathFreeCompExpr()
944 xmlFreePatternList(comp->stream); in xmlXPathFreeCompExpr()
947 if (comp->expr != NULL) { in xmlXPathFreeCompExpr()
948 xmlFree(comp->expr); in xmlXPathFreeCompExpr()
968 * Returns -1 in case of failure, the index otherwise
974 xmlXPathCompExprPtr comp = ctxt->comp; in xmlXPathCompExprAdd()
975 if (comp->nbStep >= comp->maxStep) { in xmlXPathCompExprAdd()
978 if (comp->maxStep >= XPATH_MAX_STEPS) { in xmlXPathCompExprAdd()
980 return(-1); in xmlXPathCompExprAdd()
982 comp->maxStep *= 2; in xmlXPathCompExprAdd()
983 real = (xmlXPathStepOp *) xmlRealloc(comp->steps, in xmlXPathCompExprAdd()
984 comp->maxStep * sizeof(xmlXPathStepOp)); in xmlXPathCompExprAdd()
986 comp->maxStep /= 2; in xmlXPathCompExprAdd()
988 return(-1); in xmlXPathCompExprAdd()
990 comp->steps = real; in xmlXPathCompExprAdd()
992 comp->last = comp->nbStep; in xmlXPathCompExprAdd()
993 comp->steps[comp->nbStep].ch1 = ch1; in xmlXPathCompExprAdd()
994 comp->steps[comp->nbStep].ch2 = ch2; in xmlXPathCompExprAdd()
995 comp->steps[comp->nbStep].op = op; in xmlXPathCompExprAdd()
996 comp->steps[comp->nbStep].value = value; in xmlXPathCompExprAdd()
997 comp->steps[comp->nbStep].value2 = value2; in xmlXPathCompExprAdd()
998 comp->steps[comp->nbStep].value3 = value3; in xmlXPathCompExprAdd()
999 if ((comp->dict != NULL) && in xmlXPathCompExprAdd()
1003 comp->steps[comp->nbStep].value4 = (xmlChar *) in xmlXPathCompExprAdd()
1004 (void *)xmlDictLookup(comp->dict, value4, -1); in xmlXPathCompExprAdd()
1007 comp->steps[comp->nbStep].value4 = NULL; in xmlXPathCompExprAdd()
1009 comp->steps[comp->nbStep].value5 = (xmlChar *) in xmlXPathCompExprAdd()
1010 (void *)xmlDictLookup(comp->dict, value5, -1); in xmlXPathCompExprAdd()
1013 comp->steps[comp->nbStep].value5 = NULL; in xmlXPathCompExprAdd()
1015 comp->steps[comp->nbStep].value4 = value4; in xmlXPathCompExprAdd()
1016 comp->steps[comp->nbStep].value5 = value5; in xmlXPathCompExprAdd()
1018 comp->steps[comp->nbStep].cache = NULL; in xmlXPathCompExprAdd()
1019 return(comp->nbStep++); in xmlXPathCompExprAdd()
1043 tmp = op->ch1; in xmlXPathCompSwap()
1044 op->ch1 = op->ch2; in xmlXPathCompSwap()
1045 op->ch2 = tmp; in xmlXPathCompSwap()
1052 xmlXPathCompExprAdd(ctxt, ctxt->comp->last, -1, \
1056 xmlXPathCompExprAdd(ctxt, -1, -1, (op), (val), (val2), 0 ,NULL ,NULL)
1059 xmlXPathCompExprAdd(ctxt, (ch), -1, (op), (val), (val2), 0 ,NULL ,NULL)
1106 if ((cur->type == XML_DOCUMENT_NODE) || in xmlXPathDebugDumpNode()
1107 (cur->type == XML_HTML_DOCUMENT_NODE)) { in xmlXPathDebugDumpNode()
1110 } else if (cur->type == XML_ATTRIBUTE_NODE) in xmlXPathDebugDumpNode()
1133 cur = cur->next; in xmlXPathDebugDumpNodeList()
1155 fprintf(output, "Set contains %d nodes:\n", cur->nodeNr); in xmlXPathDebugDumpNodeSet()
1156 for (i = 0;i < cur->nodeNr;i++) { in xmlXPathDebugDumpNodeSet()
1159 xmlXPathDebugDumpNode(output, cur->nodeTab[i], depth + 1); in xmlXPathDebugDumpNodeSet()
1173 if ((cur == NULL) || (cur->nodeNr == 0) || (cur->nodeTab[0] == NULL)) { in xmlXPathDebugDumpValueTree()
1182 xmlXPathDebugDumpNodeList(output, cur->nodeTab[0]->children, depth + 1); in xmlXPathDebugDumpValueTree()
1211 switch(cur->type) { in xmlXPathDebugDumpObject()
1217 xmlXPathDebugDumpNodeSet(output, cur->nodesetval, depth); in xmlXPathDebugDumpObject()
1221 xmlXPathDebugDumpValueTree(output, cur->nodesetval, depth); in xmlXPathDebugDumpObject()
1225 if (cur->boolval) fprintf(output, "true\n"); in xmlXPathDebugDumpObject()
1229 switch (xmlXPathIsInf(cur->floatval)) { in xmlXPathDebugDumpObject()
1233 case -1: in xmlXPathDebugDumpObject()
1234 fprintf(output, "Object is a number : -Infinity\n"); in xmlXPathDebugDumpObject()
1237 if (xmlXPathIsNaN(cur->floatval)) { in xmlXPathDebugDumpObject()
1239 } else if (cur->floatval == 0) { in xmlXPathDebugDumpObject()
1243 fprintf(output, "Object is a number : %0g\n", cur->floatval); in xmlXPathDebugDumpObject()
1249 xmlDebugDumpString(output, cur->stringval); in xmlXPathDebugDumpObject()
1273 switch (op->op) { in xmlXPathDebugDumpStepOp()
1281 if (op->value) in xmlXPathDebugDumpStepOp()
1287 if (op->value) in xmlXPathDebugDumpStepOp()
1291 if (!op->value2) in xmlXPathDebugDumpStepOp()
1295 if (op->value == 0) in xmlXPathDebugDumpStepOp()
1296 fprintf(output, "PLUS -"); in xmlXPathDebugDumpStepOp()
1297 else if (op->value == 1) in xmlXPathDebugDumpStepOp()
1299 else if (op->value == 2) in xmlXPathDebugDumpStepOp()
1300 fprintf(output, "PLUS unary -"); in xmlXPathDebugDumpStepOp()
1301 else if (op->value == 3) in xmlXPathDebugDumpStepOp()
1302 fprintf(output, "PLUS unary - -"); in xmlXPathDebugDumpStepOp()
1305 if (op->value == 0) in xmlXPathDebugDumpStepOp()
1307 else if (op->value == 1) in xmlXPathDebugDumpStepOp()
1321 xmlXPathAxisVal axis = (xmlXPathAxisVal)op->value; in xmlXPathDebugDumpStepOp()
1322 xmlXPathTestVal test = (xmlXPathTestVal)op->value2; in xmlXPathDebugDumpStepOp()
1323 xmlXPathTypeVal type = (xmlXPathTypeVal)op->value3; in xmlXPathDebugDumpStepOp()
1324 const xmlChar *prefix = op->value4; in xmlXPathDebugDumpStepOp()
1325 const xmlChar *name = op->value5; in xmlXPathDebugDumpStepOp()
1332 fprintf(output, " 'ancestors-or-self' "); break; in xmlXPathDebugDumpStepOp()
1340 fprintf(output, " 'descendant-or-self' "); break; in xmlXPathDebugDumpStepOp()
1344 fprintf(output, " 'following-siblings' "); break; in xmlXPathDebugDumpStepOp()
1352 fprintf(output, " 'preceding-sibling' "); break; in xmlXPathDebugDumpStepOp()
1388 xmlXPathObjectPtr object = (xmlXPathObjectPtr) op->value4; in xmlXPathDebugDumpStepOp()
1395 const xmlChar *prefix = op->value5; in xmlXPathDebugDumpStepOp()
1396 const xmlChar *name = op->value4; in xmlXPathDebugDumpStepOp()
1405 int nbargs = op->value; in xmlXPathDebugDumpStepOp()
1406 const xmlChar *prefix = op->value5; in xmlXPathDebugDumpStepOp()
1407 const xmlChar *name = op->value4; in xmlXPathDebugDumpStepOp()
1420 fprintf(output, "UNKNOWN %d\n", op->op); return; in xmlXPathDebugDumpStepOp()
1424 if (op->ch1 >= 0) in xmlXPathDebugDumpStepOp()
1425 xmlXPathDebugDumpStepOp(output, comp, &comp->steps[op->ch1], depth + 1); in xmlXPathDebugDumpStepOp()
1426 if (op->ch2 >= 0) in xmlXPathDebugDumpStepOp()
1427 xmlXPathDebugDumpStepOp(output, comp, &comp->steps[op->ch2], depth + 1); in xmlXPathDebugDumpStepOp()
1453 if (comp->stream) { in xmlXPathDebugDumpCompExpr()
1459 comp->nbStep); in xmlXPathDebugDumpCompExpr()
1460 i = comp->last; in xmlXPathDebugDumpCompExpr()
1461 xmlXPathDebugDumpStepOp(output, comp, &comp->steps[i], depth + 1); in xmlXPathDebugDumpCompExpr()
1489 ret->maxNodeset = 100; in xmlXPathNewCache()
1490 ret->maxMisc = 100; in xmlXPathNewCache()
1500 next = (void *) list->stringval; in xmlXPathCacheFreeObjectList()
1502 if (list->nodesetval != NULL) { in xmlXPathCacheFreeObjectList()
1503 if (list->nodesetval->nodeTab != NULL) in xmlXPathCacheFreeObjectList()
1504 xmlFree(list->nodesetval->nodeTab); in xmlXPathCacheFreeObjectList()
1505 xmlFree(list->nodesetval); in xmlXPathCacheFreeObjectList()
1518 if (cache->nodesetObjs) in xmlXPathFreeCache()
1519 xmlXPathCacheFreeObjectList(cache->nodesetObjs); in xmlXPathFreeCache()
1520 if (cache->miscObjs) in xmlXPathFreeCache()
1521 xmlXPathCacheFreeObjectList(cache->miscObjs); in xmlXPathFreeCache()
1541 * There are two slots for node-set and misc objects.
1545 * Returns 0 if the setting succeeded, and -1 on API or internal errors.
1554 return(-1); in xmlXPathContextSetCache()
1558 if (ctxt->cache == NULL) { in xmlXPathContextSetCache()
1559 ctxt->cache = xmlXPathNewCache(); in xmlXPathContextSetCache()
1560 if (ctxt->cache == NULL) { in xmlXPathContextSetCache()
1562 return(-1); in xmlXPathContextSetCache()
1565 cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathContextSetCache()
1569 cache->maxNodeset = value; in xmlXPathContextSetCache()
1570 cache->maxMisc = value; in xmlXPathContextSetCache()
1572 } else if (ctxt->cache != NULL) { in xmlXPathContextSetCache()
1573 xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache); in xmlXPathContextSetCache()
1574 ctxt->cache = NULL; in xmlXPathContextSetCache()
1595 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheWrapNodeSet()
1597 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheWrapNodeSet()
1599 (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheWrapNodeSet()
1601 if (cache->miscObjs != NULL) { in xmlXPathCacheWrapNodeSet()
1602 ret = cache->miscObjs; in xmlXPathCacheWrapNodeSet()
1603 cache->miscObjs = (void *) ret->stringval; in xmlXPathCacheWrapNodeSet()
1604 cache->numMisc -= 1; in xmlXPathCacheWrapNodeSet()
1605 ret->stringval = NULL; in xmlXPathCacheWrapNodeSet()
1606 ret->type = XPATH_NODESET; in xmlXPathCacheWrapNodeSet()
1607 ret->nodesetval = val; in xmlXPathCacheWrapNodeSet()
1632 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheWrapString()
1634 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheWrapString()
1635 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheWrapString()
1637 if (cache->miscObjs != NULL) { in xmlXPathCacheWrapString()
1638 ret = cache->miscObjs; in xmlXPathCacheWrapString()
1639 cache->miscObjs = (void *) ret->stringval; in xmlXPathCacheWrapString()
1640 cache->numMisc -= 1; in xmlXPathCacheWrapString()
1641 ret->type = XPATH_STRING; in xmlXPathCacheWrapString()
1642 ret->stringval = val; in xmlXPathCacheWrapString()
1668 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheNewNodeSet()
1670 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheNewNodeSet()
1671 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewNodeSet()
1673 if (cache->nodesetObjs != NULL) { in xmlXPathCacheNewNodeSet()
1675 * Use the nodeset-cache. in xmlXPathCacheNewNodeSet()
1677 ret = cache->nodesetObjs; in xmlXPathCacheNewNodeSet()
1678 cache->nodesetObjs = (void *) ret->stringval; in xmlXPathCacheNewNodeSet()
1679 cache->numNodeset -= 1; in xmlXPathCacheNewNodeSet()
1680 ret->stringval = NULL; in xmlXPathCacheNewNodeSet()
1681 ret->type = XPATH_NODESET; in xmlXPathCacheNewNodeSet()
1682 ret->boolval = 0; in xmlXPathCacheNewNodeSet()
1684 if ((ret->nodesetval->nodeMax == 0) || in xmlXPathCacheNewNodeSet()
1685 (val->type == XML_NAMESPACE_DECL)) in xmlXPathCacheNewNodeSet()
1687 if (xmlXPathNodeSetAddUnique(ret->nodesetval, val) < 0) in xmlXPathCacheNewNodeSet()
1690 ret->nodesetval->nodeTab[0] = val; in xmlXPathCacheNewNodeSet()
1691 ret->nodesetval->nodeNr = 1; in xmlXPathCacheNewNodeSet()
1695 } else if (cache->miscObjs != NULL) { in xmlXPathCacheNewNodeSet()
1698 * Fallback to misc-cache. in xmlXPathCacheNewNodeSet()
1707 ret = cache->miscObjs; in xmlXPathCacheNewNodeSet()
1708 cache->miscObjs = (void *) ret->stringval; in xmlXPathCacheNewNodeSet()
1709 cache->numMisc -= 1; in xmlXPathCacheNewNodeSet()
1710 ret->stringval = NULL; in xmlXPathCacheNewNodeSet()
1711 ret->type = XPATH_NODESET; in xmlXPathCacheNewNodeSet()
1712 ret->boolval = 0; in xmlXPathCacheNewNodeSet()
1713 ret->nodesetval = set; in xmlXPathCacheNewNodeSet()
1737 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheNewString()
1739 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheNewString()
1740 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewString()
1742 if (cache->miscObjs != NULL) { in xmlXPathCacheNewString()
1753 ret = cache->miscObjs; in xmlXPathCacheNewString()
1754 cache->miscObjs = (void *) ret->stringval; in xmlXPathCacheNewString()
1755 cache->numMisc -= 1; in xmlXPathCacheNewString()
1756 ret->type = XPATH_STRING; in xmlXPathCacheNewString()
1757 ret->stringval = copy; in xmlXPathCacheNewString()
1798 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheNewBoolean()
1800 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheNewBoolean()
1801 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewBoolean()
1803 if (cache->miscObjs != NULL) { in xmlXPathCacheNewBoolean()
1804 ret = cache->miscObjs; in xmlXPathCacheNewBoolean()
1805 cache->miscObjs = (void *) ret->stringval; in xmlXPathCacheNewBoolean()
1806 cache->numMisc -= 1; in xmlXPathCacheNewBoolean()
1807 ret->stringval = NULL; in xmlXPathCacheNewBoolean()
1808 ret->type = XPATH_BOOLEAN; in xmlXPathCacheNewBoolean()
1809 ret->boolval = (val != 0); in xmlXPathCacheNewBoolean()
1834 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheNewFloat()
1836 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheNewFloat()
1837 xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathCacheNewFloat()
1839 if (cache->miscObjs != NULL) { in xmlXPathCacheNewFloat()
1840 ret = cache->miscObjs; in xmlXPathCacheNewFloat()
1841 cache->miscObjs = (void *) ret->stringval; in xmlXPathCacheNewFloat()
1842 cache->numMisc -= 1; in xmlXPathCacheNewFloat()
1843 ret->stringval = NULL; in xmlXPathCacheNewFloat()
1844 ret->type = XPATH_NUMBER; in xmlXPathCacheNewFloat()
1845 ret->floatval = val; in xmlXPathCacheNewFloat()
1870 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathCacheObjectCopy()
1875 if ((ctxt != NULL) && (ctxt->cache != NULL)) { in xmlXPathCacheObjectCopy()
1876 switch (val->type) { in xmlXPathCacheObjectCopy()
1880 set = xmlXPathNodeSetMerge(NULL, val->nodesetval); in xmlXPathCacheObjectCopy()
1888 return(xmlXPathCacheNewString(pctxt, val->stringval)); in xmlXPathCacheObjectCopy()
1890 return(xmlXPathCacheNewBoolean(pctxt, val->boolval)); in xmlXPathCacheObjectCopy()
1892 return(xmlXPathCacheNewFloat(pctxt, val->floatval)); in xmlXPathCacheObjectCopy()
1925 switch (val->type) { in xmlXPathCastToNumberInternal()
1933 str = xmlXPathCastNodeSetToString(val->nodesetval); in xmlXPathCastToNumberInternal()
1944 ret = xmlXPathCastStringToNumber(val->stringval); in xmlXPathCastToNumberInternal()
1947 ret = val->floatval; in xmlXPathCastToNumberInternal()
1950 ret = xmlXPathCastBooleanToNumber(val->boolval); in xmlXPathCastToNumberInternal()
1973 if ((ctxt == NULL) || (ctxt->valueNr <= 0)) in valuePop()
1976 ctxt->valueNr--; in valuePop()
1977 if (ctxt->valueNr > 0) in valuePop()
1978 ctxt->value = ctxt->valueTab[ctxt->valueNr - 1]; in valuePop()
1980 ctxt->value = NULL; in valuePop()
1981 ret = ctxt->valueTab[ctxt->valueNr]; in valuePop()
1982 ctxt->valueTab[ctxt->valueNr] = NULL; in valuePop()
1993 * Returns the number of items on the value stack, or -1 in case of error.
2000 if (ctxt == NULL) return(-1); in valuePush()
2006 return(-1); in valuePush()
2008 if (ctxt->valueNr >= ctxt->valueMax) { in valuePush()
2011 if (ctxt->valueMax >= XPATH_MAX_STACK_DEPTH) { in valuePush()
2014 return (-1); in valuePush()
2016 tmp = (xmlXPathObjectPtr *) xmlRealloc(ctxt->valueTab, in valuePush()
2017 2 * ctxt->valueMax * in valuePush()
2018 sizeof(ctxt->valueTab[0])); in valuePush()
2022 return (-1); in valuePush()
2024 ctxt->valueMax *= 2; in valuePush()
2025 ctxt->valueTab = tmp; in valuePush()
2027 ctxt->valueTab[ctxt->valueNr] = value; in valuePush()
2028 ctxt->value = value; in valuePush()
2029 return (ctxt->valueNr++); in valuePush()
2051 if (obj->type != XPATH_BOOLEAN) in xmlXPathPopBoolean()
2054 ret = obj->boolval; in xmlXPathPopBoolean()
2055 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopBoolean()
2078 if (obj->type != XPATH_NUMBER) in xmlXPathPopNumber()
2081 ret = obj->floatval; in xmlXPathPopNumber()
2082 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopNumber()
2108 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopString()
2116 * Pops a node-set from the stack, handling conversion if needed.
2119 * Returns the node-set
2127 if (ctxt->value == NULL) { in xmlXPathPopNodeSet()
2136 ret = obj->nodesetval; in xmlXPathPopNodeSet()
2138 /* to fix memory leak of not clearing obj->user */ in xmlXPathPopNodeSet()
2139 if (obj->boolval && obj->user != NULL) in xmlXPathPopNodeSet()
2140 xmlFreeNodeList((xmlNodePtr) obj->user); in xmlXPathPopNodeSet()
2142 obj->nodesetval = NULL; in xmlXPathPopNodeSet()
2143 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopNodeSet()
2161 if ((ctxt == NULL) || (ctxt->value == NULL)) { in xmlXPathPopExternal()
2165 if (ctxt->value->type != XPATH_USERS) { in xmlXPathPopExternal()
2170 ret = obj->user; in xmlXPathPopExternal()
2171 obj->user = NULL; in xmlXPathPopExternal()
2172 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathPopExternal()
2184 * in ISO-Latin or UTF-8.
2187 * running with UTF-8 encoding.
2193 * UTF-8 if we are using this mode. It returns an int.
2195 * in UTF-8 mode. It also pop-up unfinished entities on the fly.
2199 #define CUR (*ctxt->cur)
2200 #define SKIP(val) ctxt->cur += (val)
2201 #define NXT(val) ctxt->cur[(val)]
2202 #define CUR_PTR ctxt->cur
2209 #define NEXTL(l) ctxt->cur += l
2212 while (IS_BLANK_CH(*(ctxt->cur))) NEXT
2214 #define CURRENT (*ctxt->cur)
2215 #define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
2222 #define DBL_EPSILON 1E-9
2226 #define LOWER_DOUBLE 1E-5
2249 case -1: in xmlXPathFormatNumber()
2250 if (buffersize > (int)sizeof("-Infinity")) in xmlXPathFormatNumber()
2251 snprintf(buffer, buffersize, "-Infinity"); in xmlXPathFormatNumber()
2272 while ((*cur) && (ptr - buffer < buffersize)) { in xmlXPathFormatNumber()
2276 if (ptr - buffer < buffersize) { in xmlXPathFormatNumber()
2279 ptr--; in xmlXPathFormatNumber()
2302 * First choose format - scientific or regular floating point. in xmlXPathFormatNumber()
2311 fraction_place = DBL_DIG - 1; in xmlXPathFormatNumber()
2314 while ((size > 0) && (work[size] != 'e')) size--; in xmlXPathFormatNumber()
2322 fraction_place = DBL_DIG - integer_place - 1; in xmlXPathFormatNumber()
2324 fraction_place = DBL_DIG - integer_place; in xmlXPathFormatNumber()
2335 size--; in xmlXPathFormatNumber()
2341 while (*(--ptr) == '0') in xmlXPathFormatNumber()
2350 work[buffersize - 1] = 0; in xmlXPathFormatNumber()
2372 * Like for line information, the order is kept in the element->content
2373 * field, the value stored is actually - the node number (starting at -1)
2376 * Returns the number of elements found in the document or -1 in case
2385 return(-1); in xmlXPathOrderDocElems()
2386 cur = doc->children; in xmlXPathOrderDocElems()
2388 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathOrderDocElems()
2389 cur->content = (void *) (-(++count)); in xmlXPathOrderDocElems()
2390 if (cur->children != NULL) { in xmlXPathOrderDocElems()
2391 cur = cur->children; in xmlXPathOrderDocElems()
2395 if (cur->next != NULL) { in xmlXPathOrderDocElems()
2396 cur = cur->next; in xmlXPathOrderDocElems()
2400 cur = cur->parent; in xmlXPathOrderDocElems()
2407 if (cur->next != NULL) { in xmlXPathOrderDocElems()
2408 cur = cur->next; in xmlXPathOrderDocElems()
2423 * Returns -2 in case of error 1 if first point < second point, 0 if
2424 * it's the same node, -1 otherwise
2434 return(-2); in xmlXPathCmpNodes()
2440 if (node1->type == XML_ATTRIBUTE_NODE) { in xmlXPathCmpNodes()
2443 node1 = node1->parent; in xmlXPathCmpNodes()
2445 if (node2->type == XML_ATTRIBUTE_NODE) { in xmlXPathCmpNodes()
2448 node2 = node2->parent; in xmlXPathCmpNodes()
2454 cur = attrNode2->prev; in xmlXPathCmpNodes()
2458 cur = cur->prev; in xmlXPathCmpNodes()
2460 return (-1); in xmlXPathCmpNodes()
2466 return(-1); in xmlXPathCmpNodes()
2468 if ((node1->type == XML_NAMESPACE_DECL) || in xmlXPathCmpNodes()
2469 (node2->type == XML_NAMESPACE_DECL)) in xmlXPathCmpNodes()
2471 if (node1 == node2->prev) in xmlXPathCmpNodes()
2473 if (node1 == node2->next) in xmlXPathCmpNodes()
2474 return(-1); in xmlXPathCmpNodes()
2479 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2480 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2481 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodes()
2482 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodes()
2483 (node1->doc == node2->doc)) { in xmlXPathCmpNodes()
2486 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodes()
2487 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodes()
2491 return(-1); in xmlXPathCmpNodes()
2497 for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) { in xmlXPathCmpNodes()
2498 if (cur->parent == node1) in xmlXPathCmpNodes()
2503 for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) { in xmlXPathCmpNodes()
2504 if (cur->parent == node2) in xmlXPathCmpNodes()
2505 return(-1); in xmlXPathCmpNodes()
2509 * Distinct document (or distinct entities :-( ) case. in xmlXPathCmpNodes()
2512 return(-2); in xmlXPathCmpNodes()
2518 depth1--; in xmlXPathCmpNodes()
2519 node1 = node1->parent; in xmlXPathCmpNodes()
2522 depth2--; in xmlXPathCmpNodes()
2523 node2 = node2->parent; in xmlXPathCmpNodes()
2525 while (node1->parent != node2->parent) { in xmlXPathCmpNodes()
2526 node1 = node1->parent; in xmlXPathCmpNodes()
2527 node2 = node2->parent; in xmlXPathCmpNodes()
2530 return(-2); in xmlXPathCmpNodes()
2535 if (node1 == node2->prev) in xmlXPathCmpNodes()
2537 if (node1 == node2->next) in xmlXPathCmpNodes()
2538 return(-1); in xmlXPathCmpNodes()
2542 if ((node1->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2543 (node2->type == XML_ELEMENT_NODE) && in xmlXPathCmpNodes()
2544 (0 > (ptrdiff_t) node1->content) && in xmlXPathCmpNodes()
2545 (0 > (ptrdiff_t) node2->content) && in xmlXPathCmpNodes()
2546 (node1->doc == node2->doc)) { in xmlXPathCmpNodes()
2549 l1 = -((ptrdiff_t) node1->content); in xmlXPathCmpNodes()
2550 l2 = -((ptrdiff_t) node2->content); in xmlXPathCmpNodes()
2554 return(-1); in xmlXPathCmpNodes()
2557 for (cur = node1->next;cur != NULL;cur = cur->next) in xmlXPathCmpNodes()
2560 return(-1); /* assume there is no sibling list corruption */ in xmlXPathCmpNodes()
2581 * Use the old Shell's sort implementation to sort the node-set in xmlXPathNodeSetSort()
2584 len = set->nodeNr; in xmlXPathNodeSetSort()
2587 j = i - incr; in xmlXPathNodeSetSort()
2590 if (xmlXPathCmpNodesExt(set->nodeTab[j], in xmlXPathNodeSetSort()
2591 set->nodeTab[j + incr]) == -1) in xmlXPathNodeSetSort()
2593 if (xmlXPathCmpNodes(set->nodeTab[j], in xmlXPathNodeSetSort()
2594 set->nodeTab[j + incr]) == -1) in xmlXPathNodeSetSort()
2597 tmp = set->nodeTab[j]; in xmlXPathNodeSetSort()
2598 set->nodeTab[j] = set->nodeTab[j + incr]; in xmlXPathNodeSetSort()
2599 set->nodeTab[j + incr] = tmp; in xmlXPathNodeSetSort()
2600 j -= incr; in xmlXPathNodeSetSort()
2607 libxml_domnode_tim_sort(set->nodeTab, set->nodeNr); in xmlXPathNodeSetSort()
2627 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) in xmlXPathNodeSetDupNs()
2629 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetDupNs()
2639 cur->type = XML_NAMESPACE_DECL; in xmlXPathNodeSetDupNs()
2640 if (ns->href != NULL) { in xmlXPathNodeSetDupNs()
2641 cur->href = xmlStrdup(ns->href); in xmlXPathNodeSetDupNs()
2642 if (cur->href == NULL) { in xmlXPathNodeSetDupNs()
2647 if (ns->prefix != NULL) { in xmlXPathNodeSetDupNs()
2648 cur->prefix = xmlStrdup(ns->prefix); in xmlXPathNodeSetDupNs()
2649 if (cur->prefix == NULL) { in xmlXPathNodeSetDupNs()
2650 xmlFree((xmlChar *) cur->href); in xmlXPathNodeSetDupNs()
2655 cur->next = (xmlNsPtr) node; in xmlXPathNodeSetDupNs()
2669 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) in xmlXPathNodeSetFreeNs()
2672 if ((ns->next != NULL) && (ns->next->type != XML_NAMESPACE_DECL)) { in xmlXPathNodeSetFreeNs()
2673 if (ns->href != NULL) in xmlXPathNodeSetFreeNs()
2674 xmlFree((xmlChar *)ns->href); in xmlXPathNodeSetFreeNs()
2675 if (ns->prefix != NULL) in xmlXPathNodeSetFreeNs()
2676 xmlFree((xmlChar *)ns->prefix); in xmlXPathNodeSetFreeNs()
2698 ret->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetCreate()
2700 if (ret->nodeTab == NULL) { in xmlXPathNodeSetCreate()
2704 memset(ret->nodeTab, 0 , in xmlXPathNodeSetCreate()
2706 ret->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetCreate()
2707 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetCreate()
2709 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetCreate()
2715 ret->nodeTab[ret->nodeNr++] = nsNode; in xmlXPathNodeSetCreate()
2717 ret->nodeTab[ret->nodeNr++] = val; in xmlXPathNodeSetCreate()
2724 * @cur: the node-set
2736 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetContains()
2737 for (i = 0; i < cur->nodeNr; i++) { in xmlXPathNodeSetContains()
2738 if (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetContains()
2742 ns2 = (xmlNsPtr) cur->nodeTab[i]; in xmlXPathNodeSetContains()
2745 if ((ns1->next != NULL) && (ns2->next == ns1->next) && in xmlXPathNodeSetContains()
2746 (xmlStrEqual(ns1->prefix, ns2->prefix))) in xmlXPathNodeSetContains()
2751 for (i = 0; i < cur->nodeNr; i++) { in xmlXPathNodeSetContains()
2752 if (cur->nodeTab[i] == val) in xmlXPathNodeSetContains()
2767 * Returns 0 in case of success and -1 in case of error
2775 (ns->type != XML_NAMESPACE_DECL) || in xmlXPathNodeSetAddNs()
2776 (node->type != XML_ELEMENT_NODE)) in xmlXPathNodeSetAddNs()
2777 return(-1); in xmlXPathNodeSetAddNs()
2783 for (i = 0;i < cur->nodeNr;i++) { in xmlXPathNodeSetAddNs()
2784 if ((cur->nodeTab[i] != NULL) && in xmlXPathNodeSetAddNs()
2785 (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) && in xmlXPathNodeSetAddNs()
2786 (((xmlNsPtr)cur->nodeTab[i])->next == (xmlNsPtr) node) && in xmlXPathNodeSetAddNs()
2787 (xmlStrEqual(ns->prefix, ((xmlNsPtr)cur->nodeTab[i])->prefix))) in xmlXPathNodeSetAddNs()
2794 if (cur->nodeMax == 0) { in xmlXPathNodeSetAddNs()
2795 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetAddNs()
2797 if (cur->nodeTab == NULL) in xmlXPathNodeSetAddNs()
2798 return(-1); in xmlXPathNodeSetAddNs()
2799 memset(cur->nodeTab, 0 , in xmlXPathNodeSetAddNs()
2801 cur->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetAddNs()
2802 } else if (cur->nodeNr == cur->nodeMax) { in xmlXPathNodeSetAddNs()
2805 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) in xmlXPathNodeSetAddNs()
2806 return(-1); in xmlXPathNodeSetAddNs()
2807 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * in xmlXPathNodeSetAddNs()
2810 return(-1); in xmlXPathNodeSetAddNs()
2811 cur->nodeMax *= 2; in xmlXPathNodeSetAddNs()
2812 cur->nodeTab = temp; in xmlXPathNodeSetAddNs()
2816 return(-1); in xmlXPathNodeSetAddNs()
2817 cur->nodeTab[cur->nodeNr++] = nsNode; in xmlXPathNodeSetAddNs()
2828 * Returns 0 in case of success, and -1 in case of error
2834 if ((cur == NULL) || (val == NULL)) return(-1); in xmlXPathNodeSetAdd()
2840 for (i = 0;i < cur->nodeNr;i++) in xmlXPathNodeSetAdd()
2841 if (cur->nodeTab[i] == val) return(0); in xmlXPathNodeSetAdd()
2846 if (cur->nodeMax == 0) { in xmlXPathNodeSetAdd()
2847 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetAdd()
2849 if (cur->nodeTab == NULL) in xmlXPathNodeSetAdd()
2850 return(-1); in xmlXPathNodeSetAdd()
2851 memset(cur->nodeTab, 0 , in xmlXPathNodeSetAdd()
2853 cur->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetAdd()
2854 } else if (cur->nodeNr == cur->nodeMax) { in xmlXPathNodeSetAdd()
2857 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) in xmlXPathNodeSetAdd()
2858 return(-1); in xmlXPathNodeSetAdd()
2859 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * in xmlXPathNodeSetAdd()
2862 return(-1); in xmlXPathNodeSetAdd()
2863 cur->nodeMax *= 2; in xmlXPathNodeSetAdd()
2864 cur->nodeTab = temp; in xmlXPathNodeSetAdd()
2866 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetAdd()
2868 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetAdd()
2871 return(-1); in xmlXPathNodeSetAdd()
2872 cur->nodeTab[cur->nodeNr++] = nsNode; in xmlXPathNodeSetAdd()
2874 cur->nodeTab[cur->nodeNr++] = val; in xmlXPathNodeSetAdd()
2886 * Returns 0 in case of success and -1 in case of failure
2890 if ((cur == NULL) || (val == NULL)) return(-1); in xmlXPathNodeSetAddUnique()
2896 if (cur->nodeMax == 0) { in xmlXPathNodeSetAddUnique()
2897 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetAddUnique()
2899 if (cur->nodeTab == NULL) in xmlXPathNodeSetAddUnique()
2900 return(-1); in xmlXPathNodeSetAddUnique()
2901 memset(cur->nodeTab, 0 , in xmlXPathNodeSetAddUnique()
2903 cur->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetAddUnique()
2904 } else if (cur->nodeNr == cur->nodeMax) { in xmlXPathNodeSetAddUnique()
2907 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH) in xmlXPathNodeSetAddUnique()
2908 return(-1); in xmlXPathNodeSetAddUnique()
2909 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * in xmlXPathNodeSetAddUnique()
2912 return(-1); in xmlXPathNodeSetAddUnique()
2913 cur->nodeTab = temp; in xmlXPathNodeSetAddUnique()
2914 cur->nodeMax *= 2; in xmlXPathNodeSetAddUnique()
2916 if (val->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetAddUnique()
2918 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetAddUnique()
2921 return(-1); in xmlXPathNodeSetAddUnique()
2922 cur->nodeTab[cur->nodeNr++] = nsNode; in xmlXPathNodeSetAddUnique()
2924 cur->nodeTab[cur->nodeNr++] = val; in xmlXPathNodeSetAddUnique()
2954 initNr = val1->nodeNr; in xmlXPathNodeSetMerge()
2956 for (i = 0;i < val2->nodeNr;i++) { in xmlXPathNodeSetMerge()
2957 n2 = val2->nodeTab[i]; in xmlXPathNodeSetMerge()
2963 n1 = val1->nodeTab[j]; in xmlXPathNodeSetMerge()
2967 } else if ((n1->type == XML_NAMESPACE_DECL) && in xmlXPathNodeSetMerge()
2968 (n2->type == XML_NAMESPACE_DECL)) { in xmlXPathNodeSetMerge()
2969 if ((((xmlNsPtr) n1)->next == ((xmlNsPtr) n2)->next) && in xmlXPathNodeSetMerge()
2970 (xmlStrEqual(((xmlNsPtr) n1)->prefix, in xmlXPathNodeSetMerge()
2971 ((xmlNsPtr) n2)->prefix))) in xmlXPathNodeSetMerge()
2984 if (val1->nodeMax == 0) { in xmlXPathNodeSetMerge()
2985 val1->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * in xmlXPathNodeSetMerge()
2987 if (val1->nodeTab == NULL) in xmlXPathNodeSetMerge()
2989 memset(val1->nodeTab, 0 , in xmlXPathNodeSetMerge()
2991 val1->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetMerge()
2992 } else if (val1->nodeNr == val1->nodeMax) { in xmlXPathNodeSetMerge()
2995 if (val1->nodeMax >= XPATH_MAX_NODESET_LENGTH) in xmlXPathNodeSetMerge()
2997 temp = (xmlNodePtr *) xmlRealloc(val1->nodeTab, val1->nodeMax * 2 * in xmlXPathNodeSetMerge()
3001 val1->nodeTab = temp; in xmlXPathNodeSetMerge()
3002 val1->nodeMax *= 2; in xmlXPathNodeSetMerge()
3004 if (n2->type == XML_NAMESPACE_DECL) { in xmlXPathNodeSetMerge()
3006 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); in xmlXPathNodeSetMerge()
3010 val1->nodeTab[val1->nodeNr++] = nsNode; in xmlXPathNodeSetMerge()
3012 val1->nodeTab[val1->nodeNr++] = n2; in xmlXPathNodeSetMerge()
3042 initNbSet1 = set1->nodeNr; in xmlXPathNodeSetMergeAndClear()
3043 for (i = 0;i < set2->nodeNr;i++) { in xmlXPathNodeSetMergeAndClear()
3044 n2 = set2->nodeTab[i]; in xmlXPathNodeSetMergeAndClear()
3049 n1 = set1->nodeTab[j]; in xmlXPathNodeSetMergeAndClear()
3052 } else if ((n1->type == XML_NAMESPACE_DECL) && in xmlXPathNodeSetMergeAndClear()
3053 (n2->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetMergeAndClear()
3055 if ((((xmlNsPtr) n1)->next == ((xmlNsPtr) n2)->next) && in xmlXPathNodeSetMergeAndClear()
3056 (xmlStrEqual(((xmlNsPtr) n1)->prefix, in xmlXPathNodeSetMergeAndClear()
3057 ((xmlNsPtr) n2)->prefix))) in xmlXPathNodeSetMergeAndClear()
3070 if (set1->nodeMax == 0) { in xmlXPathNodeSetMergeAndClear()
3071 set1->nodeTab = (xmlNodePtr *) xmlMalloc( in xmlXPathNodeSetMergeAndClear()
3073 if (set1->nodeTab == NULL) in xmlXPathNodeSetMergeAndClear()
3075 memset(set1->nodeTab, 0, in xmlXPathNodeSetMergeAndClear()
3077 set1->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetMergeAndClear()
3078 } else if (set1->nodeNr >= set1->nodeMax) { in xmlXPathNodeSetMergeAndClear()
3081 if (set1->nodeMax >= XPATH_MAX_NODESET_LENGTH) in xmlXPathNodeSetMergeAndClear()
3084 set1->nodeTab, set1->nodeMax * 2 * sizeof(xmlNodePtr)); in xmlXPathNodeSetMergeAndClear()
3087 set1->nodeTab = temp; in xmlXPathNodeSetMergeAndClear()
3088 set1->nodeMax *= 2; in xmlXPathNodeSetMergeAndClear()
3090 set1->nodeTab[set1->nodeNr++] = n2; in xmlXPathNodeSetMergeAndClear()
3092 set2->nodeTab[i] = NULL; in xmlXPathNodeSetMergeAndClear()
3095 set2->nodeNr = 0; in xmlXPathNodeSetMergeAndClear()
3123 for (i = 0;i < set2->nodeNr;i++) { in xmlXPathNodeSetMergeAndClearNoDupls()
3124 n2 = set2->nodeTab[i]; in xmlXPathNodeSetMergeAndClearNoDupls()
3125 if (set1->nodeMax == 0) { in xmlXPathNodeSetMergeAndClearNoDupls()
3126 set1->nodeTab = (xmlNodePtr *) xmlMalloc( in xmlXPathNodeSetMergeAndClearNoDupls()
3128 if (set1->nodeTab == NULL) in xmlXPathNodeSetMergeAndClearNoDupls()
3130 memset(set1->nodeTab, 0, in xmlXPathNodeSetMergeAndClearNoDupls()
3132 set1->nodeMax = XML_NODESET_DEFAULT; in xmlXPathNodeSetMergeAndClearNoDupls()
3133 } else if (set1->nodeNr >= set1->nodeMax) { in xmlXPathNodeSetMergeAndClearNoDupls()
3136 if (set1->nodeMax >= XPATH_MAX_NODESET_LENGTH) in xmlXPathNodeSetMergeAndClearNoDupls()
3139 set1->nodeTab, set1->nodeMax * 2 * sizeof(xmlNodePtr)); in xmlXPathNodeSetMergeAndClearNoDupls()
3142 set1->nodeTab = temp; in xmlXPathNodeSetMergeAndClearNoDupls()
3143 set1->nodeMax *= 2; in xmlXPathNodeSetMergeAndClearNoDupls()
3145 set1->nodeTab[set1->nodeNr++] = n2; in xmlXPathNodeSetMergeAndClearNoDupls()
3146 set2->nodeTab[i] = NULL; in xmlXPathNodeSetMergeAndClearNoDupls()
3149 set2->nodeNr = 0; in xmlXPathNodeSetMergeAndClearNoDupls()
3175 for (i = 0;i < cur->nodeNr;i++) in xmlXPathNodeSetDel()
3176 if (cur->nodeTab[i] == val) break; in xmlXPathNodeSetDel()
3178 if (i >= cur->nodeNr) { /* not found */ in xmlXPathNodeSetDel()
3181 if ((cur->nodeTab[i] != NULL) && in xmlXPathNodeSetDel()
3182 (cur->nodeTab[i]->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetDel()
3183 xmlXPathNodeSetFreeNs((xmlNsPtr) cur->nodeTab[i]); in xmlXPathNodeSetDel()
3184 cur->nodeNr--; in xmlXPathNodeSetDel()
3185 for (;i < cur->nodeNr;i++) in xmlXPathNodeSetDel()
3186 cur->nodeTab[i] = cur->nodeTab[i + 1]; in xmlXPathNodeSetDel()
3187 cur->nodeTab[cur->nodeNr] = NULL; in xmlXPathNodeSetDel()
3200 if (val >= cur->nodeNr) return; in xmlXPathNodeSetRemove()
3201 if ((cur->nodeTab[val] != NULL) && in xmlXPathNodeSetRemove()
3202 (cur->nodeTab[val]->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetRemove()
3203 xmlXPathNodeSetFreeNs((xmlNsPtr) cur->nodeTab[val]); in xmlXPathNodeSetRemove()
3204 cur->nodeNr--; in xmlXPathNodeSetRemove()
3205 for (;val < cur->nodeNr;val++) in xmlXPathNodeSetRemove()
3206 cur->nodeTab[val] = cur->nodeTab[val + 1]; in xmlXPathNodeSetRemove()
3207 cur->nodeTab[cur->nodeNr] = NULL; in xmlXPathNodeSetRemove()
3219 if (obj->nodeTab != NULL) { in xmlXPathFreeNodeSet()
3223 for (i = 0;i < obj->nodeNr;i++) in xmlXPathFreeNodeSet()
3224 if ((obj->nodeTab[i] != NULL) && in xmlXPathFreeNodeSet()
3225 (obj->nodeTab[i]->type == XML_NAMESPACE_DECL)) in xmlXPathFreeNodeSet()
3226 xmlXPathNodeSetFreeNs((xmlNsPtr) obj->nodeTab[i]); in xmlXPathFreeNodeSet()
3227 xmlFree(obj->nodeTab); in xmlXPathFreeNodeSet()
3244 if ((set == NULL) || (pos >= set->nodeNr)) in xmlXPathNodeSetClearFromPos()
3250 for (i = pos; i < set->nodeNr; i++) { in xmlXPathNodeSetClearFromPos()
3251 node = set->nodeTab[i]; in xmlXPathNodeSetClearFromPos()
3253 (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetClearFromPos()
3257 set->nodeNr = pos; in xmlXPathNodeSetClearFromPos()
3288 if ((set == NULL) || (set->nodeNr <= 1)) in xmlXPathNodeSetKeepLast()
3290 for (i = 0; i < set->nodeNr - 1; i++) { in xmlXPathNodeSetKeepLast()
3291 node = set->nodeTab[i]; in xmlXPathNodeSetKeepLast()
3293 (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetKeepLast()
3296 set->nodeTab[0] = set->nodeTab[set->nodeNr-1]; in xmlXPathNodeSetKeepLast()
3297 set->nodeNr = 1; in xmlXPathNodeSetKeepLast()
3317 ret->type = XPATH_NODESET; in xmlXPathNewNodeSet()
3318 ret->boolval = 0; in xmlXPathNewNodeSet()
3319 ret->nodesetval = xmlXPathNodeSetCreate(val); in xmlXPathNewNodeSet()
3320 if (ret->nodesetval == NULL) { in xmlXPathNewNodeSet()
3344 ret->type = XPATH_XSLT_TREE; in xmlXPathNewValueTree()
3365 else if (val->nodeTab == NULL) in xmlXPathNewNodeSetList()
3368 ret = xmlXPathNewNodeSet(val->nodeTab[0]); in xmlXPathNewNodeSetList()
3370 ret->nodesetval = xmlXPathNodeSetMerge(NULL, val); in xmlXPathNewNodeSetList()
3371 if (ret->nodesetval == NULL) { in xmlXPathNewNodeSetList()
3401 ret->type = XPATH_NODESET; in xmlXPathWrapNodeSet()
3402 ret->nodesetval = val; in xmlXPathWrapNodeSet()
3421 * @nodes1: a node-set
3422 * @nodes2: a node-set
3424 * Implements the EXSLT - Sets difference() function:
3425 * node-set set:difference (node-set, node-set)
3461 * @nodes1: a node-set
3462 * @nodes2: a node-set
3464 * Implements the EXSLT - Sets intersection() function:
3465 * node-set set:intersection (node-set, node-set)
3499 * @nodes: a node-set, sorted by document order
3501 * Implements the EXSLT - Sets distinct() function:
3502 * node-set set:distinct (node-set)
3548 * @nodes: a node-set
3550 * Implements the EXSLT - Sets distinct() function:
3551 * node-set set:distinct (node-set)
3553 * is called with the sorted node-set
3569 * @nodes1: a node-set
3570 * @nodes2: a node-set
3572 * Implements the EXSLT - Sets has-same-nodes function:
3573 * boolean set:has-same-node(node-set, node-set)
3598 * @nodes: a node-set, sorted by document order
3601 * Implements the EXSLT - Sets leading() function:
3602 * node-set set:leading (node-set, node-set)
3605 * @nodes if @node is NULL or an empty node-set if @nodes
3639 * @nodes: a node-set
3642 * Implements the EXSLT - Sets leading() function:
3643 * node-set set:leading (node-set, node-set)
3648 * @nodes if @node is NULL or an empty node-set if @nodes
3659 * @nodes1: a node-set, sorted by document order
3660 * @nodes2: a node-set, sorted by document order
3662 * Implements the EXSLT - Sets leading() function:
3663 * node-set set:leading (node-set, node-set)
3667 * an empty node-set if @nodes1 doesn't contain @nodes2
3679 * @nodes1: a node-set
3680 * @nodes2: a node-set
3682 * Implements the EXSLT - Sets leading() function:
3683 * node-set set:leading (node-set, node-set)
3689 * an empty node-set if @nodes1 doesn't contain @nodes2
3705 * @nodes: a node-set, sorted by document order
3708 * Implements the EXSLT - Sets trailing() function:
3709 * node-set set:trailing (node-set, node-set)
3712 * @nodes if @node is NULL or an empty node-set if @nodes
3732 for (i = l - 1; i >= 0; i--) { in xmlXPathNodeTrailingSorted()
3747 * @nodes: a node-set
3750 * Implements the EXSLT - Sets trailing() function:
3751 * node-set set:trailing (node-set, node-set)
3756 * @nodes if @node is NULL or an empty node-set if @nodes
3767 * @nodes1: a node-set, sorted by document order
3768 * @nodes2: a node-set, sorted by document order
3770 * Implements the EXSLT - Sets trailing() function:
3771 * node-set set:trailing (node-set, node-set)
3775 * an empty node-set if @nodes1 doesn't contain @nodes2
3787 * @nodes1: a node-set
3788 * @nodes2: a node-set
3790 * Implements the EXSLT - Sets trailing() function:
3791 * node-set set:trailing (node-set, node-set)
3797 * an empty node-set if @nodes1 doesn't contain @nodes2
3825 * Returns 0 in case of success, -1 in case of error
3842 * Returns 0 in case of success, -1 in case of error
3850 return(-1); in xmlXPathRegisterFuncNS()
3852 return(-1); in xmlXPathRegisterFuncNS()
3854 if (ctxt->funcHash == NULL) in xmlXPathRegisterFuncNS()
3855 ctxt->funcHash = xmlHashCreate(0); in xmlXPathRegisterFuncNS()
3856 if (ctxt->funcHash == NULL) { in xmlXPathRegisterFuncNS()
3858 return(-1); in xmlXPathRegisterFuncNS()
3861 return(xmlHashRemoveEntry2(ctxt->funcHash, name, ns_uri, NULL)); in xmlXPathRegisterFuncNS()
3863 ret = xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, (void *) f); in xmlXPathRegisterFuncNS()
3867 return(-1); in xmlXPathRegisterFuncNS()
3887 ctxt->funcLookupFunc = f; in xmlXPathRegisterFuncLookup()
3888 ctxt->funcLookupData = funcCtxt; in xmlXPathRegisterFuncLookup()
3906 if (ctxt->funcLookupFunc != NULL) { in xmlXPathFunctionLookup()
3910 f = ctxt->funcLookupFunc; in xmlXPathFunctionLookup()
3911 ret = f(ctxt->funcLookupData, name, NULL); in xmlXPathFunctionLookup()
3939 if (ctxt->funcLookupFunc != NULL) { in xmlXPathFunctionLookupNS()
3942 f = ctxt->funcLookupFunc; in xmlXPathFunctionLookupNS()
3943 ret = f(ctxt->funcLookupData, name, ns_uri); in xmlXPathFunctionLookupNS()
3948 if (ctxt->funcHash == NULL) in xmlXPathFunctionLookupNS()
3952 ret = (xmlXPathFunction) xmlHashLookup2(ctxt->funcHash, name, ns_uri); in xmlXPathFunctionLookupNS()
3968 xmlHashFree(ctxt->funcHash, NULL); in xmlXPathRegisteredFuncsCleanup()
3969 ctxt->funcHash = NULL; in xmlXPathRegisteredFuncsCleanup()
3987 * Returns 0 in case of success, -1 in case of error
4005 * Returns 0 in case of success, -1 in case of error
4012 return(-1); in xmlXPathRegisterVariableNS()
4014 return(-1); in xmlXPathRegisterVariableNS()
4016 if (ctxt->varHash == NULL) in xmlXPathRegisterVariableNS()
4017 ctxt->varHash = xmlHashCreate(0); in xmlXPathRegisterVariableNS()
4018 if (ctxt->varHash == NULL) in xmlXPathRegisterVariableNS()
4019 return(-1); in xmlXPathRegisterVariableNS()
4021 return(xmlHashRemoveEntry2(ctxt->varHash, name, ns_uri, in xmlXPathRegisterVariableNS()
4023 return(xmlHashUpdateEntry2(ctxt->varHash, name, ns_uri, in xmlXPathRegisterVariableNS()
4040 ctxt->varLookupFunc = f; in xmlXPathRegisterVariableLookup()
4041 ctxt->varLookupData = data; in xmlXPathRegisterVariableLookup()
4059 if (ctxt->varLookupFunc != NULL) { in xmlXPathVariableLookup()
4062 ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc) in xmlXPathVariableLookup()
4063 (ctxt->varLookupData, name, NULL); in xmlXPathVariableLookup()
4086 if (ctxt->varLookupFunc != NULL) { in xmlXPathVariableLookupNS()
4089 ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc) in xmlXPathVariableLookupNS()
4090 (ctxt->varLookupData, name, ns_uri); in xmlXPathVariableLookupNS()
4094 if (ctxt->varHash == NULL) in xmlXPathVariableLookupNS()
4099 return(xmlXPathObjectCopy(xmlHashLookup2(ctxt->varHash, name, ns_uri))); in xmlXPathVariableLookupNS()
4113 xmlHashFree(ctxt->varHash, xmlXPathFreeObjectEntry); in xmlXPathRegisteredVariablesCleanup()
4114 ctxt->varHash = NULL; in xmlXPathRegisteredVariablesCleanup()
4126 * Returns 0 in case of success, -1 in case of error
4134 return(-1); in xmlXPathRegisterNs()
4136 return(-1); in xmlXPathRegisterNs()
4138 return(-1); in xmlXPathRegisterNs()
4140 if (ctxt->nsHash == NULL) in xmlXPathRegisterNs()
4141 ctxt->nsHash = xmlHashCreate(10); in xmlXPathRegisterNs()
4142 if (ctxt->nsHash == NULL) { in xmlXPathRegisterNs()
4144 return(-1); in xmlXPathRegisterNs()
4147 return(xmlHashRemoveEntry(ctxt->nsHash, prefix, in xmlXPathRegisterNs()
4153 return(-1); in xmlXPathRegisterNs()
4155 if (xmlHashUpdateEntry(ctxt->nsHash, prefix, copy, in xmlXPathRegisterNs()
4159 return(-1); in xmlXPathRegisterNs()
4185 if (ctxt->namespaces != NULL) { in xmlXPathNsLookup()
4188 for (i = 0;i < ctxt->nsNr;i++) { in xmlXPathNsLookup()
4189 if ((ctxt->namespaces[i] != NULL) && in xmlXPathNsLookup()
4190 (xmlStrEqual(ctxt->namespaces[i]->prefix, prefix))) in xmlXPathNsLookup()
4191 return(ctxt->namespaces[i]->href); in xmlXPathNsLookup()
4195 return((const xmlChar *) xmlHashLookup(ctxt->nsHash, prefix)); in xmlXPathNsLookup()
4209 xmlHashFree(ctxt->nsHash, xmlHashDefaultDeallocator); in xmlXPathRegisteredNsCleanup()
4210 ctxt->nsHash = NULL; in xmlXPathRegisteredNsCleanup()
4237 ret->type = XPATH_NUMBER; in xmlXPathNewFloat()
4238 ret->floatval = val; in xmlXPathNewFloat()
4258 ret->type = XPATH_BOOLEAN; in xmlXPathNewBoolean()
4259 ret->boolval = (val != 0); in xmlXPathNewBoolean()
4279 ret->type = XPATH_STRING; in xmlXPathNewString()
4282 ret->stringval = xmlStrdup(val); in xmlXPathNewString()
4283 if (ret->stringval == NULL) { in xmlXPathNewString()
4310 ret->type = XPATH_STRING; in xmlXPathWrapString()
4311 ret->stringval = val; in xmlXPathWrapString()
4357 ret->type = XPATH_USERS; in xmlXPathWrapExternal()
4358 ret->user = val; in xmlXPathWrapExternal()
4381 switch (val->type) { in xmlXPathObjectCopy()
4386 ret->stringval = xmlStrdup(val->stringval); in xmlXPathObjectCopy()
4387 if (ret->stringval == NULL) { in xmlXPathObjectCopy()
4395 Removed 11 July 2004 - the current handling of xslt tmpRVT nodes means that in xmlXPathObjectCopy()
4399 if ((val->nodesetval != NULL) && in xmlXPathObjectCopy()
4400 (val->nodesetval->nodeTab != NULL)) { in xmlXPathObjectCopy()
4404 ret->boolval = 1; in xmlXPathObjectCopy()
4406 top->name = (char *) in xmlXPathObjectCopy()
4407 xmlStrdup(val->nodesetval->nodeTab[0]->name); in xmlXPathObjectCopy()
4408 ret->user = top; in xmlXPathObjectCopy()
4410 top->doc = top; in xmlXPathObjectCopy()
4411 cur = val->nodesetval->nodeTab[0]->children; in xmlXPathObjectCopy()
4415 cur = cur->next; in xmlXPathObjectCopy()
4419 ret->nodesetval = xmlXPathNodeSetCreate((xmlNodePtr) top); in xmlXPathObjectCopy()
4421 ret->nodesetval = xmlXPathNodeSetCreate(NULL); in xmlXPathObjectCopy()
4426 ret->nodesetval = xmlXPathNodeSetMerge(NULL, val->nodesetval); in xmlXPathObjectCopy()
4427 if (ret->nodesetval == NULL) { in xmlXPathObjectCopy()
4432 ret->boolval = 0; in xmlXPathObjectCopy()
4435 ret->user = val->user; in xmlXPathObjectCopy()
4454 if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) { in xmlXPathFreeObject()
4455 if (obj->nodesetval != NULL) in xmlXPathFreeObject()
4456 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathFreeObject()
4457 } else if (obj->type == XPATH_STRING) { in xmlXPathFreeObject()
4458 if (obj->stringval != NULL) in xmlXPathFreeObject()
4459 xmlFree(obj->stringval); in xmlXPathFreeObject()
4481 if ((ctxt == NULL) || (ctxt->cache == NULL)) { in xmlXPathReleaseObject()
4485 (xmlXPathContextCachePtr) ctxt->cache; in xmlXPathReleaseObject()
4487 switch (obj->type) { in xmlXPathReleaseObject()
4490 if (obj->nodesetval != NULL) { in xmlXPathReleaseObject()
4491 if ((obj->nodesetval->nodeMax <= 40) && in xmlXPathReleaseObject()
4492 (cache->numNodeset < cache->maxNodeset)) { in xmlXPathReleaseObject()
4493 obj->stringval = (void *) cache->nodesetObjs; in xmlXPathReleaseObject()
4494 cache->nodesetObjs = obj; in xmlXPathReleaseObject()
4495 cache->numNodeset += 1; in xmlXPathReleaseObject()
4498 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathReleaseObject()
4499 obj->nodesetval = NULL; in xmlXPathReleaseObject()
4504 if (obj->stringval != NULL) in xmlXPathReleaseObject()
4505 xmlFree(obj->stringval); in xmlXPathReleaseObject()
4506 obj->stringval = NULL; in xmlXPathReleaseObject()
4516 * Fallback to adding to the misc-objects slot. in xmlXPathReleaseObject()
4518 if (cache->numMisc >= cache->maxMisc) in xmlXPathReleaseObject()
4520 obj->stringval = (void *) cache->miscObjs; in xmlXPathReleaseObject()
4521 cache->miscObjs = obj; in xmlXPathReleaseObject()
4522 cache->numMisc += 1; in xmlXPathReleaseObject()
4525 obj->boolval = 0; in xmlXPathReleaseObject()
4526 if (obj->nodesetval != NULL) { in xmlXPathReleaseObject()
4527 xmlNodeSetPtr tmpset = obj->nodesetval; in xmlXPathReleaseObject()
4530 * Due to those nasty ns-nodes, we need to traverse in xmlXPathReleaseObject()
4531 * the list and free the ns-nodes. in xmlXPathReleaseObject()
4533 if (tmpset->nodeNr > 0) { in xmlXPathReleaseObject()
4537 for (i = 0; i < tmpset->nodeNr; i++) { in xmlXPathReleaseObject()
4538 node = tmpset->nodeTab[i]; in xmlXPathReleaseObject()
4540 (node->type == XML_NAMESPACE_DECL)) in xmlXPathReleaseObject()
4546 tmpset->nodeNr = 0; in xmlXPathReleaseObject()
4555 if (obj->nodesetval != NULL) in xmlXPathReleaseObject()
4556 xmlXPathFreeNodeSet(obj->nodesetval); in xmlXPathReleaseObject()
4602 case -1: in xmlXPathCastNumberToString()
4603 ret = xmlStrdup((const xmlChar *) "-Infinity"); in xmlXPathCastNumberToString()
4637 * @ns: a node-set
4639 * Converts a node-set to its string value.
4645 if ((ns == NULL) || (ns->nodeNr == 0) || (ns->nodeTab == NULL)) in xmlXPathCastNodeSetToString()
4648 if (ns->nodeNr > 1) in xmlXPathCastNodeSetToString()
4650 return(xmlXPathCastNodeToString(ns->nodeTab[0])); in xmlXPathCastNodeSetToString()
4668 switch (val->type) { in xmlXPathCastToString()
4674 ret = xmlXPathCastNodeSetToString(val->nodesetval); in xmlXPathCastToString()
4677 return(xmlStrdup(val->stringval)); in xmlXPathCastToString()
4679 ret = xmlXPathCastBooleanToString(val->boolval); in xmlXPathCastToString()
4682 ret = xmlXPathCastNumberToString(val->floatval); in xmlXPathCastToString()
4709 switch (val->type) { in xmlXPathConvertString()
4714 res = xmlXPathCastNodeSetToString(val->nodesetval); in xmlXPathConvertString()
4719 res = xmlXPathCastBooleanToString(val->boolval); in xmlXPathConvertString()
4722 res = xmlXPathCastNumberToString(val->floatval); in xmlXPathConvertString()
4803 * @ns: a node-set
4805 * Converts a node-set to its number value
4850 if (val->type == XPATH_NUMBER) in xmlXPathConvertNumber()
4889 * @ns: a node-set
4891 * Converts a node-set to its boolean value
4897 if ((ns == NULL) || (ns->nodeNr == 0)) in xmlXPathCastNodeSetToBoolean()
4916 switch (val->type) { in xmlXPathCastToBoolean()
4922 ret = xmlXPathCastNodeSetToBoolean(val->nodesetval); in xmlXPathCastToBoolean()
4925 ret = xmlXPathCastStringToBoolean(val->stringval); in xmlXPathCastToBoolean()
4928 ret = xmlXPathCastNumberToBoolean(val->floatval); in xmlXPathCastToBoolean()
4931 ret = val->boolval; in xmlXPathCastToBoolean()
4957 if (val->type == XPATH_BOOLEAN) in xmlXPathConvertBoolean()
4986 ret->doc = doc; in xmlXPathNewContext()
4987 ret->node = NULL; in xmlXPathNewContext()
4989 ret->varHash = NULL; in xmlXPathNewContext()
4991 ret->nb_types = 0; in xmlXPathNewContext()
4992 ret->max_types = 0; in xmlXPathNewContext()
4993 ret->types = NULL; in xmlXPathNewContext()
4995 ret->nb_axis = 0; in xmlXPathNewContext()
4996 ret->max_axis = 0; in xmlXPathNewContext()
4997 ret->axis = NULL; in xmlXPathNewContext()
4999 ret->nsHash = NULL; in xmlXPathNewContext()
5000 ret->user = NULL; in xmlXPathNewContext()
5002 ret->contextSize = -1; in xmlXPathNewContext()
5003 ret->proximityPosition = -1; in xmlXPathNewContext()
5006 if (xmlXPathContextSetCache(ret, 1, -1, 0) == -1) { in xmlXPathNewContext()
5014 if (ret->lastError.code != XML_ERR_OK) { in xmlXPathNewContext()
5032 if (ctxt->cache != NULL) in xmlXPathFreeContext()
5033 xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache); in xmlXPathFreeContext()
5037 xmlResetError(&ctxt->lastError); in xmlXPathFreeContext()
5058 ctxt->error = handler; in xmlXPathSetErrorHandler()
5059 ctxt->userData = data; in xmlXPathSetErrorHandler()
5087 ret->cur = ret->base = str; in xmlXPathNewParserContext()
5088 ret->context = ctxt; in xmlXPathNewParserContext()
5090 ret->comp = xmlXPathNewCompExpr(); in xmlXPathNewParserContext()
5091 if (ret->comp == NULL) { in xmlXPathNewParserContext()
5093 xmlFree(ret->valueTab); in xmlXPathNewParserContext()
5097 if ((ctxt != NULL) && (ctxt->dict != NULL)) { in xmlXPathNewParserContext()
5098 ret->comp->dict = ctxt->dict; in xmlXPathNewParserContext()
5099 xmlDictReference(ret->comp->dict); in xmlXPathNewParserContext()
5126 ret->valueTab = (xmlXPathObjectPtr *) in xmlXPathCompParserContext()
5128 if (ret->valueTab == NULL) { in xmlXPathCompParserContext()
5133 ret->valueNr = 0; in xmlXPathCompParserContext()
5134 ret->valueMax = 10; in xmlXPathCompParserContext()
5135 ret->value = NULL; in xmlXPathCompParserContext()
5137 ret->context = ctxt; in xmlXPathCompParserContext()
5138 ret->comp = comp; in xmlXPathCompParserContext()
5153 if (ctxt->valueTab != NULL) { in xmlXPathFreeParserContext()
5154 for (i = 0; i < ctxt->valueNr; i++) { in xmlXPathFreeParserContext()
5155 if (ctxt->context) in xmlXPathFreeParserContext()
5156 xmlXPathReleaseObject(ctxt->context, ctxt->valueTab[i]); in xmlXPathFreeParserContext()
5158 xmlXPathFreeObject(ctxt->valueTab[i]); in xmlXPathFreeParserContext()
5160 xmlFree(ctxt->valueTab); in xmlXPathFreeParserContext()
5162 if (ctxt->comp != NULL) { in xmlXPathFreeParserContext()
5164 if (ctxt->comp->stream != NULL) { in xmlXPathFreeParserContext()
5165 xmlFreePatternList(ctxt->comp->stream); in xmlXPathFreeParserContext()
5166 ctxt->comp->stream = NULL; in xmlXPathFreeParserContext()
5169 xmlXPathFreeCompExpr(ctxt->comp); in xmlXPathFreeParserContext()
5199 if (node->type == XML_DOCUMENT_NODE) { in xmlXPathNodeValHash()
5202 node = node->children; in xmlXPathNodeValHash()
5210 switch (node->type) { in xmlXPathNodeValHash()
5215 string = node->content; in xmlXPathNodeValHash()
5222 string = ((xmlNsPtr)node)->href; in xmlXPathNodeValHash()
5229 tmp = ((xmlAttrPtr) node)->children; in xmlXPathNodeValHash()
5232 tmp = node->children; in xmlXPathNodeValHash()
5238 switch (tmp->type) { in xmlXPathNodeValHash()
5241 string = tmp->content; in xmlXPathNodeValHash()
5261 if ((tmp->children != NULL) && in xmlXPathNodeValHash()
5262 (tmp->type != XML_DTD_NODE) && in xmlXPathNodeValHash()
5263 (tmp->type != XML_ENTITY_REF_NODE) && in xmlXPathNodeValHash()
5264 (tmp->children->type != XML_ENTITY_DECL)) { in xmlXPathNodeValHash()
5265 tmp = tmp->children; in xmlXPathNodeValHash()
5271 if (tmp->next != NULL) { in xmlXPathNodeValHash()
5272 tmp = tmp->next; in xmlXPathNodeValHash()
5277 tmp = tmp->parent; in xmlXPathNodeValHash()
5284 if (tmp->next != NULL) { in xmlXPathNodeValHash()
5285 tmp = tmp->next; in xmlXPathNodeValHash()
5325 * If one object to be compared is a node-set and the other is a number,
5327 * node-set such that the result of performing the comparison on the number
5328 * to be compared and on the result of converting the string-value of that
5341 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSetFloat()
5342 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetFloat()
5343 xmlXPathReleaseObject(ctxt->context, f); in xmlXPathCompareNodeSetFloat()
5346 ns = arg->nodesetval; in xmlXPathCompareNodeSetFloat()
5348 for (i = 0;i < ns->nodeNr;i++) { in xmlXPathCompareNodeSetFloat()
5349 str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); in xmlXPathCompareNodeSetFloat()
5363 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetFloat()
5364 xmlXPathReleaseObject(ctxt->context, f); in xmlXPathCompareNodeSetFloat()
5382 * If one object to be compared is a node-set and the other is a string,
5384 * the node-set such that the result of performing the comparison on the
5385 * string-value of the node and the other string is true.
5397 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSetString()
5398 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetString()
5399 xmlXPathReleaseObject(ctxt->context, s); in xmlXPathCompareNodeSetString()
5402 ns = arg->nodesetval; in xmlXPathCompareNodeSetString()
5404 for (i = 0;i < ns->nodeNr;i++) { in xmlXPathCompareNodeSetString()
5405 str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); in xmlXPathCompareNodeSetString()
5419 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetString()
5420 xmlXPathReleaseObject(ctxt->context, s); in xmlXPathCompareNodeSetString()
5433 * If both objects to be compared are node-sets, then the comparison
5434 * will be true if and only if there is a node in the first node-set
5435 * and a node in the second node-set such that the result of performing
5436 * the comparison on the string-values of the two nodes is true.
5438 * When neither object to be compared is a node-set and the operator
5443 * - a string that consists of optional whitespace followed by an
5446 * to the IEEE 754 round-to-nearest rule) to the mathematical value
5463 ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSets()
5468 ((arg2->type != XPATH_NODESET) && (arg2->type != XPATH_XSLT_TREE))) { in xmlXPathCompareNodeSets()
5474 ns1 = arg1->nodesetval; in xmlXPathCompareNodeSets()
5475 ns2 = arg2->nodesetval; in xmlXPathCompareNodeSets()
5477 if ((ns1 == NULL) || (ns1->nodeNr <= 0)) { in xmlXPathCompareNodeSets()
5482 if ((ns2 == NULL) || (ns2->nodeNr <= 0)) { in xmlXPathCompareNodeSets()
5488 values2 = (double *) xmlMalloc(ns2->nodeNr * sizeof(double)); in xmlXPathCompareNodeSets()
5495 for (i = 0;i < ns1->nodeNr;i++) { in xmlXPathCompareNodeSets()
5496 val1 = xmlXPathNodeToNumberInternal(ctxt, ns1->nodeTab[i]); in xmlXPathCompareNodeSets()
5499 for (j = 0;j < ns2->nodeNr;j++) { in xmlXPathCompareNodeSets()
5502 ns2->nodeTab[j]); in xmlXPathCompareNodeSets()
5541 * If one object to be compared is a node-set and the other is a boolean,
5544 * the node-set to a boolean using the boolean function is true.
5552 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) in xmlXPathCompareNodeSetValue()
5555 switch(val->type) { in xmlXPathCompareNodeSetValue()
5569 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathCompareNodeSetValue()
5570 xmlXPathReleaseObject(ctxt->context, val); in xmlXPathCompareNodeSetValue()
5583 * If one object to be compared is a node-set and the other is a string,
5585 * the node-set such that the result of performing the comparison on the
5586 * string-value of the node and the other string is true.
5600 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSetString()
5602 ns = arg->nodesetval; in xmlXPathEqualNodeSetString()
5607 if ((ns == NULL) || (ns->nodeNr <= 0) ) in xmlXPathEqualNodeSetString()
5610 for (i = 0; i < ns->nodeNr; i++) { in xmlXPathEqualNodeSetString()
5611 if (xmlXPathNodeValHash(ns->nodeTab[i]) == hash) { in xmlXPathEqualNodeSetString()
5612 str2 = xmlNodeGetContent(ns->nodeTab[i]); in xmlXPathEqualNodeSetString()
5640 * If one object to be compared is a node-set and the other is a number,
5642 * the node-set such that the result of performing the comparison on the
5643 * number to be compared and on the result of converting the string-value
5658 ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSetFloat()
5661 ns = arg->nodesetval; in xmlXPathEqualNodeSetFloat()
5663 for (i=0;i<ns->nodeNr;i++) { in xmlXPathEqualNodeSetFloat()
5664 str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); in xmlXPathEqualNodeSetFloat()
5671 v = val->floatval; in xmlXPathEqualNodeSetFloat()
5672 xmlXPathReleaseObject(ctxt->context, val); in xmlXPathEqualNodeSetFloat()
5703 * If both objects to be compared are node-sets, then the comparison
5704 * will be true if and only if there is a node in the first node-set and
5705 * a node in the second node-set such that the result of performing the
5706 * comparison on the string-values of the two nodes is true.
5725 ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSets()
5728 ((arg2->type != XPATH_NODESET) && (arg2->type != XPATH_XSLT_TREE))) in xmlXPathEqualNodeSets()
5731 ns1 = arg1->nodesetval; in xmlXPathEqualNodeSets()
5732 ns2 = arg2->nodesetval; in xmlXPathEqualNodeSets()
5734 if ((ns1 == NULL) || (ns1->nodeNr <= 0)) in xmlXPathEqualNodeSets()
5736 if ((ns2 == NULL) || (ns2->nodeNr <= 0)) in xmlXPathEqualNodeSets()
5743 for (i = 0;i < ns1->nodeNr;i++) in xmlXPathEqualNodeSets()
5744 for (j = 0;j < ns2->nodeNr;j++) in xmlXPathEqualNodeSets()
5745 if (ns1->nodeTab[i] == ns2->nodeTab[j]) in xmlXPathEqualNodeSets()
5748 values1 = (xmlChar **) xmlMalloc(ns1->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
5753 hashs1 = (unsigned int *) xmlMalloc(ns1->nodeNr * sizeof(unsigned int)); in xmlXPathEqualNodeSets()
5759 memset(values1, 0, ns1->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
5760 values2 = (xmlChar **) xmlMalloc(ns2->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
5767 hashs2 = (unsigned int *) xmlMalloc(ns2->nodeNr * sizeof(unsigned int)); in xmlXPathEqualNodeSets()
5775 memset(values2, 0, ns2->nodeNr * sizeof(xmlChar *)); in xmlXPathEqualNodeSets()
5776 for (i = 0;i < ns1->nodeNr;i++) { in xmlXPathEqualNodeSets()
5777 hashs1[i] = xmlXPathNodeValHash(ns1->nodeTab[i]); in xmlXPathEqualNodeSets()
5778 for (j = 0;j < ns2->nodeNr;j++) { in xmlXPathEqualNodeSets()
5780 hashs2[j] = xmlXPathNodeValHash(ns2->nodeTab[j]); in xmlXPathEqualNodeSets()
5789 values1[i] = xmlNodeGetContent(ns1->nodeTab[i]); in xmlXPathEqualNodeSets()
5794 values2[j] = xmlNodeGetContent(ns2->nodeTab[j]); in xmlXPathEqualNodeSets()
5806 for (i = 0;i < ns1->nodeNr;i++) in xmlXPathEqualNodeSets()
5809 for (j = 0;j < ns2->nodeNr;j++) in xmlXPathEqualNodeSets()
5827 switch (arg1->type) { in xmlXPathEqualValuesCommon()
5831 switch (arg2->type) { in xmlXPathEqualValuesCommon()
5835 ret = (arg1->boolval == arg2->boolval); in xmlXPathEqualValuesCommon()
5838 ret = (arg1->boolval == in xmlXPathEqualValuesCommon()
5839 xmlXPathCastNumberToBoolean(arg2->floatval)); in xmlXPathEqualValuesCommon()
5842 if ((arg2->stringval == NULL) || in xmlXPathEqualValuesCommon()
5843 (arg2->stringval[0] == 0)) ret = 0; in xmlXPathEqualValuesCommon()
5846 ret = (arg1->boolval == ret); in xmlXPathEqualValuesCommon()
5857 switch (arg2->type) { in xmlXPathEqualValuesCommon()
5861 ret = (arg2->boolval== in xmlXPathEqualValuesCommon()
5862 xmlXPathCastNumberToBoolean(arg1->floatval)); in xmlXPathEqualValuesCommon()
5868 if (ctxt->error) in xmlXPathEqualValuesCommon()
5873 if (xmlXPathIsNaN(arg1->floatval) || in xmlXPathEqualValuesCommon()
5874 xmlXPathIsNaN(arg2->floatval)) { in xmlXPathEqualValuesCommon()
5876 } else if (xmlXPathIsInf(arg1->floatval) == 1) { in xmlXPathEqualValuesCommon()
5877 if (xmlXPathIsInf(arg2->floatval) == 1) in xmlXPathEqualValuesCommon()
5881 } else if (xmlXPathIsInf(arg1->floatval) == -1) { in xmlXPathEqualValuesCommon()
5882 if (xmlXPathIsInf(arg2->floatval) == -1) in xmlXPathEqualValuesCommon()
5886 } else if (xmlXPathIsInf(arg2->floatval) == 1) { in xmlXPathEqualValuesCommon()
5887 if (xmlXPathIsInf(arg1->floatval) == 1) in xmlXPathEqualValuesCommon()
5891 } else if (xmlXPathIsInf(arg2->floatval) == -1) { in xmlXPathEqualValuesCommon()
5892 if (xmlXPathIsInf(arg1->floatval) == -1) in xmlXPathEqualValuesCommon()
5897 ret = (arg1->floatval == arg2->floatval); in xmlXPathEqualValuesCommon()
5909 switch (arg2->type) { in xmlXPathEqualValuesCommon()
5913 if ((arg1->stringval == NULL) || in xmlXPathEqualValuesCommon()
5914 (arg1->stringval[0] == 0)) ret = 0; in xmlXPathEqualValuesCommon()
5917 ret = (arg2->boolval == ret); in xmlXPathEqualValuesCommon()
5920 ret = xmlStrEqual(arg1->stringval, arg2->stringval); in xmlXPathEqualValuesCommon()
5926 if (ctxt->error) in xmlXPathEqualValuesCommon()
5929 if (xmlXPathIsNaN(arg1->floatval) || in xmlXPathEqualValuesCommon()
5930 xmlXPathIsNaN(arg2->floatval)) { in xmlXPathEqualValuesCommon()
5932 } else if (xmlXPathIsInf(arg1->floatval) == 1) { in xmlXPathEqualValuesCommon()
5933 if (xmlXPathIsInf(arg2->floatval) == 1) in xmlXPathEqualValuesCommon()
5937 } else if (xmlXPathIsInf(arg1->floatval) == -1) { in xmlXPathEqualValuesCommon()
5938 if (xmlXPathIsInf(arg2->floatval) == -1) in xmlXPathEqualValuesCommon()
5942 } else if (xmlXPathIsInf(arg2->floatval) == 1) { in xmlXPathEqualValuesCommon()
5943 if (xmlXPathIsInf(arg1->floatval) == 1) in xmlXPathEqualValuesCommon()
5947 } else if (xmlXPathIsInf(arg2->floatval) == -1) { in xmlXPathEqualValuesCommon()
5948 if (xmlXPathIsInf(arg1->floatval) == -1) in xmlXPathEqualValuesCommon()
5953 ret = (arg1->floatval == arg2->floatval); in xmlXPathEqualValuesCommon()
5971 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathEqualValuesCommon()
5972 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathEqualValuesCommon()
5989 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0); in xmlXPathEqualValues()
5994 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathEqualValues()
5996 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathEqualValues()
6008 if ((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE) || in xmlXPathEqualValues()
6009 (arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathEqualValues()
6013 if ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE)) { in xmlXPathEqualValues()
6018 switch (arg2->type) { in xmlXPathEqualValues()
6026 if ((arg1->nodesetval == NULL) || in xmlXPathEqualValues()
6027 (arg1->nodesetval->nodeNr == 0)) ret = 0; in xmlXPathEqualValues()
6030 ret = (ret == arg2->boolval); in xmlXPathEqualValues()
6033 ret = xmlXPathEqualNodeSetFloat(ctxt, arg1, arg2->floatval, 0); in xmlXPathEqualValues()
6037 arg2->stringval, 0); in xmlXPathEqualValues()
6043 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathEqualValues()
6044 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathEqualValues()
6064 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0); in xmlXPathNotEqualValues()
6069 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathNotEqualValues()
6071 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathNotEqualValues()
6076 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathNotEqualValues()
6083 if ((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE) || in xmlXPathNotEqualValues()
6084 (arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathNotEqualValues()
6088 if ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE)) { in xmlXPathNotEqualValues()
6093 switch (arg2->type) { in xmlXPathNotEqualValues()
6101 if ((arg1->nodesetval == NULL) || in xmlXPathNotEqualValues()
6102 (arg1->nodesetval->nodeNr == 0)) ret = 0; in xmlXPathNotEqualValues()
6105 ret = (ret != arg2->boolval); in xmlXPathNotEqualValues()
6108 ret = xmlXPathEqualNodeSetFloat(ctxt, arg1, arg2->floatval, 1); in xmlXPathNotEqualValues()
6112 arg2->stringval, 1); in xmlXPathNotEqualValues()
6118 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathNotEqualValues()
6119 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathNotEqualValues()
6138 * When neither object to be compared is a node-set and the operator is
6155 if ((ctxt == NULL) || (ctxt->context == NULL)) return(0); in xmlXPathCompareValues()
6160 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompareValues()
6162 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompareValues()
6166 if ((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE) || in xmlXPathCompareValues()
6167 (arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathCompareValues()
6173 if (((arg2->type == XPATH_NODESET) || (arg2->type == XPATH_XSLT_TREE)) && in xmlXPathCompareValues()
6174 ((arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE))){ in xmlXPathCompareValues()
6177 if ((arg1->type == XPATH_NODESET) || (arg1->type == XPATH_XSLT_TREE)) { in xmlXPathCompareValues()
6188 if (arg1->type != XPATH_NUMBER) { in xmlXPathCompareValues()
6193 if (arg2->type != XPATH_NUMBER) { in xmlXPathCompareValues()
6198 if (ctxt->error) in xmlXPathCompareValues()
6205 if (xmlXPathIsNaN(arg1->floatval) || xmlXPathIsNaN(arg2->floatval)) { in xmlXPathCompareValues()
6208 arg1i=xmlXPathIsInf(arg1->floatval); in xmlXPathCompareValues()
6209 arg2i=xmlXPathIsInf(arg2->floatval); in xmlXPathCompareValues()
6211 if ((arg1i == -1 && arg2i != -1) || in xmlXPathCompareValues()
6215 ret = (arg1->floatval < arg2->floatval); in xmlXPathCompareValues()
6221 if (arg1i == -1 || arg2i == 1) { in xmlXPathCompareValues()
6224 ret = (arg1->floatval <= arg2->floatval); in xmlXPathCompareValues()
6231 (arg2i == -1 && arg1i != -1)) { in xmlXPathCompareValues()
6234 ret = (arg1->floatval > arg2->floatval); in xmlXPathCompareValues()
6240 if (arg1i == 1 || arg2i == -1) { in xmlXPathCompareValues()
6243 ret = (arg1->floatval >= arg2->floatval); in xmlXPathCompareValues()
6250 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompareValues()
6251 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompareValues()
6259 * Implement the unary - operation on an XPath object
6265 if ((ctxt == NULL) || (ctxt->context == NULL)) return; in xmlXPathValueFlipSign()
6268 ctxt->value->floatval = -ctxt->value->floatval; in xmlXPathValueFlipSign()
6288 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathAddValues()
6291 ctxt->value->floatval += val; in xmlXPathAddValues()
6311 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathSubValues()
6314 ctxt->value->floatval -= val; in xmlXPathSubValues()
6334 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathMultValues()
6337 ctxt->value->floatval *= val; in xmlXPathMultValues()
6348 ATTRIBUTE_NO_SANITIZE("float-divide-by-zero")
6358 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathDivValues()
6361 ctxt->value->floatval /= val; in xmlXPathDivValues()
6381 xmlXPathReleaseObject(ctxt->context, arg); in xmlXPathModValues()
6384 arg1 = ctxt->value->floatval; in xmlXPathModValues()
6386 ctxt->value->floatval = xmlXPathNAN; in xmlXPathModValues()
6388 ctxt->value->floatval = fmod(arg1, arg2); in xmlXPathModValues()
6436 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextSelf()
6438 return(ctxt->context->node); in xmlXPathNextSelf()
6454 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextChild()
6456 if (ctxt->context->node == NULL) return(NULL); in xmlXPathNextChild()
6457 switch (ctxt->context->node->type) { in xmlXPathNextChild()
6467 return(ctxt->context->node->children); in xmlXPathNextChild()
6472 return(((xmlDocPtr) ctxt->context->node)->children); in xmlXPathNextChild()
6484 if ((cur->type == XML_DOCUMENT_NODE) || in xmlXPathNextChild()
6485 (cur->type == XML_HTML_DOCUMENT_NODE)) in xmlXPathNextChild()
6487 return(cur->next); in xmlXPathNextChild()
6502 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextChildElement()
6504 cur = ctxt->context->node; in xmlXPathNextChildElement()
6509 switch (cur->type) { in xmlXPathNextChildElement()
6512 case XML_ENTITY_REF_NODE: /* URGENT TODO: entify-refs as well? */ in xmlXPathNextChildElement()
6514 cur = cur->children; in xmlXPathNextChildElement()
6516 if (cur->type == XML_ELEMENT_NODE) in xmlXPathNextChildElement()
6519 cur = cur->next; in xmlXPathNextChildElement()
6521 (cur->type != XML_ELEMENT_NODE)); in xmlXPathNextChildElement()
6536 switch (cur->type) { in xmlXPathNextChildElement()
6546 /* case XML_DTD_NODE: */ /* URGENT TODO: DTD-node as well? */ in xmlXPathNextChildElement()
6550 if (cur->next != NULL) { in xmlXPathNextChildElement()
6551 if (cur->next->type == XML_ELEMENT_NODE) in xmlXPathNextChildElement()
6552 return(cur->next); in xmlXPathNextChildElement()
6553 cur = cur->next; in xmlXPathNextChildElement()
6555 cur = cur->next; in xmlXPathNextChildElement()
6556 } while ((cur != NULL) && (cur->type != XML_ELEMENT_NODE)); in xmlXPathNextChildElement()
6568 * Traversal function for the "descendant-or-self" axis.
6582 switch (contextNode->type) {
6597 switch (cur->type) {
6604 if (cur->children != NULL) {
6605 cur = cur->children;
6622 if (cur->next != NULL) {
6623 cur = cur->next;
6625 cur = cur->parent;
6647 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextDescendant()
6649 if (ctxt->context->node == NULL) in xmlXPathNextDescendant()
6651 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextDescendant()
6652 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextDescendant()
6655 if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextDescendant()
6656 return(ctxt->context->doc->children); in xmlXPathNextDescendant()
6657 return(ctxt->context->node->children); in xmlXPathNextDescendant()
6660 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNextDescendant()
6662 if (cur->children != NULL) { in xmlXPathNextDescendant()
6666 if (cur->children->type != XML_ENTITY_DECL) { in xmlXPathNextDescendant()
6667 cur = cur->children; in xmlXPathNextDescendant()
6671 if (cur->type != XML_DTD_NODE) in xmlXPathNextDescendant()
6676 if (cur == ctxt->context->node) return(NULL); in xmlXPathNextDescendant()
6678 while (cur->next != NULL) { in xmlXPathNextDescendant()
6679 cur = cur->next; in xmlXPathNextDescendant()
6680 if ((cur->type != XML_ENTITY_DECL) && in xmlXPathNextDescendant()
6681 (cur->type != XML_DTD_NODE)) in xmlXPathNextDescendant()
6686 cur = cur->parent; in xmlXPathNextDescendant()
6688 if (cur == ctxt->context->node) return(NULL); in xmlXPathNextDescendant()
6689 if (cur->next != NULL) { in xmlXPathNextDescendant()
6690 cur = cur->next; in xmlXPathNextDescendant()
6702 * Traversal function for the "descendant-or-self" direction
6703 * the descendant-or-self axis contains the context node and the descendants
6712 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextDescendantOrSelf()
6714 return(ctxt->context->node); in xmlXPathNextDescendantOrSelf()
6716 if (ctxt->context->node == NULL) in xmlXPathNextDescendantOrSelf()
6718 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextDescendantOrSelf()
6719 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextDescendantOrSelf()
6737 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextParent()
6744 if (ctxt->context->node == NULL) return(NULL); in xmlXPathNextParent()
6745 switch (ctxt->context->node->type) { in xmlXPathNextParent()
6760 if (ctxt->context->node->parent == NULL) in xmlXPathNextParent()
6761 return((xmlNodePtr) ctxt->context->doc); in xmlXPathNextParent()
6762 if ((ctxt->context->node->parent->type == XML_ELEMENT_NODE) && in xmlXPathNextParent()
6763 ((ctxt->context->node->parent->name[0] == ' ') || in xmlXPathNextParent()
6764 (xmlStrEqual(ctxt->context->node->parent->name, in xmlXPathNextParent()
6767 return(ctxt->context->node->parent); in xmlXPathNextParent()
6769 xmlAttrPtr att = (xmlAttrPtr) ctxt->context->node; in xmlXPathNextParent()
6771 return(att->parent); in xmlXPathNextParent()
6779 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node; in xmlXPathNextParent()
6781 if ((ns->next != NULL) && in xmlXPathNextParent()
6782 (ns->next->type != XML_NAMESPACE_DECL)) in xmlXPathNextParent()
6783 return((xmlNodePtr) ns->next); in xmlXPathNextParent()
6807 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextAncestor()
6814 if (ctxt->context->node == NULL) return(NULL); in xmlXPathNextAncestor()
6815 switch (ctxt->context->node->type) { in xmlXPathNextAncestor()
6830 if (ctxt->context->node->parent == NULL) in xmlXPathNextAncestor()
6831 return((xmlNodePtr) ctxt->context->doc); in xmlXPathNextAncestor()
6832 if ((ctxt->context->node->parent->type == XML_ELEMENT_NODE) && in xmlXPathNextAncestor()
6833 ((ctxt->context->node->parent->name[0] == ' ') || in xmlXPathNextAncestor()
6834 (xmlStrEqual(ctxt->context->node->parent->name, in xmlXPathNextAncestor()
6837 return(ctxt->context->node->parent); in xmlXPathNextAncestor()
6839 xmlAttrPtr tmp = (xmlAttrPtr) ctxt->context->node; in xmlXPathNextAncestor()
6841 return(tmp->parent); in xmlXPathNextAncestor()
6849 xmlNsPtr ns = (xmlNsPtr) ctxt->context->node; in xmlXPathNextAncestor()
6851 if ((ns->next != NULL) && in xmlXPathNextAncestor()
6852 (ns->next->type != XML_NAMESPACE_DECL)) in xmlXPathNextAncestor()
6853 return((xmlNodePtr) ns->next); in xmlXPathNextAncestor()
6860 if (cur == ctxt->context->doc->children) in xmlXPathNextAncestor()
6861 return((xmlNodePtr) ctxt->context->doc); in xmlXPathNextAncestor()
6862 if (cur == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextAncestor()
6864 switch (cur->type) { in xmlXPathNextAncestor()
6879 if (cur->parent == NULL) in xmlXPathNextAncestor()
6881 if ((cur->parent->type == XML_ELEMENT_NODE) && in xmlXPathNextAncestor()
6882 ((cur->parent->name[0] == ' ') || in xmlXPathNextAncestor()
6883 (xmlStrEqual(cur->parent->name, in xmlXPathNextAncestor()
6886 return(cur->parent); in xmlXPathNextAncestor()
6890 return(att->parent); in xmlXPathNextAncestor()
6895 if ((ns->next != NULL) && in xmlXPathNextAncestor()
6896 (ns->next->type != XML_NAMESPACE_DECL)) in xmlXPathNextAncestor()
6897 return((xmlNodePtr) ns->next); in xmlXPathNextAncestor()
6915 * Traversal function for the "ancestor-or-self" direction
6916 * he ancestor-or-self axis contains the context node and ancestors of
6925 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextAncestorOrSelf()
6927 return(ctxt->context->node); in xmlXPathNextAncestorOrSelf()
6936 * Traversal function for the "following-sibling" direction
6937 * The following-sibling axis contains the following siblings of the context
6944 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextFollowingSibling()
6945 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextFollowingSibling()
6946 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextFollowingSibling()
6948 if (cur == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextFollowingSibling()
6951 return(ctxt->context->node->next); in xmlXPathNextFollowingSibling()
6952 return(cur->next); in xmlXPathNextFollowingSibling()
6960 * Traversal function for the "preceding-sibling" direction
6961 * The preceding-sibling axis contains the preceding siblings of the context
6969 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextPrecedingSibling()
6970 if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || in xmlXPathNextPrecedingSibling()
6971 (ctxt->context->node->type == XML_NAMESPACE_DECL)) in xmlXPathNextPrecedingSibling()
6973 if (cur == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextPrecedingSibling()
6976 return(ctxt->context->node->prev); in xmlXPathNextPrecedingSibling()
6977 if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) { in xmlXPathNextPrecedingSibling()
6978 cur = cur->prev; in xmlXPathNextPrecedingSibling()
6980 return(ctxt->context->node->prev); in xmlXPathNextPrecedingSibling()
6982 return(cur->prev); in xmlXPathNextPrecedingSibling()
7000 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextFollowing()
7001 if ((cur != NULL) && (cur->type != XML_ATTRIBUTE_NODE) && in xmlXPathNextFollowing()
7002 (cur->type != XML_NAMESPACE_DECL) && (cur->children != NULL)) in xmlXPathNextFollowing()
7003 return(cur->children); in xmlXPathNextFollowing()
7006 cur = ctxt->context->node; in xmlXPathNextFollowing()
7007 if (cur->type == XML_ATTRIBUTE_NODE) { in xmlXPathNextFollowing()
7008 cur = cur->parent; in xmlXPathNextFollowing()
7009 } else if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNextFollowing()
7012 if ((ns->next == NULL) || in xmlXPathNextFollowing()
7013 (ns->next->type == XML_NAMESPACE_DECL)) in xmlXPathNextFollowing()
7015 cur = (xmlNodePtr) ns->next; in xmlXPathNextFollowing()
7019 if (cur->next != NULL) return(cur->next) ; in xmlXPathNextFollowing()
7021 cur = cur->parent; in xmlXPathNextFollowing()
7023 if (cur == (xmlNodePtr) ctxt->context->doc) return(NULL); in xmlXPathNextFollowing()
7024 if (cur->next != NULL) return(cur->next); in xmlXPathNextFollowing()
7041 if (node->type == XML_NAMESPACE_DECL) in xmlXPathIsAncestor()
7043 if (ancestor->type == XML_NAMESPACE_DECL) in xmlXPathIsAncestor()
7046 if (ancestor->doc != node->doc) return(0); in xmlXPathIsAncestor()
7048 if (ancestor == (xmlNodePtr) node->doc) return(1); in xmlXPathIsAncestor()
7049 if (node == (xmlNodePtr) ancestor->doc) return(0); in xmlXPathIsAncestor()
7050 while (node->parent != NULL) { in xmlXPathIsAncestor()
7051 if (node->parent == ancestor) in xmlXPathIsAncestor()
7053 node = node->parent; in xmlXPathIsAncestor()
7074 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextPreceding()
7076 cur = ctxt->context->node; in xmlXPathNextPreceding()
7077 if (cur->type == XML_ATTRIBUTE_NODE) { in xmlXPathNextPreceding()
7078 cur = cur->parent; in xmlXPathNextPreceding()
7079 } else if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNextPreceding()
7082 if ((ns->next == NULL) || in xmlXPathNextPreceding()
7083 (ns->next->type == XML_NAMESPACE_DECL)) in xmlXPathNextPreceding()
7085 cur = (xmlNodePtr) ns->next; in xmlXPathNextPreceding()
7088 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) in xmlXPathNextPreceding()
7090 if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) in xmlXPathNextPreceding()
7091 cur = cur->prev; in xmlXPathNextPreceding()
7093 if (cur->prev != NULL) { in xmlXPathNextPreceding()
7094 for (cur = cur->prev; cur->last != NULL; cur = cur->last) ; in xmlXPathNextPreceding()
7098 cur = cur->parent; in xmlXPathNextPreceding()
7101 if (cur == ctxt->context->doc->children) in xmlXPathNextPreceding()
7103 } while (xmlXPathIsAncestor(cur, ctxt->context->node)); in xmlXPathNextPreceding()
7118 * state kept in the parser context: ctxt->ancestor.
7126 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextPrecedingInternal()
7128 cur = ctxt->context->node; in xmlXPathNextPrecedingInternal()
7131 if (cur->type == XML_ATTRIBUTE_NODE) { in xmlXPathNextPrecedingInternal()
7132 cur = cur->parent; in xmlXPathNextPrecedingInternal()
7133 } else if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNextPrecedingInternal()
7136 if ((ns->next == NULL) || in xmlXPathNextPrecedingInternal()
7137 (ns->next->type == XML_NAMESPACE_DECL)) in xmlXPathNextPrecedingInternal()
7139 cur = (xmlNodePtr) ns->next; in xmlXPathNextPrecedingInternal()
7141 ctxt->ancestor = cur->parent; in xmlXPathNextPrecedingInternal()
7143 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNextPrecedingInternal()
7145 if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE)) in xmlXPathNextPrecedingInternal()
7146 cur = cur->prev; in xmlXPathNextPrecedingInternal()
7147 while (cur->prev == NULL) { in xmlXPathNextPrecedingInternal()
7148 cur = cur->parent; in xmlXPathNextPrecedingInternal()
7151 if (cur == ctxt->context->doc->children) in xmlXPathNextPrecedingInternal()
7153 if (cur != ctxt->ancestor) in xmlXPathNextPrecedingInternal()
7155 ctxt->ancestor = cur->parent; in xmlXPathNextPrecedingInternal()
7157 cur = cur->prev; in xmlXPathNextPrecedingInternal()
7158 while (cur->last != NULL) in xmlXPathNextPrecedingInternal()
7159 cur = cur->last; in xmlXPathNextPrecedingInternal()
7170 * the order of nodes on this axis is implementation-defined; the axis will
7179 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextNamespace()
7180 if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL); in xmlXPathNextNamespace()
7182 if (ctxt->context->tmpNsList != NULL) in xmlXPathNextNamespace()
7183 xmlFree(ctxt->context->tmpNsList); in xmlXPathNextNamespace()
7184 ctxt->context->tmpNsNr = 0; in xmlXPathNextNamespace()
7185 if (xmlGetNsListSafe(ctxt->context->doc, ctxt->context->node, in xmlXPathNextNamespace()
7186 &ctxt->context->tmpNsList) < 0) { in xmlXPathNextNamespace()
7190 if (ctxt->context->tmpNsList != NULL) { in xmlXPathNextNamespace()
7191 while (ctxt->context->tmpNsList[ctxt->context->tmpNsNr] != NULL) { in xmlXPathNextNamespace()
7192 ctxt->context->tmpNsNr++; in xmlXPathNextNamespace()
7197 if (ctxt->context->tmpNsNr > 0) { in xmlXPathNextNamespace()
7198 return (xmlNodePtr)ctxt->context->tmpNsList[--ctxt->context->tmpNsNr]; in xmlXPathNextNamespace()
7200 if (ctxt->context->tmpNsList != NULL) in xmlXPathNextNamespace()
7201 xmlFree(ctxt->context->tmpNsList); in xmlXPathNextNamespace()
7202 ctxt->context->tmpNsList = NULL; in xmlXPathNextNamespace()
7219 if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL); in xmlXPathNextAttribute()
7220 if (ctxt->context->node == NULL) in xmlXPathNextAttribute()
7222 if (ctxt->context->node->type != XML_ELEMENT_NODE) in xmlXPathNextAttribute()
7225 if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc) in xmlXPathNextAttribute()
7227 return((xmlNodePtr)ctxt->context->node->properties); in xmlXPathNextAttribute()
7229 return((xmlNodePtr)cur->next); in xmlXPathNextAttribute()
7255 if ((ctxt == NULL) || (ctxt->context == NULL)) in xmlXPathRoot()
7258 (xmlNodePtr) ctxt->context->doc)); in xmlXPathRoot()
7264 *http://www.w3.org/Style/XSL/Group/1999/07/xpath-19990705.html#corelib *
7281 if (ctxt->context->contextSize >= 0) { in xmlXPathLastFunction()
7283 xmlXPathCacheNewFloat(ctxt, (double) ctxt->context->contextSize)); in xmlXPathLastFunction()
7303 if (ctxt->context->proximityPosition >= 0) { in xmlXPathPositionFunction()
7305 (double) ctxt->context->proximityPosition)); in xmlXPathPositionFunction()
7317 * number count(node-set)
7324 if ((ctxt->value == NULL) || in xmlXPathCountFunction()
7325 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathCountFunction()
7326 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathCountFunction()
7330 if ((cur == NULL) || (cur->nodesetval == NULL)) in xmlXPathCountFunction()
7334 (double) cur->nodesetval->nodeNr)); in xmlXPathCountFunction()
7335 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathCountFunction()
7345 * Returns a node-set of selected elements.
7366 ID = xmlStrndup(ids, cur - ids); in xmlXPathGetElementsByIds()
7381 if (attr->type == XML_ATTRIBUTE_NODE) in xmlXPathGetElementsByIds()
7382 elem = attr->parent; in xmlXPathGetElementsByIds()
7383 else if (attr->type == XML_ELEMENT_NODE) in xmlXPathGetElementsByIds()
7407 * node-set id(object)
7409 * (see [5.2.1 Unique IDs]). When the argument to id is of type node-set,
7411 * string value of each of the nodes in the argument node-set. When the
7414 * into a whitespace-separated list of tokens (whitespace is any sequence
7415 * of characters matching the production S); the result is a node-set
7428 if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) { in xmlXPathIdFunction()
7436 if (obj->nodesetval != NULL) { in xmlXPathIdFunction()
7437 for (i = 0; i < obj->nodesetval->nodeNr; i++) { in xmlXPathIdFunction()
7439 xmlXPathCastNodeToString(obj->nodesetval->nodeTab[i]); in xmlXPathIdFunction()
7442 ns = xmlXPathGetElementsByIds(ctxt->context->doc, tokens); in xmlXPathIdFunction()
7453 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathIdFunction()
7460 xmlXPathReleaseObject(ctxt->context, obj); in xmlXPathIdFunction()
7461 ret = xmlXPathGetElementsByIds(ctxt->context->doc, tokens); in xmlXPathIdFunction()
7474 * Implement the local-name() XPath function
7475 * string local-name(node-set?)
7476 * The local-name function returns a string containing the local part
7477 * of the name of the node in the argument node-set that is first in
7478 * document order. If the node-set is empty or the first node has no
7489 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt, ctxt->context->node)); in xmlXPathLocalNameFunction()
7494 if ((ctxt->value == NULL) || in xmlXPathLocalNameFunction()
7495 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathLocalNameFunction()
7496 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathLocalNameFunction()
7500 if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { in xmlXPathLocalNameFunction()
7504 switch (cur->nodesetval->nodeTab[i]->type) { in xmlXPathLocalNameFunction()
7508 if (cur->nodesetval->nodeTab[i]->name[0] == ' ') in xmlXPathLocalNameFunction()
7512 cur->nodesetval->nodeTab[i]->name)); in xmlXPathLocalNameFunction()
7516 ((xmlNsPtr)cur->nodesetval->nodeTab[i])->prefix)); in xmlXPathLocalNameFunction()
7522 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathLocalNameFunction()
7530 * Implement the namespace-uri() XPath function
7531 * string namespace-uri(node-set?)
7532 * The namespace-uri function returns a string containing the
7534 * node-set that is first in document order. If the node-set is empty,
7546 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt, ctxt->context->node)); in xmlXPathNamespaceURIFunction()
7550 if ((ctxt->value == NULL) || in xmlXPathNamespaceURIFunction()
7551 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathNamespaceURIFunction()
7552 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathNamespaceURIFunction()
7556 if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { in xmlXPathNamespaceURIFunction()
7560 switch (cur->nodesetval->nodeTab[i]->type) { in xmlXPathNamespaceURIFunction()
7563 if (cur->nodesetval->nodeTab[i]->ns == NULL) in xmlXPathNamespaceURIFunction()
7567 cur->nodesetval->nodeTab[i]->ns->href)); in xmlXPathNamespaceURIFunction()
7573 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathNamespaceURIFunction()
7582 * string name(node-set?)
7584 * the name of the node in the argument node-set that is first in document
7604 valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt, ctxt->context->node)); in xmlXPathNameFunction()
7609 if ((ctxt->value == NULL) || in xmlXPathNameFunction()
7610 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathNameFunction()
7611 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathNameFunction()
7615 if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { in xmlXPathNameFunction()
7620 switch (cur->nodesetval->nodeTab[i]->type) { in xmlXPathNameFunction()
7623 if (cur->nodesetval->nodeTab[i]->name[0] == ' ') in xmlXPathNameFunction()
7626 else if ((cur->nodesetval->nodeTab[i]->ns == NULL) || in xmlXPathNameFunction()
7627 (cur->nodesetval->nodeTab[i]->ns->prefix == NULL)) { in xmlXPathNameFunction()
7629 cur->nodesetval->nodeTab[i]->name)); in xmlXPathNameFunction()
7633 fullname = xmlBuildQName(cur->nodesetval->nodeTab[i]->name, in xmlXPathNameFunction()
7634 cur->nodesetval->nodeTab[i]->ns->prefix, in xmlXPathNameFunction()
7636 if (fullname == cur->nodesetval->nodeTab[i]->name) in xmlXPathNameFunction()
7637 fullname = xmlStrdup(cur->nodesetval->nodeTab[i]->name); in xmlXPathNameFunction()
7645 cur->nodesetval->nodeTab[i])); in xmlXPathNameFunction()
7649 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathNameFunction()
7661 * - A node-set is converted to a string by returning the value of
7662 * the node in the node-set that is first in document order.
7663 * If the node-set is empty, an empty string is returned.
7664 * - A number is converted to a string as follows
7669 * + negative infinity is converted to the string -Infinity
7672 * zeros, preceded by a minus sign (-) if the number is negative
7676 * decimal point, preceded by a minus sign (-) if the number
7683 * - The boolean false value is converted to the string false.
7686 * If the argument is omitted, it defaults to a node-set with the
7696 stringval = xmlXPathCastNodeToString(ctxt->context->node); in xmlXPathStringFunction()
7706 if (cur->type != XPATH_STRING) { in xmlXPathStringFunction()
7710 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathStringFunction()
7721 * Implement the string-length() XPath function
7722 * number string-length(string?)
7723 * The string-length returns the number of characters in the string
7733 if ((ctxt == NULL) || (ctxt->context == NULL)) in xmlXPathStringLengthFunction()
7735 if (ctxt->context->node == NULL) { in xmlXPathStringLengthFunction()
7740 content = xmlXPathCastNodeToString(ctxt->context->node); in xmlXPathStringLengthFunction()
7754 xmlUTF8Strlen(cur->stringval))); in xmlXPathStringLengthFunction()
7755 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathStringLengthFunction()
7779 if ((cur == NULL) || (cur->type != XPATH_STRING)) { in xmlXPathConcatFunction()
7780 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathConcatFunction()
7783 nargs--; in xmlXPathConcatFunction()
7788 if ((newobj == NULL) || (newobj->type != XPATH_STRING)) { in xmlXPathConcatFunction()
7789 xmlXPathReleaseObject(ctxt->context, newobj); in xmlXPathConcatFunction()
7790 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathConcatFunction()
7793 tmp = xmlStrcat(newobj->stringval, cur->stringval); in xmlXPathConcatFunction()
7796 newobj->stringval = cur->stringval; in xmlXPathConcatFunction()
7797 cur->stringval = tmp; in xmlXPathConcatFunction()
7798 xmlXPathReleaseObject(ctxt->context, newobj); in xmlXPathConcatFunction()
7799 nargs--; in xmlXPathConcatFunction()
7825 if ((hay == NULL) || (hay->type != XPATH_STRING)) { in xmlXPathContainsFunction()
7826 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathContainsFunction()
7827 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathContainsFunction()
7830 if (xmlStrstr(hay->stringval, needle->stringval)) in xmlXPathContainsFunction()
7834 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathContainsFunction()
7835 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathContainsFunction()
7843 * Implement the starts-with() XPath function
7844 * boolean starts-with(string, string)
7845 * The starts-with function returns true if the first argument string
7860 if ((hay == NULL) || (hay->type != XPATH_STRING)) { in xmlXPathStartsWithFunction()
7861 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathStartsWithFunction()
7862 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathStartsWithFunction()
7865 n = xmlStrlen(needle->stringval); in xmlXPathStartsWithFunction()
7866 if (xmlStrncmp(hay->stringval, needle->stringval, n)) in xmlXPathStartsWithFunction()
7870 xmlXPathReleaseObject(ctxt->context, hay); in xmlXPathStartsWithFunction()
7871 xmlXPathReleaseObject(ctxt->context, needle); in xmlXPathStartsWithFunction()
7895 * - substring("12345", 1.5, 2.6) returns "234"
7896 * - substring("12345", 0, 3) returns "12"
7897 * - substring("12345", 0 div 0, 3) returns ""
7898 * - substring("12345", 1, 0 div 0) returns ""
7899 * - substring("12345", -42, 1 div 0) returns "12345"
7900 * - substring("12345", -1 div 0, 1 div 0) returns ""
7921 le = len->floatval; in xmlXPathSubstringFunction()
7922 xmlXPathReleaseObject(ctxt->context, len); in xmlXPathSubstringFunction()
7928 in = start->floatval; in xmlXPathSubstringFunction()
7929 xmlXPathReleaseObject(ctxt->context, start); in xmlXPathSubstringFunction()
7938 if (in - floor(in) >= 0.5) in xmlXPathSubstringFunction()
7946 if (in - rin >= 0.5) in xmlXPathSubstringFunction()
7950 if (le - rle >= 0.5) in xmlXPathSubstringFunction()
7961 i -= 1; in xmlXPathSubstringFunction()
7962 j -= 1; in xmlXPathSubstringFunction()
7964 if ((i < j) && (i < xmlUTF8Strlen(str->stringval))) { in xmlXPathSubstringFunction()
7965 xmlChar *ret = xmlUTF8Strsub(str->stringval, i, j - i); in xmlXPathSubstringFunction()
7974 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathSubstringFunction()
7982 * Implement the substring-before() XPath function
7983 * string substring-before(string, string)
7984 * The substring-before function returns the substring of the first
7988 * string. For example, substring-before("1999/04/01","/") returns 1999.
8002 if (ctxt->error != 0) in xmlXPathSubstringBeforeFunction()
8005 point = xmlStrstr(str->stringval, find->stringval); in xmlXPathSubstringBeforeFunction()
8009 result = xmlStrndup(str->stringval, point - str->stringval); in xmlXPathSubstringBeforeFunction()
8018 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathSubstringBeforeFunction()
8019 xmlXPathReleaseObject(ctxt->context, find); in xmlXPathSubstringBeforeFunction()
8027 * Implement the substring-after() XPath function
8028 * string substring-after(string, string)
8029 * The substring-after function returns the substring of the first
8033 * string. For example, substring-after("1999/04/01","/") returns 04/01,
8034 * and substring-after("1999/04/01","19") returns 99/04/01.
8048 if (ctxt->error != 0) in xmlXPathSubstringAfterFunction()
8051 point = xmlStrstr(str->stringval, find->stringval); in xmlXPathSubstringAfterFunction()
8055 result = xmlStrdup(point + xmlStrlen(find->stringval)); in xmlXPathSubstringAfterFunction()
8064 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathSubstringAfterFunction()
8065 xmlXPathReleaseObject(ctxt->context, find); in xmlXPathSubstringAfterFunction()
8073 * Implement the normalize-space() XPath function
8074 * string normalize-space(string?)
8075 * The normalize-space function returns the argument string with white
8090 source = xmlXPathCastNodeToString(ctxt->context->node); in xmlXPathNormalizeFunction()
8100 source = ctxt->value->stringval; in xmlXPathNormalizeFunction()
8141 * string are removed. For example, translate("--aaa--","abc-","ABC")
8166 if (ctxt->error != 0) in xmlXPathTranslateFunction()
8172 if (ctxt->context->opLimit != 0) { in xmlXPathTranslateFunction()
8173 unsigned long f1 = xmlStrlen(from->stringval); in xmlXPathTranslateFunction()
8174 unsigned long f2 = xmlStrlen(str->stringval); in xmlXPathTranslateFunction()
8193 max = xmlUTF8Strlen(to->stringval); in xmlXPathTranslateFunction()
8194 for (cptr = str->stringval; (ch=*cptr); ) { in xmlXPathTranslateFunction()
8195 offset = xmlUTF8Strloc(from->stringval, cptr); in xmlXPathTranslateFunction()
8198 point = xmlUTF8Strpos(to->stringval, offset); in xmlXPathTranslateFunction()
8231 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathTranslateFunction()
8232 xmlXPathReleaseObject(ctxt->context, from); in xmlXPathTranslateFunction()
8233 xmlXPathReleaseObject(ctxt->context, to); in xmlXPathTranslateFunction()
8244 * - a number is true if and only if it is neither positive or
8246 * - a node-set is true if and only if it is non-empty
8247 * - a string is true if and only if its length is non-zero
8256 if (cur->type != XPATH_BOOLEAN) { in xmlXPathBooleanFunction()
8259 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathBooleanFunction()
8280 ctxt->value->boolval = ! ctxt->value->boolval; in xmlXPathNotFunction()
8328 * or if there is some suffix starting with - such that the attribute
8345 lang = val->stringval; in xmlXPathLangFunction()
8346 cur = ctxt->context->node; in xmlXPathLangFunction()
8353 cur = cur->parent; in xmlXPathLangFunction()
8359 if ((theLang[i] == 0) || (theLang[i] == '-')) in xmlXPathLangFunction()
8366 xmlXPathReleaseObject(ctxt->context, val); in xmlXPathLangFunction()
8385 if (ctxt->context->node == NULL) { in xmlXPathNumberFunction()
8388 xmlChar* content = xmlNodeGetContent(ctxt->context->node); in xmlXPathNumberFunction()
8401 if (cur->type != XPATH_NUMBER) { in xmlXPathNumberFunction()
8405 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathNumberFunction()
8417 * number sum(node-set)
8419 * the argument node-set.
8428 if ((ctxt->value == NULL) || in xmlXPathSumFunction()
8429 ((ctxt->value->type != XPATH_NODESET) && in xmlXPathSumFunction()
8430 (ctxt->value->type != XPATH_XSLT_TREE))) in xmlXPathSumFunction()
8434 if ((cur->nodesetval != NULL) && (cur->nodesetval->nodeNr != 0)) { in xmlXPathSumFunction()
8435 for (i = 0; i < cur->nodesetval->nodeNr; i++) { in xmlXPathSumFunction()
8437 cur->nodesetval->nodeTab[i]); in xmlXPathSumFunction()
8441 xmlXPathReleaseObject(ctxt->context, cur); in xmlXPathSumFunction()
8460 ctxt->value->floatval = floor(ctxt->value->floatval); in xmlXPathFloorFunction()
8481 ctxt->value->floatval = copysign(ceil(ctxt->value->floatval), ctxt->value->floatval); in xmlXPathCeilingFunction()
8483 ctxt->value->floatval = ceil(ctxt->value->floatval); in xmlXPathCeilingFunction()
8506 f = ctxt->value->floatval; in xmlXPathRoundFunction()
8508 if ((f >= -0.5) && (f < 0.5)) { in xmlXPathRoundFunction()
8510 ctxt->value->floatval *= 0.0; in xmlXPathRoundFunction()
8514 if (f - rounded >= 0.5) in xmlXPathRoundFunction()
8516 ctxt->value->floatval = rounded; in xmlXPathRoundFunction()
8543 * The current char value, if using UTF-8 this may actually span multiple
8557 cur = ctxt->cur; in xmlXPathCurrentChar()
8561 * From rfc2044: encoding of the Unicode values on UTF-8: in xmlXPathCurrentChar()
8563 * UCS-4 range (hex.) UTF-8 octet sequence (binary) in xmlXPathCurrentChar()
8564 * 0000 0000-0000 007F 0xxxxxxx in xmlXPathCurrentChar()
8565 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx in xmlXPathCurrentChar()
8566 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx in xmlXPathCurrentChar()
8582 /* 4-byte code */ in xmlXPathCurrentChar()
8589 /* 3-byte code */ in xmlXPathCurrentChar()
8596 /* 2-byte code */ in xmlXPathCurrentChar()
8606 /* 1-byte code */ in xmlXPathCurrentChar()
8615 * to ISO-Latin-1 (if you don't like this policy, just declare the in xmlXPathCurrentChar()
8630 * [NS 4] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
8642 if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL); in xmlXPathParseNCName()
8646 in = ctxt->cur; in xmlXPathParseNCName()
8655 (*in == '-')) in xmlXPathParseNCName()
8660 count = in - ctxt->cur; in xmlXPathParseNCName()
8663 ret = xmlStrndup(ctxt->cur, count); in xmlXPathParseNCName()
8666 ctxt->cur = in; in xmlXPathParseNCName()
8711 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
8725 if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL); in xmlXPathParseName()
8729 in = ctxt->cur; in xmlXPathParseName()
8737 (*in == '_') || (*in == '-') || in xmlXPathParseName()
8741 count = in - ctxt->cur; in xmlXPathParseName()
8743 ctxt->cur = in; in xmlXPathParseName()
8746 ret = xmlStrndup(ctxt->cur, count); in xmlXPathParseName()
8749 ctxt->cur = in; in xmlXPathParseName()
8777 (c == '.') || (c == '-') || in xmlXPathParseNameComplex()
8802 (c == '.') || (c == '-') || in xmlXPathParseNameComplex()
8847 * [31] Digits ::= [0-9]+
8851 * negative values : '-' Number.
8869 if (*cur == '-') { in xmlXPathStringEvalNumber()
8885 tmp = (*cur - '0'); in xmlXPathStringEvalNumber()
8894 ret = ret * 10 + (*cur - '0'); in xmlXPathStringEvalNumber()
8914 v = (*cur - '0'); in xmlXPathStringEvalNumber()
8926 if (*cur == '-') { in xmlXPathStringEvalNumber()
8934 exponent = exponent * 10 + (*cur - '0'); in xmlXPathStringEvalNumber()
8940 if (isneg) ret = -ret; in xmlXPathStringEvalNumber()
8941 if (is_exponent_negative) exponent = -exponent; in xmlXPathStringEvalNumber()
8952 * [31] Digits ::= [0-9]+
8982 tmp = (CUR - '0'); in xmlXPathCompNumber()
8991 ret = ret * 10 + (CUR - '0'); in xmlXPathCompNumber()
9010 v = (CUR - '0'); in xmlXPathCompNumber()
9022 if (CUR == '-') { in xmlXPathCompNumber()
9030 exponent = exponent * 10 + (CUR - '0'); in xmlXPathCompNumber()
9034 exponent = -exponent; in xmlXPathCompNumber()
9039 ctxt->error = XPATH_MEMORY_ERROR; in xmlXPathCompNumber()
9041 NULL) == -1) { in xmlXPathCompNumber()
9042 xmlXPathReleaseObject(ctxt->context, num); in xmlXPathCompNumber()
9084 ret = xmlStrndup(q, CUR_PTR - q); in xmlXPathParseLiteral()
9112 ctxt->error = XPATH_MEMORY_ERROR; in xmlXPathCompLiteral()
9114 NULL) == -1) { in xmlXPathCompLiteral()
9115 xmlXPathReleaseObject(ctxt->context, lit); in xmlXPathCompLiteral()
9152 ctxt->comp->last = -1; in xmlXPathCompVariableReference()
9153 if (PUSH_LONG_EXPR(XPATH_OP_VARIABLE, 0, 0, 0, name, prefix) == -1) { in xmlXPathCompVariableReference()
9158 if ((ctxt->context != NULL) && (ctxt->context->flags & XML_XPATH_NOVAR)) { in xmlXPathCompVariableReference()
9171 * | 'processing-instruction'
9187 if (xmlStrEqual(name, BAD_CAST "processing-instruction")) in xmlXPathIsNodeType()
9225 * Optimization for count(): we don't need the node-set to be sorted. in xmlXPathCompFunctionCall()
9232 ctxt->comp->last = -1; in xmlXPathCompFunctionCall()
9235 int op1 = ctxt->comp->last; in xmlXPathCompFunctionCall()
9236 ctxt->comp->last = -1; in xmlXPathCompFunctionCall()
9238 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompFunctionCall()
9243 PUSH_BINARY_EXPR(XPATH_OP_ARG, op1, ctxt->comp->last, 0, 0); in xmlXPathCompFunctionCall()
9255 if (PUSH_LONG_EXPR(XPATH_OP_FUNCTION, nbargs, 0, 0, name, prefix) == -1) { in xmlXPathCompFunctionCall()
9309 * be filtered does not evaluate to a node-set. The context node list
9310 * used for evaluating the expression in square brackets is the node-set
9335 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
9352 cur = ctxt->cur; in xmlXPathScanName()
9363 (c == '.') || (c == '-') || in xmlXPathScanName()
9370 ret = xmlStrndup(cur, ctxt->cur - cur); in xmlXPathScanName()
9373 ctxt->cur = cur; in xmlXPathScanName()
9389 * does not evaluate to a node-set.
9392 * /descendant-or-self::node()/.
9421 * - a nodetype in xmlXPathCompPathExpr()
9422 * - a function call in which case it's followed by '(' in xmlXPathCompPathExpr()
9423 * - an axis in which case it's followed by ':' in xmlXPathCompPathExpr()
9424 * - a element name in xmlXPathCompPathExpr()
9524 int op1 = ctxt->comp->last; in xmlXPathCompUnionExpr()
9531 PUSH_BINARY_EXPR(XPATH_OP_UNION, op1, ctxt->comp->last, 0, 0); in xmlXPathCompUnionExpr()
9542 * | '-' UnaryExpr
9553 while (CUR == '-') { in xmlXPathCompUnaryExpr()
9554 minus = 1 - minus; in xmlXPathCompUnaryExpr()
9564 PUSH_UNARY_EXPR(XPATH_OP_PLUS, ctxt->comp->last, 2, 0); in xmlXPathCompUnaryExpr()
9566 PUSH_UNARY_EXPR(XPATH_OP_PLUS, ctxt->comp->last, 3, 0); in xmlXPathCompUnaryExpr()
9591 int op = -1; in xmlXPathCompMultiplicativeExpr()
9592 int op1 = ctxt->comp->last; in xmlXPathCompMultiplicativeExpr()
9607 PUSH_BINARY_EXPR(XPATH_OP_MULT, op1, ctxt->comp->last, op, 0); in xmlXPathCompMultiplicativeExpr()
9618 * | AdditiveExpr '-' MultiplicativeExpr
9629 while ((CUR == '+') || (CUR == '-')) { in xmlXPathCompAdditiveExpr()
9631 int op1 = ctxt->comp->last; in xmlXPathCompAdditiveExpr()
9639 PUSH_BINARY_EXPR(XPATH_OP_PLUS, op1, ctxt->comp->last, plus, 0); in xmlXPathCompAdditiveExpr()
9669 int op1 = ctxt->comp->last; in xmlXPathCompRelationalExpr()
9680 PUSH_BINARY_EXPR(XPATH_OP_CMP, op1, ctxt->comp->last, inf, strict); in xmlXPathCompRelationalExpr()
9708 int op1 = ctxt->comp->last; in xmlXPathCompEqualityExpr()
9717 PUSH_BINARY_EXPR(XPATH_OP_EQUAL, op1, ctxt->comp->last, eq, 0); in xmlXPathCompEqualityExpr()
9738 int op1 = ctxt->comp->last; in xmlXPathCompAndExpr()
9743 PUSH_BINARY_EXPR(XPATH_OP_AND, op1, ctxt->comp->last, 0, 0); in xmlXPathCompAndExpr()
9760 xmlXPathContextPtr xpctxt = ctxt->context; in xmlXPathCompileExpr()
9763 if (xpctxt->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompileExpr()
9769 xpctxt->depth += 10; in xmlXPathCompileExpr()
9776 int op1 = ctxt->comp->last; in xmlXPathCompileExpr()
9781 PUSH_BINARY_EXPR(XPATH_OP_OR, op1, ctxt->comp->last, 0, 0); in xmlXPathCompileExpr()
9784 if ((sort) && (ctxt->comp->steps[ctxt->comp->last].op != XPATH_OP_VALUE)) { in xmlXPathCompileExpr()
9788 * operations which don't require a sorted node-set. in xmlXPathCompileExpr()
9791 PUSH_UNARY_EXPR(XPATH_OP_SORT, ctxt->comp->last , 0, 0); in xmlXPathCompileExpr()
9795 xpctxt->depth -= 10; in xmlXPathCompileExpr()
9810 int op1 = ctxt->comp->last; in xmlXPathCompPredicate()
9819 ctxt->comp->last = -1; in xmlXPathCompPredicate()
9840 PUSH_BINARY_EXPR(XPATH_OP_FILTER, op1, ctxt->comp->last, 0, 0); in xmlXPathCompPredicate()
9842 PUSH_BINARY_EXPR(XPATH_OP_PREDICATE, op1, ctxt->comp->last, 0, 0); in xmlXPathCompPredicate()
9857 * | 'processing-instruction' '(' Literal ')'
9864 * | 'processing-instruction'
9909 else if (xmlStrEqual(name, BAD_CAST "processing-instruction")) in xmlXPathCompNodeTest()
9955 *prefix = xmlXPathNsLookup(ctxt->context, name); in xmlXPathCompNodeTest()
9987 * | 'ancestor-or-self'
9991 * | 'descendant-or-self'
9993 * | 'following-sibling'
9997 * | 'preceding-sibling'
10009 if (xmlStrEqual(name, BAD_CAST "ancestor-or-self")) in xmlXPathIsAxisName()
10021 if (xmlStrEqual(name, BAD_CAST "descendant-or-self")) in xmlXPathIsAxisName()
10027 if (xmlStrEqual(name, BAD_CAST "following-sibling")) in xmlXPathIsAxisName()
10039 if (xmlStrEqual(name, BAD_CAST "preceding-sibling")) in xmlXPathIsAxisName()
10068 * | 'range-to' '(' Expr ')' Predicate*
10074 * self::node()/descendant-or-self::node()/child::para
10115 /* an element name can conflict with an axis one :-\ */ in xmlXPathCompStep()
10129 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathCompStep()
10138 if ((prefix != NULL) && (ctxt->context != NULL) && in xmlXPathCompStep()
10139 (ctxt->context->flags & XML_XPATH_CHECKNS)) { in xmlXPathCompStep()
10140 if (xmlXPathNsLookup(ctxt->context, prefix) == NULL) { in xmlXPathCompStep()
10145 op1 = ctxt->comp->last; in xmlXPathCompStep()
10146 ctxt->comp->last = -1; in xmlXPathCompStep()
10153 if (PUSH_FULL_EXPR(XPATH_OP_COLLECT, op1, ctxt->comp->last, axis, in xmlXPathCompStep()
10154 test, type, (void *)prefix, (void *)name) == -1) { in xmlXPathCompStep()
10217 * // is short for /descendant-or-self::node()/. For example,
10218 * //para is short for /descendant-or-self::node()/child::para and
10222 * short for div/descendant-or-self::node()/child::para and so will
10265 * @minPos: minimum position in the filtered set (1-based)
10266 * @maxPos: maximum position in the filtered set (1-based)
10287 if ((set == NULL) || (set->nodeNr == 0)) in xmlXPathNodeSetFilter()
10294 if (set->nodeNr < minPos) { in xmlXPathNodeSetFilter()
10299 xpctxt = ctxt->context; in xmlXPathNodeSetFilter()
10300 oldnode = xpctxt->node; in xmlXPathNodeSetFilter()
10301 olddoc = xpctxt->doc; in xmlXPathNodeSetFilter()
10302 oldcs = xpctxt->contextSize; in xmlXPathNodeSetFilter()
10303 oldpp = xpctxt->proximityPosition; in xmlXPathNodeSetFilter()
10304 filterOp = &ctxt->comp->steps[filterOpIndex]; in xmlXPathNodeSetFilter()
10306 xpctxt->contextSize = set->nodeNr; in xmlXPathNodeSetFilter()
10308 for (i = 0, j = 0, pos = 1; i < set->nodeNr; i++) { in xmlXPathNodeSetFilter()
10309 xmlNodePtr node = set->nodeTab[i]; in xmlXPathNodeSetFilter()
10312 xpctxt->node = node; in xmlXPathNodeSetFilter()
10313 xpctxt->proximityPosition = i + 1; in xmlXPathNodeSetFilter()
10321 if ((node->type != XML_NAMESPACE_DECL) && in xmlXPathNodeSetFilter()
10322 (node->doc != NULL)) in xmlXPathNodeSetFilter()
10323 xpctxt->doc = node->doc; in xmlXPathNodeSetFilter()
10327 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathNodeSetFilter()
10337 set->nodeTab[j] = node; in xmlXPathNodeSetFilter()
10338 set->nodeTab[i] = NULL; in xmlXPathNodeSetFilter()
10344 set->nodeTab[i] = NULL; in xmlXPathNodeSetFilter()
10345 if (node->type == XML_NAMESPACE_DECL) in xmlXPathNodeSetFilter()
10361 for (; i < set->nodeNr; i++) { in xmlXPathNodeSetFilter()
10362 xmlNodePtr node = set->nodeTab[i]; in xmlXPathNodeSetFilter()
10363 if ((node != NULL) && (node->type == XML_NAMESPACE_DECL)) in xmlXPathNodeSetFilter()
10368 set->nodeNr = j; in xmlXPathNodeSetFilter()
10371 if ((set->nodeMax > XML_NODESET_DEFAULT) && in xmlXPathNodeSetFilter()
10372 (set->nodeNr < set->nodeMax / 2)) { in xmlXPathNodeSetFilter()
10374 int nodeMax = set->nodeNr; in xmlXPathNodeSetFilter()
10378 tmp = (xmlNodePtr *) xmlRealloc(set->nodeTab, in xmlXPathNodeSetFilter()
10383 set->nodeTab = tmp; in xmlXPathNodeSetFilter()
10384 set->nodeMax = nodeMax; in xmlXPathNodeSetFilter()
10388 xpctxt->node = oldnode; in xmlXPathNodeSetFilter()
10389 xpctxt->doc = olddoc; in xmlXPathNodeSetFilter()
10390 xpctxt->contextSize = oldcs; in xmlXPathNodeSetFilter()
10391 xpctxt->proximityPosition = oldpp; in xmlXPathNodeSetFilter()
10399 * @minPos: minimum position in the filtered set (1-based)
10400 * @maxPos: maximum position in the filtered set (1-based)
10414 if (op->ch1 != -1) { in xmlXPathCompOpEvalPredicate()
10415 xmlXPathCompExprPtr comp = ctxt->comp; in xmlXPathCompOpEvalPredicate()
10417 * Process inner predicates first. in xmlXPathCompOpEvalPredicate()
10419 if (comp->steps[op->ch1].op != XPATH_OP_PREDICATE) { in xmlXPathCompOpEvalPredicate()
10422 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEvalPredicate()
10424 ctxt->context->depth += 1; in xmlXPathCompOpEvalPredicate()
10425 xmlXPathCompOpEvalPredicate(ctxt, &comp->steps[op->ch1], set, in xmlXPathCompOpEvalPredicate()
10426 1, set->nodeNr, hasNsNodes); in xmlXPathCompOpEvalPredicate()
10427 ctxt->context->depth -= 1; in xmlXPathCompOpEvalPredicate()
10431 if (op->ch2 != -1) in xmlXPathCompOpEvalPredicate()
10432 xmlXPathNodeSetFilter(ctxt, set, op->ch2, minPos, maxPos, hasNsNodes); in xmlXPathCompOpEvalPredicate()
10448 * If not -1, then ch1 will point to: in xmlXPathIsPositionalPredicate()
10449 * 1) For predicates (XPATH_OP_PREDICATE): in xmlXPathIsPositionalPredicate()
10450 * - an inner predicate operator in xmlXPathIsPositionalPredicate()
10452 * - an inner filter operator OR in xmlXPathIsPositionalPredicate()
10453 * - an expression selecting the node set. in xmlXPathIsPositionalPredicate()
10456 if ((op->op != XPATH_OP_PREDICATE) && (op->op != XPATH_OP_FILTER)) in xmlXPathIsPositionalPredicate()
10459 if (op->ch2 != -1) { in xmlXPathIsPositionalPredicate()
10460 exprOp = &ctxt->comp->steps[op->ch2]; in xmlXPathIsPositionalPredicate()
10465 (exprOp->op == XPATH_OP_VALUE) && in xmlXPathIsPositionalPredicate()
10466 (exprOp->value4 != NULL) && in xmlXPathIsPositionalPredicate()
10467 (((xmlXPathObjectPtr) exprOp->value4)->type == XPATH_NUMBER)) in xmlXPathIsPositionalPredicate()
10469 double floatval = ((xmlXPathObjectPtr) exprOp->value4)->floatval; in xmlXPathIsPositionalPredicate()
10477 * "[position() = 1]"; thus - obviously - a position-range, in xmlXPathIsPositionalPredicate()
10513 if (xmlXPathNodeSetAddNs(seq, xpctxt->node, (xmlNsPtr) cur) < 0) \ in xmlXPathNodeCollectAndTest()
10518 if (xmlXPathNodeSetAddNs(seq, xpctxt->node, (xmlNsPtr) cur) < 0) \ in xmlXPathNodeCollectAndTest()
10522 xmlXPathAxisVal axis = (xmlXPathAxisVal) op->value; in xmlXPathNodeCollectAndTest()
10523 xmlXPathTestVal test = (xmlXPathTestVal) op->value2; in xmlXPathNodeCollectAndTest()
10524 xmlXPathTypeVal type = (xmlXPathTypeVal) op->value3; in xmlXPathNodeCollectAndTest()
10525 const xmlChar *prefix = op->value4; in xmlXPathNodeCollectAndTest()
10526 const xmlChar *name = op->value5; in xmlXPathNodeCollectAndTest()
10554 xmlXPathContextPtr xpctxt = ctxt->context; in xmlXPathNodeCollectAndTest()
10573 * - If the nodes to be traversed wrt to the initial nodes and in xmlXPathNodeCollectAndTest()
10578 * not in the ancestor-or-self axis of the other, then we could safely in xmlXPathNodeCollectAndTest()
10579 * avoid a duplicate-aware merge, if the axis to be traversed is e.g. in xmlXPathNodeCollectAndTest()
10580 * the descendant-or-self axis. in xmlXPathNodeCollectAndTest()
10657 contextSeq = obj->nodesetval; in xmlXPathNodeCollectAndTest()
10658 if ((contextSeq == NULL) || (contextSeq->nodeNr <= 0)) { in xmlXPathNodeCollectAndTest()
10663 * Predicate optimization --------------------------------------------- in xmlXPathNodeCollectAndTest()
10666 * the short-hand form, i.e., "[n]". in xmlXPathNodeCollectAndTest()
10668 * Example - expression "/foo[parent::bar][1]": in xmlXPathNodeCollectAndTest()
10670 * COLLECT 'child' 'name' 'node' foo -- op (we are here) in xmlXPathNodeCollectAndTest()
10671 * ROOT -- op->ch1 in xmlXPathNodeCollectAndTest()
10672 * PREDICATE -- op->ch2 (predOp) in xmlXPathNodeCollectAndTest()
10673 * PREDICATE -- predOp->ch1 = [parent::bar] in xmlXPathNodeCollectAndTest()
10677 * ELEM Object is a number : 1 -- predOp->ch2 = [1] in xmlXPathNodeCollectAndTest()
10684 if (op->ch2 != -1) { in xmlXPathNodeCollectAndTest()
10688 predOp = &ctxt->comp->steps[op->ch2]; in xmlXPathNodeCollectAndTest()
10690 if (predOp->ch1 != -1) { in xmlXPathNodeCollectAndTest()
10694 predOp = &ctxt->comp->steps[predOp->ch1]; in xmlXPathNodeCollectAndTest()
10707 * Axis traversal ----------------------------------------------------- in xmlXPathNodeCollectAndTest()
10711 * - For the attribute axis, the principal node type is attribute. in xmlXPathNodeCollectAndTest()
10712 * - For the namespace axis, the principal node type is namespace. in xmlXPathNodeCollectAndTest()
10713 * - For other axes, the principal node type is element. in xmlXPathNodeCollectAndTest()
10719 oldContextNode = xpctxt->node; in xmlXPathNodeCollectAndTest()
10727 while (((contextIdx < contextSeq->nodeNr) || (contextNode != NULL)) && in xmlXPathNodeCollectAndTest()
10728 (ctxt->error == XPATH_EXPRESSION_OK)) { in xmlXPathNodeCollectAndTest()
10729 xpctxt->node = contextSeq->nodeTab[contextIdx++]; in xmlXPathNodeCollectAndTest()
10791 switch (cur->type) { in xmlXPathNodeCollectAndTest()
10814 } else if (cur->type == (xmlElementType) type) { in xmlXPathNodeCollectAndTest()
10815 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNodeCollectAndTest()
10820 (cur->type == XML_CDATA_SECTION_NODE)) in xmlXPathNodeCollectAndTest()
10826 if ((cur->type == XML_PI_NODE) && in xmlXPathNodeCollectAndTest()
10827 ((name == NULL) || xmlStrEqual(name, cur->name))) in xmlXPathNodeCollectAndTest()
10834 if (cur->type == XML_ATTRIBUTE_NODE) in xmlXPathNodeCollectAndTest()
10839 } else if ((cur->ns != NULL) && in xmlXPathNodeCollectAndTest()
10840 (xmlStrEqual(URI, cur->ns->href))) in xmlXPathNodeCollectAndTest()
10846 if (cur->type == XML_NAMESPACE_DECL) in xmlXPathNodeCollectAndTest()
10851 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathNodeCollectAndTest()
10856 } else if ((cur->ns != NULL) && in xmlXPathNodeCollectAndTest()
10857 (xmlStrEqual(URI, cur->ns->href))) in xmlXPathNodeCollectAndTest()
10870 if (cur->type != XML_ATTRIBUTE_NODE) in xmlXPathNodeCollectAndTest()
10873 if (cur->type != XML_NAMESPACE_DECL) in xmlXPathNodeCollectAndTest()
10876 if (cur->type != XML_ELEMENT_NODE) in xmlXPathNodeCollectAndTest()
10879 switch (cur->type) { in xmlXPathNodeCollectAndTest()
10881 if (xmlStrEqual(name, cur->name)) { in xmlXPathNodeCollectAndTest()
10883 if (cur->ns == NULL) in xmlXPathNodeCollectAndTest()
10888 if ((cur->ns != NULL) && in xmlXPathNodeCollectAndTest()
10889 (xmlStrEqual(URI, cur->ns->href))) in xmlXPathNodeCollectAndTest()
10899 if (xmlStrEqual(name, attr->name)) { in xmlXPathNodeCollectAndTest()
10901 if ((attr->ns == NULL) || in xmlXPathNodeCollectAndTest()
10902 (attr->ns->prefix == NULL)) in xmlXPathNodeCollectAndTest()
10907 if ((attr->ns != NULL) && in xmlXPathNodeCollectAndTest()
10909 attr->ns->href))) in xmlXPathNodeCollectAndTest()
10918 if (cur->type == XML_NAMESPACE_DECL) { in xmlXPathNodeCollectAndTest()
10921 if ((ns->prefix != NULL) && (name != NULL) in xmlXPathNodeCollectAndTest()
10922 && (xmlStrEqual(ns->prefix, name))) in xmlXPathNodeCollectAndTest()
10933 } while ((cur != NULL) && (ctxt->error == XPATH_EXPRESSION_OK)); in xmlXPathNodeCollectAndTest()
10937 axis_range_end: /* ----------------------------------------------------- */ in xmlXPathNodeCollectAndTest()
10941 * a duplicate-aware merge is still needed. in xmlXPathNodeCollectAndTest()
10959 first_hit: /* ---------------------------------------------------------- */ in xmlXPathNodeCollectAndTest()
10962 * no predicates existed and a node test succeeded. in xmlXPathNodeCollectAndTest()
10974 apply_predicates: /* --------------------------------------------------- */ in xmlXPathNodeCollectAndTest()
10975 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathNodeCollectAndTest()
10979 * Apply predicates. in xmlXPathNodeCollectAndTest()
10981 if ((predOp != NULL) && (seq->nodeNr > 0)) { in xmlXPathNodeCollectAndTest()
10987 * account location-sets. in xmlXPathNodeCollectAndTest()
10988 * (E.g. ctxt->value->type == XPATH_LOCATIONSET) in xmlXPathNodeCollectAndTest()
10991 * does not indicate that a location-set will be processed in xmlXPathNodeCollectAndTest()
10995 * Iterate over all predicates, starting with the outermost in xmlXPathNodeCollectAndTest()
10997 * TODO: Problem: we cannot execute the inner predicates first in xmlXPathNodeCollectAndTest()
11014 xmlXPathCompOpEvalPredicate(ctxt, predOp, seq, 1, seq->nodeNr, in xmlXPathNodeCollectAndTest()
11017 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathNodeCollectAndTest()
11023 if (seq->nodeNr > 0) { in xmlXPathNodeCollectAndTest()
11042 if ((obj->boolval) && (obj->user != NULL)) { in xmlXPathNodeCollectAndTest()
11048 ctxt->value->boolval = 1; in xmlXPathNodeCollectAndTest()
11049 ctxt->value->user = obj->user; in xmlXPathNodeCollectAndTest()
11050 obj->user = NULL; in xmlXPathNodeCollectAndTest()
11051 obj->boolval = 0; in xmlXPathNodeCollectAndTest()
11059 if ((seq != NULL) && (seq->nodeNr == 0)) { in xmlXPathNodeCollectAndTest()
11078 xpctxt->node = oldContextNode; in xmlXPathNodeCollectAndTest()
11083 if (xpctxt->tmpNsList != NULL) { in xmlXPathNodeCollectAndTest()
11084 xmlFree(xpctxt->tmpNsList); in xmlXPathNodeCollectAndTest()
11085 xpctxt->tmpNsList = NULL; in xmlXPathNodeCollectAndTest()
11117 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEvalFirst()
11119 ctxt->context->depth += 1; in xmlXPathCompOpEvalFirst()
11120 comp = ctxt->comp; in xmlXPathCompOpEvalFirst()
11121 switch (op->op) { in xmlXPathCompOpEvalFirst()
11126 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1], in xmlXPathCompOpEvalFirst()
11129 if ((ctxt->value != NULL) in xmlXPathCompOpEvalFirst()
11130 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalFirst()
11131 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalFirst()
11132 && (ctxt->value->nodesetval->nodeNr >= 1)) { in xmlXPathCompOpEvalFirst()
11140 * OPTIMIZE TODO: How do we know if the node-list wasn't in xmlXPathCompOpEvalFirst()
11143 if (ctxt->value->nodesetval->nodeNr > 1) in xmlXPathCompOpEvalFirst()
11144 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalFirst()
11145 *first = ctxt->value->nodesetval->nodeTab[0]; in xmlXPathCompOpEvalFirst()
11148 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch2], in xmlXPathCompOpEvalFirst()
11154 if ((arg1 == NULL) || (arg1->type != XPATH_NODESET) || in xmlXPathCompOpEvalFirst()
11155 (arg2 == NULL) || (arg2->type != XPATH_NODESET)) { in xmlXPathCompOpEvalFirst()
11156 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalFirst()
11157 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalFirst()
11160 if ((ctxt->context->opLimit != 0) && in xmlXPathCompOpEvalFirst()
11161 (((arg1->nodesetval != NULL) && in xmlXPathCompOpEvalFirst()
11163 arg1->nodesetval->nodeNr) < 0)) || in xmlXPathCompOpEvalFirst()
11164 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEvalFirst()
11166 arg2->nodesetval->nodeNr) < 0)))) { in xmlXPathCompOpEvalFirst()
11167 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalFirst()
11168 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalFirst()
11172 if ((arg2->nodesetval != NULL) && in xmlXPathCompOpEvalFirst()
11173 (arg2->nodesetval->nodeNr != 0)) { in xmlXPathCompOpEvalFirst()
11174 arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, in xmlXPathCompOpEvalFirst()
11175 arg2->nodesetval); in xmlXPathCompOpEvalFirst()
11176 if (arg1->nodesetval == NULL) in xmlXPathCompOpEvalFirst()
11180 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalFirst()
11190 if (op->ch1 != -1) in xmlXPathCompOpEvalFirst()
11191 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalFirst()
11193 if (op->ch2 != -1) in xmlXPathCompOpEvalFirst()
11194 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEvalFirst()
11197 ctxt->context->node)); in xmlXPathCompOpEvalFirst()
11200 if (op->ch1 == -1) in xmlXPathCompOpEvalFirst()
11203 total = xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalFirst()
11210 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt, op->value4)); in xmlXPathCompOpEvalFirst()
11213 if (op->ch1 != -1) in xmlXPathCompOpEvalFirst()
11215 xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1], in xmlXPathCompOpEvalFirst()
11218 if ((ctxt->value != NULL) in xmlXPathCompOpEvalFirst()
11219 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalFirst()
11220 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalFirst()
11221 && (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEvalFirst()
11222 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalFirst()
11234 ctxt->context->depth -= 1; in xmlXPathCompOpEvalFirst()
11260 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEvalLast()
11262 ctxt->context->depth += 1; in xmlXPathCompOpEvalLast()
11263 comp = ctxt->comp; in xmlXPathCompOpEvalLast()
11264 switch (op->op) { in xmlXPathCompOpEvalLast()
11269 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], last); in xmlXPathCompOpEvalLast()
11271 if ((ctxt->value != NULL) in xmlXPathCompOpEvalLast()
11272 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalLast()
11273 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalLast()
11274 && (ctxt->value->nodesetval->nodeNr >= 1)) { in xmlXPathCompOpEvalLast()
11278 if (ctxt->value->nodesetval->nodeNr > 1) in xmlXPathCompOpEvalLast()
11279 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalLast()
11281 ctxt->value->nodesetval->nodeTab[ctxt->value-> in xmlXPathCompOpEvalLast()
11282 nodesetval->nodeNr - in xmlXPathCompOpEvalLast()
11286 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch2], last); in xmlXPathCompOpEvalLast()
11288 if ((ctxt->value != NULL) in xmlXPathCompOpEvalLast()
11289 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalLast()
11290 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalLast()
11291 && (ctxt->value->nodesetval->nodeNr >= 1)) { /* TODO: NOP ? */ in xmlXPathCompOpEvalLast()
11296 if ((arg1 == NULL) || (arg1->type != XPATH_NODESET) || in xmlXPathCompOpEvalLast()
11297 (arg2 == NULL) || (arg2->type != XPATH_NODESET)) { in xmlXPathCompOpEvalLast()
11298 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalLast()
11299 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalLast()
11302 if ((ctxt->context->opLimit != 0) && in xmlXPathCompOpEvalLast()
11303 (((arg1->nodesetval != NULL) && in xmlXPathCompOpEvalLast()
11305 arg1->nodesetval->nodeNr) < 0)) || in xmlXPathCompOpEvalLast()
11306 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEvalLast()
11308 arg2->nodesetval->nodeNr) < 0)))) { in xmlXPathCompOpEvalLast()
11309 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEvalLast()
11310 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalLast()
11314 if ((arg2->nodesetval != NULL) && in xmlXPathCompOpEvalLast()
11315 (arg2->nodesetval->nodeNr != 0)) { in xmlXPathCompOpEvalLast()
11316 arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, in xmlXPathCompOpEvalLast()
11317 arg2->nodesetval); in xmlXPathCompOpEvalLast()
11318 if (arg1->nodesetval == NULL) in xmlXPathCompOpEvalLast()
11322 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEvalLast()
11332 if (op->ch1 != -1) in xmlXPathCompOpEvalLast()
11333 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalLast()
11335 if (op->ch2 != -1) in xmlXPathCompOpEvalLast()
11336 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEvalLast()
11339 ctxt->context->node)); in xmlXPathCompOpEvalLast()
11342 if (op->ch1 == -1) in xmlXPathCompOpEvalLast()
11345 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalLast()
11352 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt, op->value4)); in xmlXPathCompOpEvalLast()
11355 if (op->ch1 != -1) in xmlXPathCompOpEvalLast()
11357 xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], in xmlXPathCompOpEvalLast()
11360 if ((ctxt->value != NULL) in xmlXPathCompOpEvalLast()
11361 && (ctxt->value->type == XPATH_NODESET) in xmlXPathCompOpEvalLast()
11362 && (ctxt->value->nodesetval != NULL) in xmlXPathCompOpEvalLast()
11363 && (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEvalLast()
11364 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEvalLast()
11371 ctxt->context->depth -= 1; in xmlXPathCompOpEvalLast()
11386 comp = ctxt->comp; in xmlXPathCompOpEvalFilterFirst()
11390 if ((op->ch1 != -1) && (op->ch2 != -1) && in xmlXPathCompOpEvalFilterFirst()
11391 (comp->steps[op->ch1].op == XPATH_OP_SORT) && in xmlXPathCompOpEvalFilterFirst()
11392 (comp->steps[op->ch2].op == XPATH_OP_SORT)) { in xmlXPathCompOpEvalFilterFirst()
11393 int f = comp->steps[op->ch2].ch1; in xmlXPathCompOpEvalFilterFirst()
11395 if ((f != -1) && in xmlXPathCompOpEvalFilterFirst()
11396 (comp->steps[f].op == XPATH_OP_FUNCTION) && in xmlXPathCompOpEvalFilterFirst()
11397 (comp->steps[f].value5 == NULL) && in xmlXPathCompOpEvalFilterFirst()
11398 (comp->steps[f].value == 0) && in xmlXPathCompOpEvalFilterFirst()
11399 (comp->steps[f].value4 != NULL) && in xmlXPathCompOpEvalFilterFirst()
11401 (comp->steps[f].value4, BAD_CAST "last"))) { in xmlXPathCompOpEvalFilterFirst()
11406 &comp->steps[op->ch1], in xmlXPathCompOpEvalFilterFirst()
11413 if ((ctxt->value != NULL) && in xmlXPathCompOpEvalFilterFirst()
11414 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEvalFilterFirst()
11415 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEvalFilterFirst()
11416 (ctxt->value->nodesetval->nodeTab != NULL) && in xmlXPathCompOpEvalFilterFirst()
11417 (ctxt->value->nodesetval->nodeNr > 1)) { in xmlXPathCompOpEvalFilterFirst()
11418 xmlXPathNodeSetKeepLast(ctxt->value->nodesetval); in xmlXPathCompOpEvalFilterFirst()
11419 *first = *(ctxt->value->nodesetval->nodeTab); in xmlXPathCompOpEvalFilterFirst()
11425 if (op->ch1 != -1) in xmlXPathCompOpEvalFilterFirst()
11426 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEvalFilterFirst()
11428 if (op->ch2 == -1) in xmlXPathCompOpEvalFilterFirst()
11430 if (ctxt->value == NULL) in xmlXPathCompOpEvalFilterFirst()
11440 set = obj->nodesetval; in xmlXPathCompOpEvalFilterFirst()
11442 xmlXPathNodeSetFilter(ctxt, set, op->ch2, 1, 1, 1); in xmlXPathCompOpEvalFilterFirst()
11443 if (set->nodeNr > 0) in xmlXPathCompOpEvalFilterFirst()
11444 *first = set->nodeTab[0]; in xmlXPathCompOpEvalFilterFirst()
11471 if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathCompOpEval()
11473 ctxt->context->depth += 1; in xmlXPathCompOpEval()
11474 comp = ctxt->comp; in xmlXPathCompOpEval()
11475 switch (op->op) { in xmlXPathCompOpEval()
11479 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11482 if ((ctxt->value == NULL) || (ctxt->value->boolval == 0)) in xmlXPathCompOpEval()
11485 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11486 if (ctxt->error) { in xmlXPathCompOpEval()
11491 if (ctxt->value != NULL) in xmlXPathCompOpEval()
11492 ctxt->value->boolval &= arg2->boolval; in xmlXPathCompOpEval()
11493 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
11496 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11499 if ((ctxt->value == NULL) || (ctxt->value->boolval == 1)) in xmlXPathCompOpEval()
11502 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11503 if (ctxt->error) { in xmlXPathCompOpEval()
11508 if (ctxt->value != NULL) in xmlXPathCompOpEval()
11509 ctxt->value->boolval |= arg2->boolval; in xmlXPathCompOpEval()
11510 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
11513 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11515 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11517 if (op->value) in xmlXPathCompOpEval()
11524 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11526 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11528 ret = xmlXPathCompareValues(ctxt, op->value, op->value2); in xmlXPathCompOpEval()
11532 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11534 if (op->ch2 != -1) { in xmlXPathCompOpEval()
11535 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11538 if (op->value == 0) in xmlXPathCompOpEval()
11540 else if (op->value == 1) in xmlXPathCompOpEval()
11542 else if (op->value == 2) in xmlXPathCompOpEval()
11544 else if (op->value == 3) { in xmlXPathCompOpEval()
11550 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11552 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11554 if (op->value == 0) in xmlXPathCompOpEval()
11556 else if (op->value == 1) in xmlXPathCompOpEval()
11558 else if (op->value == 2) in xmlXPathCompOpEval()
11562 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11564 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11569 if ((arg1 == NULL) || (arg1->type != XPATH_NODESET) || in xmlXPathCompOpEval()
11570 (arg2 == NULL) || (arg2->type != XPATH_NODESET)) { in xmlXPathCompOpEval()
11571 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEval()
11572 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
11575 if ((ctxt->context->opLimit != 0) && in xmlXPathCompOpEval()
11576 (((arg1->nodesetval != NULL) && in xmlXPathCompOpEval()
11578 arg1->nodesetval->nodeNr) < 0)) || in xmlXPathCompOpEval()
11579 ((arg2->nodesetval != NULL) && in xmlXPathCompOpEval()
11581 arg2->nodesetval->nodeNr) < 0)))) { in xmlXPathCompOpEval()
11582 xmlXPathReleaseObject(ctxt->context, arg1); in xmlXPathCompOpEval()
11583 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
11587 if (((arg2->nodesetval != NULL) && in xmlXPathCompOpEval()
11588 (arg2->nodesetval->nodeNr != 0))) in xmlXPathCompOpEval()
11590 arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, in xmlXPathCompOpEval()
11591 arg2->nodesetval); in xmlXPathCompOpEval()
11592 if (arg1->nodesetval == NULL) in xmlXPathCompOpEval()
11597 xmlXPathReleaseObject(ctxt->context, arg2); in xmlXPathCompOpEval()
11603 if (op->ch1 != -1) in xmlXPathCompOpEval()
11604 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11606 if (op->ch2 != -1) in xmlXPathCompOpEval()
11607 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11610 ctxt->context->node)); in xmlXPathCompOpEval()
11613 if (op->ch1 == -1) in xmlXPathCompOpEval()
11616 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11623 valuePush(ctxt, xmlXPathCacheObjectCopy(ctxt, op->value4)); in xmlXPathCompOpEval()
11628 if (op->ch1 != -1) in xmlXPathCompOpEval()
11630 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11631 if (op->value5 == NULL) { in xmlXPathCompOpEval()
11632 val = xmlXPathVariableLookup(ctxt->context, op->value4); in xmlXPathCompOpEval()
11639 URI = xmlXPathNsLookup(ctxt->context, op->value5); in xmlXPathCompOpEval()
11644 val = xmlXPathVariableLookupNS(ctxt->context, in xmlXPathCompOpEval()
11645 op->value4, URI); in xmlXPathCompOpEval()
11658 frame = ctxt->valueNr; in xmlXPathCompOpEval()
11659 if (op->ch1 != -1) { in xmlXPathCompOpEval()
11661 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11662 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEval()
11665 if (ctxt->valueNr < frame + op->value) in xmlXPathCompOpEval()
11667 for (i = 0; i < op->value; i++) { in xmlXPathCompOpEval()
11668 if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) in xmlXPathCompOpEval()
11671 if (op->cache != NULL) in xmlXPathCompOpEval()
11672 func = op->cache; in xmlXPathCompOpEval()
11676 if (op->value5 == NULL) in xmlXPathCompOpEval()
11678 xmlXPathFunctionLookup(ctxt->context, in xmlXPathCompOpEval()
11679 op->value4); in xmlXPathCompOpEval()
11681 URI = xmlXPathNsLookup(ctxt->context, op->value5); in xmlXPathCompOpEval()
11684 func = xmlXPathFunctionLookupNS(ctxt->context, in xmlXPathCompOpEval()
11685 op->value4, URI); in xmlXPathCompOpEval()
11689 op->cache = func; in xmlXPathCompOpEval()
11690 op->cacheURI = (void *) URI; in xmlXPathCompOpEval()
11692 oldFunc = ctxt->context->function; in xmlXPathCompOpEval()
11693 oldFuncURI = ctxt->context->functionURI; in xmlXPathCompOpEval()
11694 ctxt->context->function = op->value4; in xmlXPathCompOpEval()
11695 ctxt->context->functionURI = op->cacheURI; in xmlXPathCompOpEval()
11696 func(ctxt, op->value); in xmlXPathCompOpEval()
11697 ctxt->context->function = oldFunc; in xmlXPathCompOpEval()
11698 ctxt->context->functionURI = oldFuncURI; in xmlXPathCompOpEval()
11699 if ((ctxt->error == XPATH_EXPRESSION_OK) && in xmlXPathCompOpEval()
11700 (ctxt->valueNr != frame + 1)) in xmlXPathCompOpEval()
11705 if (op->ch1 != -1) { in xmlXPathCompOpEval()
11706 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11709 if (op->ch2 != -1) { in xmlXPathCompOpEval()
11710 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); in xmlXPathCompOpEval()
11722 if ((op->ch1 != -1) && (op->ch2 != -1) && in xmlXPathCompOpEval()
11730 * to assume anything, so it would be more robust and in xmlXPathCompOpEval()
11733 ((comp->steps[op->ch1].op == XPATH_OP_SORT) || /* 18 */ in xmlXPathCompOpEval()
11734 (comp->steps[op->ch1].op == XPATH_OP_FILTER)) && /* 17 */ in xmlXPathCompOpEval()
11736 (comp->steps[op->ch1].op == XPATH_OP_SORT) && in xmlXPathCompOpEval()
11738 (comp->steps[op->ch2].op == XPATH_OP_VALUE)) { /* 12 */ in xmlXPathCompOpEval()
11741 val = comp->steps[op->ch2].value4; in xmlXPathCompOpEval()
11742 if ((val != NULL) && (val->type == XPATH_NUMBER) && in xmlXPathCompOpEval()
11743 (val->floatval == 1.0)) { in xmlXPathCompOpEval()
11748 &comp->steps[op->ch1], in xmlXPathCompOpEval()
11755 if ((ctxt->value != NULL) && in xmlXPathCompOpEval()
11756 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEval()
11757 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEval()
11758 (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEval()
11759 xmlXPathNodeSetClearFromPos(ctxt->value->nodesetval, in xmlXPathCompOpEval()
11767 if ((op->ch1 != -1) && (op->ch2 != -1) && in xmlXPathCompOpEval()
11768 (comp->steps[op->ch1].op == XPATH_OP_SORT) && in xmlXPathCompOpEval()
11769 (comp->steps[op->ch2].op == XPATH_OP_SORT)) { in xmlXPathCompOpEval()
11770 int f = comp->steps[op->ch2].ch1; in xmlXPathCompOpEval()
11772 if ((f != -1) && in xmlXPathCompOpEval()
11773 (comp->steps[f].op == XPATH_OP_FUNCTION) && in xmlXPathCompOpEval()
11774 (comp->steps[f].value5 == NULL) && in xmlXPathCompOpEval()
11775 (comp->steps[f].value == 0) && in xmlXPathCompOpEval()
11776 (comp->steps[f].value4 != NULL) && in xmlXPathCompOpEval()
11778 (comp->steps[f].value4, BAD_CAST "last"))) { in xmlXPathCompOpEval()
11783 &comp->steps[op->ch1], in xmlXPathCompOpEval()
11790 if ((ctxt->value != NULL) && in xmlXPathCompOpEval()
11791 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEval()
11792 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEval()
11793 (ctxt->value->nodesetval->nodeTab != NULL) && in xmlXPathCompOpEval()
11794 (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEval()
11795 xmlXPathNodeSetKeepLast(ctxt->value->nodesetval); in xmlXPathCompOpEval()
11800 * Process inner predicates first. in xmlXPathCompOpEval()
11803 * PREDICATE <-- we are here "[1]" in xmlXPathCompOpEval()
11804 * PREDICATE <-- process "[parent::book]" first in xmlXPathCompOpEval()
11810 if (op->ch1 != -1) in xmlXPathCompOpEval()
11812 xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11814 if (op->ch2 == -1) in xmlXPathCompOpEval()
11816 if (ctxt->value == NULL) in xmlXPathCompOpEval()
11827 set = obj->nodesetval; in xmlXPathCompOpEval()
11829 xmlXPathNodeSetFilter(ctxt, set, op->ch2, in xmlXPathCompOpEval()
11830 1, set->nodeNr, 1); in xmlXPathCompOpEval()
11835 if (op->ch1 != -1) in xmlXPathCompOpEval()
11836 total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); in xmlXPathCompOpEval()
11838 if ((ctxt->value != NULL) && in xmlXPathCompOpEval()
11839 (ctxt->value->type == XPATH_NODESET) && in xmlXPathCompOpEval()
11840 (ctxt->value->nodesetval != NULL) && in xmlXPathCompOpEval()
11841 (ctxt->value->nodesetval->nodeNr > 1)) in xmlXPathCompOpEval()
11843 xmlXPathNodeSetSort(ctxt->value->nodesetval); in xmlXPathCompOpEval()
11851 ctxt->context->depth -= 1; in xmlXPathCompOpEval()
11861 * Returns 1 if true, 0 if false and -1 on API or internal errors.
11873 /* comp = ctxt->comp; */ in xmlXPathCompOpEvalToBoolean()
11874 switch (op->op) { in xmlXPathCompOpEvalToBoolean()
11878 resObj = (xmlXPathObjectPtr) op->value4; in xmlXPathCompOpEvalToBoolean()
11886 if (op->ch1 != -1) { in xmlXPathCompOpEvalToBoolean()
11887 op = &ctxt->comp->steps[op->ch1]; in xmlXPathCompOpEvalToBoolean()
11892 if (op->ch1 == -1) in xmlXPathCompOpEvalToBoolean()
11895 xmlXPathCompOpEval(ctxt, &ctxt->comp->steps[op->ch1]); in xmlXPathCompOpEvalToBoolean()
11896 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEvalToBoolean()
11897 return(-1); in xmlXPathCompOpEvalToBoolean()
11900 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEvalToBoolean()
11901 return(-1); in xmlXPathCompOpEvalToBoolean()
11905 return(-1); in xmlXPathCompOpEvalToBoolean()
11912 if (ctxt->error != XPATH_EXPRESSION_OK) in xmlXPathCompOpEvalToBoolean()
11913 return(-1); in xmlXPathCompOpEvalToBoolean()
11917 return(-1); in xmlXPathCompOpEvalToBoolean()
11924 if (resObj->type == XPATH_BOOLEAN) { in xmlXPathCompOpEvalToBoolean()
11925 res = resObj->boolval; in xmlXPathCompOpEvalToBoolean()
11928 * For predicates a result of type "number" is handled in xmlXPathCompOpEvalToBoolean()
11939 xmlXPathReleaseObject(ctxt->context, resObj); in xmlXPathCompOpEvalToBoolean()
11963 xmlXPathContextPtr ctxt = pctxt->context; in xmlXPathRunStreamEval()
11966 return(-1); in xmlXPathRunStreamEval()
11968 if (max_depth == -1) in xmlXPathRunStreamEval()
11969 return(-1); in xmlXPathRunStreamEval()
11970 if (max_depth == -2) in xmlXPathRunStreamEval()
11973 if (min_depth == -1) in xmlXPathRunStreamEval()
11974 return(-1); in xmlXPathRunStreamEval()
11977 return(-1); in xmlXPathRunStreamEval()
11984 return(-1); in xmlXPathRunStreamEval()
11987 return(-1); in xmlXPathRunStreamEval()
12000 res = xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, in xmlXPathRunStreamEval()
12001 (xmlNodePtr) ctxt->doc); in xmlXPathRunStreamEval()
12006 res = xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, in xmlXPathRunStreamEval()
12007 ctxt->node); in xmlXPathRunStreamEval()
12018 cur = (xmlNodePtr)ctxt->doc; in xmlXPathRunStreamEval()
12019 } else if (ctxt->node != NULL) { in xmlXPathRunStreamEval()
12020 switch (ctxt->node->type) { in xmlXPathRunStreamEval()
12025 cur = ctxt->node; in xmlXPathRunStreamEval()
12054 return(-1); in xmlXPathRunStreamEval()
12065 if (xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, cur) < 0) in xmlXPathRunStreamEval()
12073 if (ctxt->opLimit != 0) { in xmlXPathRunStreamEval()
12074 if (ctxt->opCount >= ctxt->opLimit) { in xmlXPathRunStreamEval()
12077 return(-1); in xmlXPathRunStreamEval()
12079 ctxt->opCount++; in xmlXPathRunStreamEval()
12082 switch (cur->type) { in xmlXPathRunStreamEval()
12088 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathRunStreamEval()
12089 ret = xmlStreamPush(patstream, cur->name, in xmlXPathRunStreamEval()
12090 (cur->ns ? cur->ns->href : NULL)); in xmlXPathRunStreamEval()
12092 ret = xmlStreamPushNode(patstream, NULL, NULL, cur->type); in xmlXPathRunStreamEval()
12101 if (xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, in xmlXPathRunStreamEval()
12105 if ((cur->children == NULL) || (depth >= max_depth)) { in xmlXPathRunStreamEval()
12107 while (cur->next != NULL) { in xmlXPathRunStreamEval()
12108 cur = cur->next; in xmlXPathRunStreamEval()
12109 if ((cur->type != XML_ENTITY_DECL) && in xmlXPathRunStreamEval()
12110 (cur->type != XML_DTD_NODE)) in xmlXPathRunStreamEval()
12119 if (cur->type == XML_NAMESPACE_DECL) break; in xmlXPathRunStreamEval()
12120 if ((cur->children != NULL) && (depth < max_depth)) { in xmlXPathRunStreamEval()
12124 if (cur->children->type != XML_ENTITY_DECL) { in xmlXPathRunStreamEval()
12125 cur = cur->children; in xmlXPathRunStreamEval()
12130 if (cur->type != XML_DTD_NODE) in xmlXPathRunStreamEval()
12138 while (cur->next != NULL) { in xmlXPathRunStreamEval()
12139 cur = cur->next; in xmlXPathRunStreamEval()
12140 if ((cur->type != XML_ENTITY_DECL) && in xmlXPathRunStreamEval()
12141 (cur->type != XML_DTD_NODE)) in xmlXPathRunStreamEval()
12146 cur = cur->parent; in xmlXPathRunStreamEval()
12147 depth--; in xmlXPathRunStreamEval()
12149 (cur->type == XML_DOCUMENT_NODE)) in xmlXPathRunStreamEval()
12151 if (cur->type == XML_ELEMENT_NODE) { in xmlXPathRunStreamEval()
12154 ((cur->type == XML_TEXT_NODE) || in xmlXPathRunStreamEval()
12155 (cur->type == XML_CDATA_SECTION_NODE) || in xmlXPathRunStreamEval()
12156 (cur->type == XML_COMMENT_NODE) || in xmlXPathRunStreamEval()
12157 (cur->type == XML_PI_NODE))) in xmlXPathRunStreamEval()
12161 if (cur->next != NULL) { in xmlXPathRunStreamEval()
12162 cur = cur->next; in xmlXPathRunStreamEval()
12195 if ((ctxt == NULL) || (ctxt->comp == NULL)) in xmlXPathRunEval()
12196 return(-1); in xmlXPathRunEval()
12198 if (ctxt->valueTab == NULL) { in xmlXPathRunEval()
12200 ctxt->valueTab = (xmlXPathObjectPtr *) in xmlXPathRunEval()
12202 if (ctxt->valueTab == NULL) { in xmlXPathRunEval()
12204 return(-1); in xmlXPathRunEval()
12206 ctxt->valueNr = 0; in xmlXPathRunEval()
12207 ctxt->valueMax = 10; in xmlXPathRunEval()
12208 ctxt->value = NULL; in xmlXPathRunEval()
12211 if (ctxt->comp->stream) { in xmlXPathRunEval()
12218 res = xmlXPathRunStreamEval(ctxt, ctxt->comp->stream, NULL, 1); in xmlXPathRunEval()
12219 if (res != -1) in xmlXPathRunEval()
12227 res = xmlXPathRunStreamEval(ctxt, ctxt->comp->stream, &resObj, 0); in xmlXPathRunEval()
12229 if ((res != -1) && (resObj != NULL)) { in xmlXPathRunEval()
12234 xmlXPathReleaseObject(ctxt->context, resObj); in xmlXPathRunEval()
12238 * if res == -1. Is this intended? in xmlXPathRunEval()
12242 comp = ctxt->comp; in xmlXPathRunEval()
12243 if (comp->last < 0) { in xmlXPathRunEval()
12245 return(-1); in xmlXPathRunEval()
12247 oldDepth = ctxt->context->depth; in xmlXPathRunEval()
12250 &comp->steps[comp->last], 0)); in xmlXPathRunEval()
12252 xmlXPathCompOpEval(ctxt, &comp->steps[comp->last]); in xmlXPathRunEval()
12253 ctxt->context->depth = oldDepth; in xmlXPathRunEval()
12283 switch (res->type) { in xmlXPathEvalPredicate()
12285 return(res->boolval); in xmlXPathEvalPredicate()
12287 return(res->floatval == ctxt->proximityPosition); in xmlXPathEvalPredicate()
12290 if (res->nodesetval == NULL) in xmlXPathEvalPredicate()
12292 return(res->nodesetval->nodeNr != 0); in xmlXPathEvalPredicate()
12294 return((res->stringval != NULL) && in xmlXPathEvalPredicate()
12295 (xmlStrlen(res->stringval) != 0)); in xmlXPathEvalPredicate()
12322 switch (res->type) { in xmlXPathEvaluatePredicateResult()
12324 return(res->boolval); in xmlXPathEvaluatePredicateResult()
12327 return((res->floatval == ctxt->context->proximityPosition) && in xmlXPathEvaluatePredicateResult()
12328 (!xmlXPathIsNaN(res->floatval))); /* MSC pbm Mark Vakoc !*/ in xmlXPathEvaluatePredicateResult()
12330 return(res->floatval == ctxt->context->proximityPosition); in xmlXPathEvaluatePredicateResult()
12334 if (res->nodesetval == NULL) in xmlXPathEvaluatePredicateResult()
12336 return(res->nodesetval->nodeNr != 0); in xmlXPathEvaluatePredicateResult()
12338 return((res->stringval != NULL) && (res->stringval[0] != 0)); in xmlXPathEvaluatePredicateResult()
12384 ((ctxt == NULL) || (ctxt->nsNr == 0) || (tmp[1] == ':'))) in xmlXPathTryStreamCompile()
12388 dict = ctxt->dict; in xmlXPathTryStreamCompile()
12389 if (ctxt->nsNr > 0) { in xmlXPathTryStreamCompile()
12390 namespaces = xmlMalloc(2 * (ctxt->nsNr + 1) * sizeof(xmlChar*)); in xmlXPathTryStreamCompile()
12395 for (i = 0, j = 0; (j < ctxt->nsNr); j++) { in xmlXPathTryStreamCompile()
12396 ns = ctxt->namespaces[j]; in xmlXPathTryStreamCompile()
12397 namespaces[i++] = ns->href; in xmlXPathTryStreamCompile()
12398 namespaces[i++] = ns->prefix; in xmlXPathTryStreamCompile()
12421 comp->stream = stream; in xmlXPathTryStreamCompile()
12422 comp->dict = dict; in xmlXPathTryStreamCompile()
12423 if (comp->dict) in xmlXPathTryStreamCompile()
12424 xmlDictReference(comp->dict); in xmlXPathTryStreamCompile()
12437 xmlXPathCompExprPtr comp = pctxt->comp; in xmlXPathOptimizeExpression()
12441 * Try to rewrite "descendant-or-self::node()/foo" to an optimized in xmlXPathOptimizeExpression()
12445 if ((op->op == XPATH_OP_COLLECT /* 11 */) && in xmlXPathOptimizeExpression()
12446 (op->ch1 != -1) && in xmlXPathOptimizeExpression()
12447 (op->ch2 == -1 /* no predicate */)) in xmlXPathOptimizeExpression()
12449 xmlXPathStepOpPtr prevop = &comp->steps[op->ch1]; in xmlXPathOptimizeExpression()
12451 if ((prevop->op == XPATH_OP_COLLECT /* 11 */) && in xmlXPathOptimizeExpression()
12452 ((xmlXPathAxisVal) prevop->value == in xmlXPathOptimizeExpression()
12454 (prevop->ch2 == -1) && in xmlXPathOptimizeExpression()
12455 ((xmlXPathTestVal) prevop->value2 == NODE_TEST_TYPE) && in xmlXPathOptimizeExpression()
12456 ((xmlXPathTypeVal) prevop->value3 == NODE_TYPE_NODE)) in xmlXPathOptimizeExpression()
12459 * This is a "descendant-or-self::node()" without predicates. in xmlXPathOptimizeExpression()
12463 switch ((xmlXPathAxisVal) op->value) { in xmlXPathOptimizeExpression()
12467 * Convert "descendant-or-self::node()/child::" or in xmlXPathOptimizeExpression()
12468 * "descendant-or-self::node()/descendant::" to in xmlXPathOptimizeExpression()
12471 op->ch1 = prevop->ch1; in xmlXPathOptimizeExpression()
12472 op->value = AXIS_DESCENDANT; in xmlXPathOptimizeExpression()
12477 * Convert "descendant-or-self::node()/self::" or in xmlXPathOptimizeExpression()
12478 * "descendant-or-self::node()/descendant-or-self::" to in xmlXPathOptimizeExpression()
12479 * to "descendant-or-self::" in xmlXPathOptimizeExpression()
12481 op->ch1 = prevop->ch1; in xmlXPathOptimizeExpression()
12482 op->value = AXIS_DESCENDANT_OR_SELF; in xmlXPathOptimizeExpression()
12491 if (op->op == XPATH_OP_VALUE) in xmlXPathOptimizeExpression()
12495 ctxt = pctxt->context; in xmlXPathOptimizeExpression()
12497 if (ctxt->depth >= XPATH_MAX_RECURSION_DEPTH) in xmlXPathOptimizeExpression()
12499 ctxt->depth += 1; in xmlXPathOptimizeExpression()
12501 if (op->ch1 != -1) in xmlXPathOptimizeExpression()
12502 xmlXPathOptimizeExpression(pctxt, &comp->steps[op->ch1]); in xmlXPathOptimizeExpression()
12503 if (op->ch2 != -1) in xmlXPathOptimizeExpression()
12504 xmlXPathOptimizeExpression(pctxt, &comp->steps[op->ch2]); in xmlXPathOptimizeExpression()
12506 ctxt->depth -= 1; in xmlXPathOptimizeExpression()
12537 oldDepth = ctxt->depth; in xmlXPathCtxtCompile()
12540 ctxt->depth = oldDepth; in xmlXPathCtxtCompile()
12542 if( pctxt->error != XPATH_EXPRESSION_OK ) in xmlXPathCtxtCompile()
12548 if (*pctxt->cur != 0) { in xmlXPathCtxtCompile()
12553 * out in other places. It's not critical so we leave it as-is for now in xmlXPathCtxtCompile()
12558 comp = pctxt->comp; in xmlXPathCtxtCompile()
12559 if ((comp->nbStep > 1) && (comp->last >= 0)) { in xmlXPathCtxtCompile()
12561 oldDepth = ctxt->depth; in xmlXPathCtxtCompile()
12562 xmlXPathOptimizeExpression(pctxt, &comp->steps[comp->last]); in xmlXPathCtxtCompile()
12564 ctxt->depth = oldDepth; in xmlXPathCtxtCompile()
12566 pctxt->comp = NULL; in xmlXPathCtxtCompile()
12571 comp->expr = xmlStrdup(str); in xmlXPathCtxtCompile()
12617 return(-1); in xmlXPathCompiledEvalInternal()
12620 xmlResetError(&ctxt->lastError); in xmlXPathCompiledEvalInternal()
12630 return(-1); in xmlXPathCompiledEvalInternal()
12633 if (pctxt->error == XPATH_EXPRESSION_OK) { in xmlXPathCompiledEvalInternal()
12634 if (pctxt->valueNr != ((toBool) ? 0 : 1)) in xmlXPathCompiledEvalInternal()
12645 pctxt->comp = NULL; in xmlXPathCompiledEvalInternal()
12648 reentance--; in xmlXPathCompiledEvalInternal()
12682 * -1 in API and internal errors.
12707 if (ctxt->context->lastError.code != 0) in xmlXPathEvalExpr()
12711 comp = xmlXPathTryStreamCompile(ctxt->context, ctxt->base); in xmlXPathEvalExpr()
12713 (ctxt->context->lastError.code == XML_ERR_NO_MEMORY)) { in xmlXPathEvalExpr()
12718 if (ctxt->comp != NULL) in xmlXPathEvalExpr()
12719 xmlXPathFreeCompExpr(ctxt->comp); in xmlXPathEvalExpr()
12720 ctxt->comp = comp; in xmlXPathEvalExpr()
12724 if (ctxt->context != NULL) in xmlXPathEvalExpr()
12725 oldDepth = ctxt->context->depth; in xmlXPathEvalExpr()
12727 if (ctxt->context != NULL) in xmlXPathEvalExpr()
12728 ctxt->context->depth = oldDepth; in xmlXPathEvalExpr()
12732 if (*ctxt->cur != 0) in xmlXPathEvalExpr()
12735 if ((ctxt->comp->nbStep > 1) && (ctxt->comp->last >= 0)) { in xmlXPathEvalExpr()
12736 if (ctxt->context != NULL) in xmlXPathEvalExpr()
12737 oldDepth = ctxt->context->depth; in xmlXPathEvalExpr()
12739 &ctxt->comp->steps[ctxt->comp->last]); in xmlXPathEvalExpr()
12740 if (ctxt->context != NULL) in xmlXPathEvalExpr()
12741 ctxt->context->depth = oldDepth; in xmlXPathEvalExpr()
12768 xmlResetError(&ctx->lastError); in xmlXPathEval()
12775 if (ctxt->error != XPATH_EXPRESSION_OK) { in xmlXPathEval()
12777 } else if (ctxt->valueNr != 1) { in xmlXPathEval()
12796 * Returns -1 in case of error or 0 if successful
12801 return(-1); in xmlXPathSetContextNode()
12803 if (node->doc == ctx->doc) { in xmlXPathSetContextNode()
12804 ctx->node = node; in xmlXPathSetContextNode()
12807 return(-1); in xmlXPathSetContextNode()
12856 * Implement the escape-uri() XPath function
12857 * string escape-uri(string $str, bool $escape-reserved)
12860 * 2396] to the string supplied as $uri-part, which typically represents all
12864 * represent the character in UTF-8.
12867 * boolean argument $escape-reserved.
12869 * If $escape-reserved is true, all characters are escaped other than lower
12870 * case letters a-z, upper case letters A-Z, digits 0-9, and the characters
12871 * referred to in [RFC 2396] as "marks": specifically, "-" | "_" | "." | "!"
12873 * if it is not followed by two hexadecimal digits (that is, 0-9, a-f, and
12874 * A-F).
12876 * If $escape-reserved is false, the behavior differs in that characters
12883 * the upper-case letters A-F.
12885 * Generally, $escape-reserved should be set to true when escaping a string
12889 * In the case of non-ascii characters, the string is encoded according to
12890 * utf-8 and then converted according to RFC 2396.
12893 …* xf:escape-uri ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"), t…
12895 …* xf:escape-uri ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"), f…
12920 for (cptr = str->stringval; *cptr; cptr++) { in xmlXPathEscapeUriFunction()
12924 *cptr == '-' || *cptr == '_' || *cptr == '.' || in xmlXPathEscapeUriFunction()
12944 escape[1] = 'A' - 10 + (*cptr >> 4); in xmlXPathEscapeUriFunction()
12948 escape[2] = 'A' - 10 + (*cptr & 0xF); in xmlXPathEscapeUriFunction()
12956 xmlXPathReleaseObject(ctxt->context, str); in xmlXPathEscapeUriFunction()
12988 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"local-name", in xmlXPathRegisterAllFunctions()
12994 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"namespace-uri", in xmlXPathRegisterAllFunctions()
12996 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"normalize-space", in xmlXPathRegisterAllFunctions()
13006 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"string-length", in xmlXPathRegisterAllFunctions()
13008 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"starts-with", in xmlXPathRegisterAllFunctions()
13012 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring-before", in xmlXPathRegisterAllFunctions()
13014 xmlXPathRegisterFunc(ctxt, (const xmlChar *)"substring-after", in xmlXPathRegisterAllFunctions()
13023 xmlXPathRegisterFuncNS(ctxt, (const xmlChar *)"escape-uri", in xmlXPathRegisterAllFunctions()
13024 (const xmlChar *)"http://www.w3.org/2002/08/xquery-functions", in xmlXPathRegisterAllFunctions()