mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
util: xml: Introduce virXPathU(Int|LongLong)Base
In an effort to remove the 'Long' variants of XPath number fetching functions we need a way to replace the hex number parsing capability. The new helpers are created from the originals by adding a 'base' argument and keeping the original function as a wrapper to pass 10. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
90cb594cf6
commit
7160805e76
@ -3699,9 +3699,11 @@ virXPathNode;
|
||||
virXPathNodeSet;
|
||||
virXPathString;
|
||||
virXPathUInt;
|
||||
virXPathUIntBase;
|
||||
virXPathULong;
|
||||
virXPathULongHex;
|
||||
virXPathULongLong;
|
||||
virXPathULongLongBase;
|
||||
|
||||
|
||||
# Let emacs know we want case-insensitive sorting
|
||||
|
@ -228,9 +228,10 @@ virXPathULongBase(const char *xpath,
|
||||
|
||||
|
||||
/**
|
||||
* virXPathUInt:
|
||||
* virXPathUIntBase:
|
||||
* @xpath: the XPath string to evaluate
|
||||
* @ctxt: an XPath context
|
||||
* @base: base of the number to fetch @value as
|
||||
* @value: the returned unsigned int value
|
||||
*
|
||||
* Convenience function to evaluate an XPath number. The @xpath expression
|
||||
@ -242,8 +243,9 @@ virXPathULongBase(const char *xpath,
|
||||
* value doesn't have an unsigned int format.
|
||||
*/
|
||||
int
|
||||
virXPathUInt(const char *xpath,
|
||||
virXPathUIntBase(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int base,
|
||||
unsigned int *value)
|
||||
{
|
||||
g_autoptr(xmlXPathObject) obj = NULL;
|
||||
@ -251,13 +253,22 @@ virXPathUInt(const char *xpath,
|
||||
if (!(obj = virXPathEvalString(xpath, ctxt)))
|
||||
return -1;
|
||||
|
||||
if (virStrToLong_ui((char *) obj->stringval, NULL, 10, value) < 0)
|
||||
if (virStrToLong_ui((char *) obj->stringval, NULL, base, value) < 0)
|
||||
return -2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virXPathUInt(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int *value)
|
||||
{
|
||||
return virXPathUIntBase(xpath, ctxt, 10, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXPathULong:
|
||||
* @xpath: the XPath string to evaluate
|
||||
@ -302,9 +313,10 @@ virXPathULongHex(const char *xpath,
|
||||
|
||||
|
||||
/**
|
||||
* virXPathULongLong:
|
||||
* virXPathULongLongBase:
|
||||
* @xpath: the XPath string to evaluate
|
||||
* @ctxt: an XPath context
|
||||
* @base: base of the number to fetch @value as
|
||||
* @value: the returned unsigned long long value
|
||||
*
|
||||
* Convenience function to evaluate an XPath number. The @xpath expression
|
||||
@ -316,8 +328,9 @@ virXPathULongHex(const char *xpath,
|
||||
* value doesn't have a unsigned long long format.
|
||||
*/
|
||||
int
|
||||
virXPathULongLong(const char *xpath,
|
||||
virXPathULongLongBase(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int base,
|
||||
unsigned long long *value)
|
||||
{
|
||||
g_autoptr(xmlXPathObject) obj = NULL;
|
||||
@ -325,13 +338,22 @@ virXPathULongLong(const char *xpath,
|
||||
if (!(obj = virXPathEvalString(xpath, ctxt)))
|
||||
return -1;
|
||||
|
||||
if (virStrToLong_ullp((char *) obj->stringval, NULL, 10, value) < 0)
|
||||
if (virStrToLong_ullp((char *) obj->stringval, NULL, base, value) < 0)
|
||||
return -2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virXPathULongLong(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long long *value)
|
||||
{
|
||||
return virXPathULongLongBase(xpath, ctxt, 10, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXPathLongLong:
|
||||
* @xpath: the XPath string to evaluate
|
||||
|
@ -51,6 +51,11 @@ virXPathInt(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
int *value);
|
||||
int
|
||||
virXPathUIntBase(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int base,
|
||||
unsigned int *value);
|
||||
int
|
||||
virXPathUInt(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int *value);
|
||||
@ -63,6 +68,11 @@ virXPathULong(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long *value);
|
||||
int
|
||||
virXPathULongLongBase(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int base,
|
||||
unsigned long long *value);
|
||||
int
|
||||
virXPathULongLong(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long long *value);
|
||||
|
Loading…
Reference in New Issue
Block a user