* xmlXPathSubstringBeforeFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the substring-before() XPath function * string substring-before(string, string) * The substring-before function returns the substring of the first * argument string that precedes the first occurrence of the second * argument string in the first argument string, or the e
| 8136 | * string. For example, substring-before("1999/04/01","/") returns 1999. |
| 8137 | */ |
| 8138 | void |
| 8139 | xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
| 8140 | xmlXPathObjectPtr str = NULL; |
| 8141 | xmlXPathObjectPtr find = NULL; |
| 8142 | const xmlChar *point; |
| 8143 | xmlChar *result; |
| 8144 | |
| 8145 | CHECK_ARITY(2); |
| 8146 | CAST_TO_STRING; |
| 8147 | find = valuePop(ctxt); |
| 8148 | CAST_TO_STRING; |
| 8149 | str = valuePop(ctxt); |
| 8150 | if (ctxt->error != 0) |
| 8151 | goto error; |
| 8152 | |
| 8153 | point = xmlStrstr(str->stringval, find->stringval); |
| 8154 | if (point == NULL) { |
| 8155 | result = xmlStrdup(BAD_CAST ""); |
| 8156 | } else { |
| 8157 | result = xmlStrndup(str->stringval, point - str->stringval); |
| 8158 | } |
| 8159 | if (result == NULL) { |
| 8160 | xmlXPathPErrMemory(ctxt); |
| 8161 | goto error; |
| 8162 | } |
| 8163 | valuePush(ctxt, xmlXPathCacheWrapString(ctxt, result)); |
| 8164 | |
| 8165 | error: |
| 8166 | xmlXPathReleaseObject(ctxt->context, str); |
| 8167 | xmlXPathReleaseObject(ctxt->context, find); |
| 8168 | } |
| 8169 | |
| 8170 | /** |
| 8171 | * xmlXPathSubstringAfterFunction: |
nothing calls this directly
no test coverage detected