提交 5133b503 编写于 作者: P Peter Krempa

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.
上级 5429a3b6
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册