MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathSubstringBeforeFunction

Function xmlXPathSubstringBeforeFunction

ThirdParty/libxml2/vtklibxml2/xpath.c:8138–8168  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

8136 * string. For example, substring-before("1999/04/01","/") returns 1999.
8137 */
8138void
8139xmlXPathSubstringBeforeFunction(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
8165error:
8166 xmlXPathReleaseObject(ctxt->context, str);
8167 xmlXPathReleaseObject(ctxt->context, find);
8168}
8169
8170/**
8171 * xmlXPathSubstringAfterFunction:

Callers

nothing calls this directly

Calls 8

valuePopFunction · 0.85
xmlStrstrFunction · 0.85
xmlStrdupFunction · 0.85
xmlStrndupFunction · 0.85
xmlXPathPErrMemoryFunction · 0.85
valuePushFunction · 0.85
xmlXPathCacheWrapStringFunction · 0.85
xmlXPathReleaseObjectFunction · 0.85

Tested by

no test coverage detected