* xmlXPathEqualNodeSetFloat: * @arg: the nodeset object argument * @f: the float to compare to * @neq: flag to show whether to compare '=' (0) or '!=' (1) * * Implement the equal operation on XPath objects content: @arg1 == @arg2 * If one object to be compared is a node-set and the other is a number, * then the comparison will be true if and only if there is a node in * the node-set suc
| 5764 | * Returns 0 or 1 depending on the results of the test. |
| 5765 | */ |
| 5766 | static int |
| 5767 | xmlXPathEqualNodeSetFloat(xmlXPathParserContextPtr ctxt, |
| 5768 | xmlXPathObjectPtr arg, double f, int neq) { |
| 5769 | int i, ret=0; |
| 5770 | xmlNodeSetPtr ns; |
| 5771 | xmlChar *str2; |
| 5772 | xmlXPathObjectPtr val; |
| 5773 | double v; |
| 5774 | |
| 5775 | if ((arg == NULL) || |
| 5776 | ((arg->type != XPATH_NODESET) && (arg->type != XPATH_XSLT_TREE))) |
| 5777 | return(0); |
| 5778 | |
| 5779 | ns = arg->nodesetval; |
| 5780 | if (ns != NULL) { |
| 5781 | for (i=0;i<ns->nodeNr;i++) { |
| 5782 | str2 = xmlXPathCastNodeToString(ns->nodeTab[i]); |
| 5783 | if (str2 != NULL) { |
| 5784 | valuePush(ctxt, xmlXPathCacheNewString(ctxt, str2)); |
| 5785 | xmlFree(str2); |
| 5786 | xmlXPathNumberFunction(ctxt, 1); |
| 5787 | CHECK_ERROR0; |
| 5788 | val = valuePop(ctxt); |
| 5789 | v = val->floatval; |
| 5790 | xmlXPathReleaseObject(ctxt->context, val); |
| 5791 | if (!xmlXPathIsNaN(v)) { |
| 5792 | if ((!neq) && (v==f)) { |
| 5793 | ret = 1; |
| 5794 | break; |
| 5795 | } else if ((neq) && (v!=f)) { |
| 5796 | ret = 1; |
| 5797 | break; |
| 5798 | } |
| 5799 | } else { /* NaN is unequal to any value */ |
| 5800 | if (neq) |
| 5801 | ret = 1; |
| 5802 | } |
| 5803 | } else { |
| 5804 | xmlXPathPErrMemory(ctxt); |
| 5805 | } |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | return(ret); |
| 5810 | } |
| 5811 | |
| 5812 | |
| 5813 | /** |
no test coverage detected