提交 df304575 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 fca6f593
...@@ -2049,6 +2049,10 @@ virJSONStringReformat(const char *jsonstr, ...@@ -2049,6 +2049,10 @@ virJSONStringReformat(const char *jsonstr,
} }
static virJSONValuePtr
virJSONValueObjectDeflattenKeys(virJSONValuePtr json);
static int static int
virJSONValueObjectDeflattenWorker(const char *key, virJSONValueObjectDeflattenWorker(const char *key,
virJSONValuePtr value, virJSONValuePtr value,
...@@ -2064,7 +2068,7 @@ virJSONValueObjectDeflattenWorker(const char *key, ...@@ -2064,7 +2068,7 @@ virJSONValueObjectDeflattenWorker(const char *key,
if (!strchr(key, '.')) { if (!strchr(key, '.')) {
if (virJSONValueIsObject(value)) if (virJSONValueIsObject(value))
newval = virJSONValueObjectDeflatten(value); newval = virJSONValueObjectDeflattenKeys(value);
else else
newval = virJSONValueCopy(value); newval = virJSONValueCopy(value);
...@@ -2113,6 +2117,20 @@ virJSONValueObjectDeflattenWorker(const char *key, ...@@ -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: * virJSONValueObjectDeflatten:
* *
...@@ -2128,12 +2146,5 @@ virJSONValueObjectDeflattenWorker(const char *key, ...@@ -2128,12 +2146,5 @@ virJSONValueObjectDeflattenWorker(const char *key,
virJSONValuePtr virJSONValuePtr
virJSONValueObjectDeflatten(virJSONValuePtr json) virJSONValueObjectDeflatten(virJSONValuePtr json)
{ {
g_autoptr(virJSONValue) deflattened = virJSONValueNewObject(); return virJSONValueObjectDeflattenKeys(json);
if (virJSONValueObjectForeachKeyValue(json,
virJSONValueObjectDeflattenWorker,
deflattened) < 0)
return NULL;
return g_steal_pointer(&deflattened);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册