* xmlXPathCompareNodeSets: * @inf: less than (1) or greater than (0) * @strict: is the comparison strict * @arg1: the first node set object * @arg2: the second node set object * * Implement the compare operation on nodesets: * * If both objects to be compared are node-sets, then the comparison * will be true if and only if there is a node in the first node-set * and a node in the sec
| 5568 | * and then the comparison must be done when possible |
| 5569 | */ |
| 5570 | static int |
| 5571 | xmlXPathCompareNodeSets(xmlXPathParserContextPtr ctxt, int inf, int strict, |
| 5572 | xmlXPathObjectPtr arg1, xmlXPathObjectPtr arg2) { |
| 5573 | int i, j, init = 0; |
| 5574 | double val1; |
| 5575 | double *values2; |
| 5576 | int ret = 0; |
| 5577 | xmlNodeSetPtr ns1; |
| 5578 | xmlNodeSetPtr ns2; |
| 5579 | |
| 5580 | if ((arg1 == NULL) || |
| 5581 | ((arg1->type != XPATH_NODESET) && (arg1->type != XPATH_XSLT_TREE))) { |
| 5582 | xmlXPathFreeObject(arg2); |
| 5583 | return(0); |
| 5584 | } |
| 5585 | if ((arg2 == NULL) || |
| 5586 | ((arg2->type != XPATH_NODESET) && (arg2->type != XPATH_XSLT_TREE))) { |
| 5587 | xmlXPathFreeObject(arg1); |
| 5588 | xmlXPathFreeObject(arg2); |
| 5589 | return(0); |
| 5590 | } |
| 5591 | |
| 5592 | ns1 = arg1->nodesetval; |
| 5593 | ns2 = arg2->nodesetval; |
| 5594 | |
| 5595 | if ((ns1 == NULL) || (ns1->nodeNr <= 0)) { |
| 5596 | xmlXPathFreeObject(arg1); |
| 5597 | xmlXPathFreeObject(arg2); |
| 5598 | return(0); |
| 5599 | } |
| 5600 | if ((ns2 == NULL) || (ns2->nodeNr <= 0)) { |
| 5601 | xmlXPathFreeObject(arg1); |
| 5602 | xmlXPathFreeObject(arg2); |
| 5603 | return(0); |
| 5604 | } |
| 5605 | |
| 5606 | values2 = (double *) xmlMalloc(ns2->nodeNr * sizeof(double)); |
| 5607 | if (values2 == NULL) { |
| 5608 | xmlXPathPErrMemory(ctxt); |
| 5609 | xmlXPathFreeObject(arg1); |
| 5610 | xmlXPathFreeObject(arg2); |
| 5611 | return(0); |
| 5612 | } |
| 5613 | for (i = 0;i < ns1->nodeNr;i++) { |
| 5614 | val1 = xmlXPathNodeToNumberInternal(ctxt, ns1->nodeTab[i]); |
| 5615 | if (xmlXPathIsNaN(val1)) |
| 5616 | continue; |
| 5617 | for (j = 0;j < ns2->nodeNr;j++) { |
| 5618 | if (init == 0) { |
| 5619 | values2[j] = xmlXPathNodeToNumberInternal(ctxt, |
| 5620 | ns2->nodeTab[j]); |
| 5621 | } |
| 5622 | if (xmlXPathIsNaN(values2[j])) |
| 5623 | continue; |
| 5624 | if (inf && strict) |
| 5625 | ret = (val1 < values2[j]); |
| 5626 | else if (inf && !strict) |
| 5627 | ret = (val1 <= values2[j]); |
no test coverage detected