* xmlXPathStringLengthFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the string-length() XPath function * number string-length(string?) * The string-length returns the number of characters in the string * (see [3.6 Strings]). If the argument is omitted, it defaults to * the context node converted to a string, in other words the value * of
| 7874 | * of the context node. |
| 7875 | */ |
| 7876 | void |
| 7877 | xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
| 7878 | xmlXPathObjectPtr cur; |
| 7879 | |
| 7880 | if (nargs == 0) { |
| 7881 | if ((ctxt == NULL) || (ctxt->context == NULL)) |
| 7882 | return; |
| 7883 | if (ctxt->context->node == NULL) { |
| 7884 | valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, 0)); |
| 7885 | } else { |
| 7886 | xmlChar *content; |
| 7887 | |
| 7888 | content = xmlXPathCastNodeToString(ctxt->context->node); |
| 7889 | if (content == NULL) |
| 7890 | xmlXPathPErrMemory(ctxt); |
| 7891 | valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, |
| 7892 | xmlUTF8Strlen(content))); |
| 7893 | xmlFree(content); |
| 7894 | } |
| 7895 | return; |
| 7896 | } |
| 7897 | CHECK_ARITY(1); |
| 7898 | CAST_TO_STRING; |
| 7899 | CHECK_TYPE(XPATH_STRING); |
| 7900 | cur = valuePop(ctxt); |
| 7901 | valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, |
| 7902 | xmlUTF8Strlen(cur->stringval))); |
| 7903 | xmlXPathReleaseObject(ctxt->context, cur); |
| 7904 | } |
| 7905 | |
| 7906 | /** |
| 7907 | * xmlXPathConcatFunction: |
nothing calls this directly
no test coverage detected