📄 xpath.c
字号:
xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);#endif return(ret); } } return(xmlXPathWrapNodeSet(val)); }/** * xmlXPathCacheWrapString: * @ctxt: the XPath context * @val: the xmlChar * value * * This is the cached version of xmlXPathWrapString(). * Wraps the @val string into an XPath object. * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheWrapString(xmlXPathContextPtr ctxt, xmlChar *val){ if ((ctxt != NULL) && (ctxt->cache != NULL)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->stringObjs != NULL) && (cache->stringObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->stringObjs->items[--cache->stringObjs->number]; ret->type = XPATH_STRING; ret->stringval = val;#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);#endif return(ret); } else if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; /* * Fallback to misc-cache. */ ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_STRING; ret->stringval = val;#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);#endif return(ret); } } return(xmlXPathWrapString(val));}/** * xmlXPathCacheNewNodeSet: * @ctxt: the XPath context * @val: the NodePtr value * * This is the cached version of xmlXPathNewNodeSet(). * Acquire an xmlXPathObjectPtr of type NodeSet and initialize * it with the single Node @val * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val){ if ((ctxt != NULL) && (ctxt->cache)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->nodesetObjs != NULL) && (cache->nodesetObjs->number != 0)) { xmlXPathObjectPtr ret; /* * Use the nodset-cache. */ ret = (xmlXPathObjectPtr) cache->nodesetObjs->items[--cache->nodesetObjs->number]; ret->type = XPATH_NODESET; ret->boolval = 0; if (val) { if ((ret->nodesetval->nodeMax == 0) || (val->type == XML_NAMESPACE_DECL)) { xmlXPathNodeSetAddUnique(ret->nodesetval, val); } else { ret->nodesetval->nodeTab[0] = val; ret->nodesetval->nodeNr = 1; } }#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);#endif return(ret); } else if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; /* * Fallback to misc-cache. */ ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_NODESET; ret->boolval = 0; ret->nodesetval = xmlXPathNodeSetCreate(val);#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);#endif return(ret); } } return(xmlXPathNewNodeSet(val));}/** * xmlXPathCacheNewCString: * @ctxt: the XPath context * @val: the char * value * * This is the cached version of xmlXPathNewCString(). * Acquire an xmlXPathObjectPtr of type string and of value @val * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheNewCString(xmlXPathContextPtr ctxt, const char *val){ if ((ctxt != NULL) && (ctxt->cache)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->stringObjs != NULL) && (cache->stringObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->stringObjs->items[--cache->stringObjs->number]; ret->type = XPATH_STRING; ret->stringval = xmlStrdup(BAD_CAST val);#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);#endif return(ret); } else if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_STRING; ret->stringval = xmlStrdup(BAD_CAST val);#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);#endif return(ret); } } return(xmlXPathNewCString(val));}/** * xmlXPathCacheNewString: * @ctxt: the XPath context * @val: the xmlChar * value * * This is the cached version of xmlXPathNewString(). * Acquire an xmlXPathObjectPtr of type string and of value @val * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheNewString(xmlXPathContextPtr ctxt, const xmlChar *val){ if ((ctxt != NULL) && (ctxt->cache)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->stringObjs != NULL) && (cache->stringObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->stringObjs->items[--cache->stringObjs->number]; ret->type = XPATH_STRING; if (val != NULL) ret->stringval = xmlStrdup(val); else ret->stringval = xmlStrdup((const xmlChar *)"");#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);#endif return(ret); } else if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_STRING; if (val != NULL) ret->stringval = xmlStrdup(val); else ret->stringval = xmlStrdup((const xmlChar *)"");#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_STRING);#endif return(ret); } } return(xmlXPathNewString(val));}/** * xmlXPathCacheNewBoolean: * @ctxt: the XPath context * @val: the boolean value * * This is the cached version of xmlXPathNewBoolean(). * Acquires an xmlXPathObjectPtr of type boolean and of value @val * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheNewBoolean(xmlXPathContextPtr ctxt, int val){ if ((ctxt != NULL) && (ctxt->cache)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->booleanObjs != NULL) && (cache->booleanObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->booleanObjs->items[--cache->booleanObjs->number]; ret->type = XPATH_BOOLEAN; ret->boolval = (val != 0);#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_BOOLEAN);#endif return(ret); } else if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_BOOLEAN; ret->boolval = (val != 0);#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_BOOLEAN);#endif return(ret); } } return(xmlXPathNewBoolean(val));}/** * xmlXPathCacheNewFloat: * @ctxt: the XPath context * @val: the double value * * This is the cached version of xmlXPathNewFloat(). * Acquires an xmlXPathObjectPtr of type double and of value @val * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheNewFloat(xmlXPathContextPtr ctxt, double val){ if ((ctxt != NULL) && (ctxt->cache)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->numberObjs != NULL) && (cache->numberObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->numberObjs->items[--cache->numberObjs->number]; ret->type = XPATH_NUMBER; ret->floatval = val;#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_NUMBER);#endif return(ret); } else if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_NUMBER; ret->floatval = val;#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjUsageRequested(ctxt, XPATH_NUMBER);#endif return(ret); } } return(xmlXPathNewFloat(val));}/** * xmlXPathCacheConvertString: * @ctxt: the XPath context * @val: an XPath object * * This is the cached version of xmlXPathConvertString(). * Converts an existing object to its string() equivalent * * Returns a created or reused object, the old one is freed (cached) * (or the operation is done directly on @val) */static xmlXPathObjectPtrxmlXPathCacheConvertString(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val) { xmlChar *res = NULL; if (val == NULL) return(xmlXPathCacheNewCString(ctxt, "")); switch (val->type) { case XPATH_UNDEFINED:#ifdef DEBUG_EXPR xmlGenericError(xmlGenericErrorContext, "STRING: undefined\n");#endif break; case XPATH_NODESET: case XPATH_XSLT_TREE: res = xmlXPathCastNodeSetToString(val->nodesetval); break; case XPATH_STRING: return(val); case XPATH_BOOLEAN: res = xmlXPathCastBooleanToString(val->boolval); break; case XPATH_NUMBER: res = xmlXPathCastNumberToString(val->floatval); break; case XPATH_USERS: case XPATH_POINT: case XPATH_RANGE: case XPATH_LOCATIONSET: TODO; break; } xmlXPathReleaseObject(ctxt, val); if (res == NULL) return(xmlXPathCacheNewCString(ctxt, "")); return(xmlXPathCacheWrapString(ctxt, res));}/** * xmlXPathCacheObjectCopy: * @ctxt: the XPath context * @val: the original object * * This is the cached version of xmlXPathObjectCopy(). * Acquire a copy of a given object * * Returns a created or reused created object. */static xmlXPathObjectPtrxmlXPathCacheObjectCopy(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val){ if (val == NULL) return(NULL); if (XP_HAS_CACHE(ctxt)) { switch (val->type) { case XPATH_NODESET: return(xmlXPathCacheWrapNodeSet(ctxt, xmlXPathNodeSetMerge(NULL, val->nodesetval))); case XPATH_STRING: return(xmlXPathCacheNewString(ctxt, val->stringval)); case XPATH_BOOLEAN: return(xmlXPathCacheNewBoolean(ctxt, val->boolval)); case XPATH_NUMBER: return(xmlXPathCacheNewFloat(ctxt, val->floatval)); default: break; } } return(xmlXPathObjectCopy(val));}/** * xmlXPathCacheConvertBoolean: * @ctxt: the XPath context * @val: an XPath object * * This is the cached version of xmlXPathConvertBoolean(). * Converts an existing object to its boolean() equivalent * * Returns a created or reused object, the old one is freed (or the operation * is done directly on @val) */static xmlXPathObjectPtrxmlXPathCacheConvertBoolean(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val) { xmlXPathObjectPtr ret; if (val == NULL) return(xmlXPathCacheNewBoolean(ctxt, 0)); if (val->type == XPATH_BOOLEAN) return(val); ret = xmlXPathCacheNewBoolean(ctxt, xmlXPathCastToBoolean(val)); xmlXPathReleaseObject(ctxt, val); return(ret);}/** * xmlXPathCacheConvertNumber: * @ctxt: the XPath context * @val: an XPath object * * This is the cached version of xmlXPathConvertNumber(). * Converts an existing object to its number() equivalent * * Returns a created or reused object, the old one is freed (or the operation * is done directly on @val) */static xmlXPathObjectPtrxmlXPathCacheConvertNumber(xmlXPathContextPtr ctxt, xmlXPathObjectPtr val) { xmlXPathObjectPtr ret; if (val == NULL) return(xmlXPathCacheNewFloat(ctxt, 0.0)); if (val->type == XPATH_NUMBER) return(val); ret = xmlXPathCacheNewFloat(ctxt, xmlXPathCastToNumber(val)); xmlXPathReleaseObject(ctxt, val); return(ret);}/************************************************************************ * * * Parser stacks related functions and macros * * * ************************************************************************//** * valuePop: * @ctxt: an XPath evaluation context * * Pops the top XPath object from the value stack * * Returns the XPath object just removed */xmlXPathObjectPtrvaluePop(xmlXPathParserContextPtr ctxt){ xmlXPathObjectPtr ret; if ((ctxt == NULL) || (ctxt->valueNr <= 0)) return (NULL); ctxt->valueNr--; if (ctxt->valueNr > 0) ctxt->value = ctxt->valueTab[ctxt->valueNr - 1]; else ctxt->value = NU
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -