* xmlXPathStartsWithFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the starts-with() XPath function * boolean starts-with(string, string) * The starts-with function returns true if the first argument string * starts with the second argument string, and otherwise returns false. */
| 7994 | * starts with the second argument string, and otherwise returns false. |
| 7995 | */ |
| 7996 | void |
| 7997 | xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
| 7998 | xmlXPathObjectPtr hay, needle; |
| 7999 | int n; |
| 8000 | |
| 8001 | CHECK_ARITY(2); |
| 8002 | CAST_TO_STRING; |
| 8003 | CHECK_TYPE(XPATH_STRING); |
| 8004 | needle = valuePop(ctxt); |
| 8005 | CAST_TO_STRING; |
| 8006 | hay = valuePop(ctxt); |
| 8007 | |
| 8008 | if ((hay == NULL) || (hay->type != XPATH_STRING)) { |
| 8009 | xmlXPathReleaseObject(ctxt->context, hay); |
| 8010 | xmlXPathReleaseObject(ctxt->context, needle); |
| 8011 | XP_ERROR(XPATH_INVALID_TYPE); |
| 8012 | } |
| 8013 | n = xmlStrlen(needle->stringval); |
| 8014 | if (xmlStrncmp(hay->stringval, needle->stringval, n)) |
| 8015 | valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt, 0)); |
| 8016 | else |
| 8017 | valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt, 1)); |
| 8018 | xmlXPathReleaseObject(ctxt->context, hay); |
| 8019 | xmlXPathReleaseObject(ctxt->context, needle); |
| 8020 | } |
| 8021 | |
| 8022 | /** |
| 8023 | * xmlXPathSubstringFunction: |
nothing calls this directly
no test coverage detected