mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
util: json: Add helpers for manipulating json arrays
Add a checker to determine whether a JSON object is an array and a helper to steal objects from a JSON array.
This commit is contained in:
parent
5429a3b648
commit
5133b50372
@ -564,6 +564,13 @@ virJSONValueObjectGetValue(virJSONValuePtr object,
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
virJSONValueIsArray(virJSONValuePtr array)
|
||||
{
|
||||
return array->type == VIR_JSON_TYPE_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virJSONValueArraySize(virJSONValuePtr array)
|
||||
{
|
||||
@ -588,6 +595,28 @@ virJSONValueArrayGet(virJSONValuePtr array,
|
||||
}
|
||||
|
||||
|
||||
virJSONValuePtr
|
||||
virJSONValueArraySteal(virJSONValuePtr array,
|
||||
unsigned int element)
|
||||
{
|
||||
virJSONValuePtr ret = NULL;
|
||||
|
||||
if (array->type != VIR_JSON_TYPE_ARRAY)
|
||||
return NULL;
|
||||
|
||||
if (element >= array->data.array.nvalues)
|
||||
return NULL;
|
||||
|
||||
ret = array->data.array.values[element];
|
||||
|
||||
VIR_DELETE_ELEMENT(array->data.array.values,
|
||||
element,
|
||||
array->data.array.nvalues);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
virJSONValueGetString(virJSONValuePtr string)
|
||||
{
|
||||
|
@ -97,8 +97,10 @@ int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value);
|
||||
int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key);
|
||||
virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
|
||||
|
||||
bool virJSONValueIsArray(virJSONValuePtr array);
|
||||
int virJSONValueArraySize(virJSONValuePtr object);
|
||||
virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element);
|
||||
virJSONValuePtr virJSONValueArraySteal(virJSONValuePtr object, unsigned int element);
|
||||
|
||||
int virJSONValueObjectKeysNumber(virJSONValuePtr object);
|
||||
const char *virJSONValueObjectGetKey(virJSONValuePtr object, unsigned int n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user