mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: json: Introduce virJSONValueArrayConcat
Add a helper that concatenates the second array into the first. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
5ddfac1169
commit
3b60a0c027
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user