From 5726d872f3c7a78a6c17ff5a6e47e01cff0a5e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Wed, 25 Sep 2013 13:30:01 +0200 Subject: qdict: Extract qdict_extract_subqdict Signed-off-by: Benoit Canet Signed-off-by: Kevin Wolf --- qobject/qdict.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'qobject') diff --git a/qobject/qdict.c b/qobject/qdict.c index 472f106..0f3e0a6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -527,3 +527,24 @@ void qdict_flatten(QDict *qdict) { qdict_do_flatten(qdict, qdict, NULL); } + +/* extract all the src QDict entries starting by start into dst */ +void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start) + +{ + const QDictEntry *entry, *next; + const char *p; + + *dst = qdict_new(); + entry = qdict_first(src); + + while (entry != NULL) { + next = qdict_next(src, entry); + if (strstart(entry->key, start, &p)) { + qobject_incref(entry->value); + qdict_put_obj(*dst, p, entry->value); + qdict_del(src, entry->key); + } + entry = next; + } +} -- cgit v1.1