mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-08 16:54:49 +00:00
util: json: Extract deflattening of keys into a separate function
Extract the code so that there's a clean separation once we'll want do do other steps. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
fca6f593c9
commit
df30457587
@ -2049,6 +2049,10 @@ virJSONStringReformat(const char *jsonstr,
|
||||
}
|
||||
|
||||
|
||||
static virJSONValuePtr
|
||||
virJSONValueObjectDeflattenKeys(virJSONValuePtr json);
|
||||
|
||||
|
||||
static int
|
||||
virJSONValueObjectDeflattenWorker(const char *key,
|
||||
virJSONValuePtr value,
|
||||
@ -2064,7 +2068,7 @@ virJSONValueObjectDeflattenWorker(const char *key,
|
||||
if (!strchr(key, '.')) {
|
||||
|
||||
if (virJSONValueIsObject(value))
|
||||
newval = virJSONValueObjectDeflatten(value);
|
||||
newval = virJSONValueObjectDeflattenKeys(value);
|
||||
else
|
||||
newval = virJSONValueCopy(value);
|
||||
|
||||
@ -2113,6 +2117,20 @@ virJSONValueObjectDeflattenWorker(const char *key,
|
||||
}
|
||||
|
||||
|
||||
static virJSONValuePtr
|
||||
virJSONValueObjectDeflattenKeys(virJSONValuePtr json)
|
||||
{
|
||||
g_autoptr(virJSONValue) deflattened = virJSONValueNewObject();
|
||||
|
||||
if (virJSONValueObjectForeachKeyValue(json,
|
||||
virJSONValueObjectDeflattenWorker,
|
||||
deflattened) < 0)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&deflattened);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virJSONValueObjectDeflatten:
|
||||
*
|
||||
@ -2128,12 +2146,5 @@ virJSONValueObjectDeflattenWorker(const char *key,
|
||||
virJSONValuePtr
|
||||
virJSONValueObjectDeflatten(virJSONValuePtr json)
|
||||
{
|
||||
g_autoptr(virJSONValue) deflattened = virJSONValueNewObject();
|
||||
|
||||
if (virJSONValueObjectForeachKeyValue(json,
|
||||
virJSONValueObjectDeflattenWorker,
|
||||
deflattened) < 0)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&deflattened);
|
||||
return virJSONValueObjectDeflattenKeys(json);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user