提交 3b60a0c0 编写于 作者: P Peter Krempa

util: json: Introduce virJSONValueArrayConcat

Add a helper that concatenates the second array into the first.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 5ddfac11
......@@ -2285,6 +2285,7 @@ virISCSIScanTargets;
virJSONStringReformat;
virJSONValueArrayAppend;
virJSONValueArrayAppendString;
virJSONValueArrayConcat;
virJSONValueArrayForeachSteal;
virJSONValueArrayGet;
virJSONValueArraySize;
......
......@@ -811,6 +811,37 @@ virJSONValueArrayAppendString(virJSONValuePtr object,
}
/**
* virJSONValueArrayConcat:
* @a: JSON value array (destination)
* @c: JSON value array (source)
*
* Merges the members of @c array into @a. The values are stolen from @c.
*/
int
virJSONValueArrayConcat(virJSONValuePtr a,
virJSONValuePtr c)
{
size_t i;
if (a->type != VIR_JSON_TYPE_ARRAY ||
c->type != VIR_JSON_TYPE_ARRAY) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("expecting JSON array"));
return -1;
}
a->data.array.values = g_renew(virJSONValuePtr, a->data.array.values,
a->data.array.nvalues + c->data.array.nvalues);
for (i = 0; i < c->data.array.nvalues; i++)
a->data.array.values[a->data.array.nvalues++] = g_steal_pointer(&c->data.array.values[i]);
c->data.array.nvalues = 0;
return 0;
}
int
virJSONValueObjectHasKey(virJSONValuePtr object,
const char *key)
......
......@@ -71,6 +71,8 @@ virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap);
int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr value);
int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value);
int virJSONValueArrayConcat(virJSONValuePtr a,
virJSONValuePtr c);
int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key);
virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册