* xmlXPathNumberFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the number() XPath function * number number(object?) */
| 8524 | * number number(object?) |
| 8525 | */ |
| 8526 | void |
| 8527 | xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
| 8528 | xmlXPathObjectPtr cur; |
| 8529 | double res; |
| 8530 | |
| 8531 | if (ctxt == NULL) return; |
| 8532 | if (nargs == 0) { |
| 8533 | if (ctxt->context->node == NULL) { |
| 8534 | valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, 0.0)); |
| 8535 | } else { |
| 8536 | xmlChar* content = xmlNodeGetContent(ctxt->context->node); |
| 8537 | if (content == NULL) |
| 8538 | xmlXPathPErrMemory(ctxt); |
| 8539 | |
| 8540 | res = xmlXPathStringEvalNumber(content); |
| 8541 | valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, res)); |
| 8542 | xmlFree(content); |
| 8543 | } |
| 8544 | return; |
| 8545 | } |
| 8546 | |
| 8547 | CHECK_ARITY(1); |
| 8548 | cur = valuePop(ctxt); |
| 8549 | if (cur->type != XPATH_NUMBER) { |
| 8550 | double floatval; |
| 8551 | |
| 8552 | floatval = xmlXPathCastToNumberInternal(ctxt, cur); |
| 8553 | xmlXPathReleaseObject(ctxt->context, cur); |
| 8554 | cur = xmlXPathCacheNewFloat(ctxt, floatval); |
| 8555 | } |
| 8556 | valuePush(ctxt, cur); |
| 8557 | } |
| 8558 | |
| 8559 | /** |
| 8560 | * xmlXPathSumFunction: |
no test coverage detected