480
static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
483
const QDictEntry *entry, *next;
487
entry = qdict_first(qdict);
489
while (entry != NULL) {
491
next = qdict_next(qdict, entry);
492
value = qdict_entry_value(entry);
497
qobject_incref(value);
498
new_key = g_strdup_printf("%s.%s", prefix, entry->key);
499
qdict_put_obj(target, new_key, value);
503
if (qobject_type(value) == QTYPE_QDICT) {
504
qdict_do_flatten(qobject_to_qdict(value), target,
505
new_key ? new_key : entry->key);
510
qdict_del(qdict, entry->key);
512
/* Restart loop after modifying the iterated QDict */
513
entry = qdict_first(qdict);
522
* qdict_flatten(): For each nested QDict with key x, all fields with key y
523
* are moved to this QDict and their key is renamed to "x.y". This operation
524
* is applied recursively for nested QDicts.
526
void qdict_flatten(QDict *qdict)
528
qdict_do_flatten(qdict, qdict, NULL);