From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O5Q3C-0000DG-RT for qemu-devel@nongnu.org; Fri, 23 Apr 2010 17:04:38 -0400 Received: from [140.186.70.92] (port=51638 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5Q3B-0000Bq-Ax for qemu-devel@nongnu.org; Fri, 23 Apr 2010 17:04:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O5Q38-0004e0-SM for qemu-devel@nongnu.org; Fri, 23 Apr 2010 17:04:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19302) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5Q38-0004dQ-L2 for qemu-devel@nongnu.org; Fri, 23 Apr 2010 17:04:34 -0400 Date: Fri, 23 Apr 2010 18:04:19 -0300 From: Luiz Capitulino Message-ID: <20100423180419.776a85bf@redhat.com> In-Reply-To: <1271340427-12579-2-git-send-email-miguel.filho@gmail.com> References: <1271340427-12579-1-git-send-email-miguel.filho@gmail.com> <1271340427-12579-2-git-send-email-miguel.filho@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH v3 01/12] QObject API: add qdict_to_qstring() function List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Miguel Di Ciurcio Filho Cc: qemu-devel@nongnu.org, armbru@redhat.com On Thu, 15 Apr 2010 11:06:56 -0300 Miguel Di Ciurcio Filho wrote: > This is a helper function that converts a QDict to a QString, using the format: > > key1=value1 SPACE key2=value2 SPACE key3=value3 > > Handy for debugging and other things. Something I don't remember if we talked about is: why not use commas instead of whitespaces? I believe it's because there's a trailing whitespace there ;) I don't think it's difficult to add a qstring_rstrip() though. > > Signed-off-by: Miguel Di Ciurcio Filho > --- > qdict.c | 41 +++++++++++++++++++++++++++++++++++++++++ > qdict.h | 3 +++ > 2 files changed, 44 insertions(+), 0 deletions(-) > > diff --git a/qdict.c b/qdict.c > index aae57bf..fddade0 100644 > --- a/qdict.c > +++ b/qdict.c > @@ -324,6 +324,47 @@ void qdict_iter(const QDict *qdict, > } > } > > +void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque) > +{ > + QString *str = opaque; > + > + qstring_append(str, key); > + qstring_append(str, "="); > + switch (qobject_type(obj)) { > + case QTYPE_QSTRING: > + qstring_append(str, qstring_get_str(qobject_to_qstring(obj))); > + break; > + case QTYPE_QINT: > + qstring_append_int(str, qint_get_int(qobject_to_qint(obj))); > + break; > + case QTYPE_QBOOL: > + qstring_append(str, qbool_get_int(qobject_to_qbool(obj)) ? "true" : > + "false" ); > + break; > + default: > + qstring_append(str, "NULL"); > + } > + > + qstring_append(str, " "); > +} > + > +/** > + * qdict_to_qstring(): Format a string with the keys and values of a QDict. > + * > + * Nested lists and dicts are not supported, yet. > + * > + * Return a pointer to a QString, with the following format: > + * key1=value1 SPACE key2=value2 SPACE key3=value3 > + */ > +QString *qdict_to_qstring(const QDict *qdict) > +{ > + QString *str; > + str = qstring_new(); > + qdict_iter(qdict, qdict_to_qstring_iter, str); > + > + return str; > +} > + > /** > * qentry_destroy(): Free all the memory allocated by a QDictEntry > */ > diff --git a/qdict.h b/qdict.h > index 579dcdd..6731555 100644 > --- a/qdict.h > +++ b/qdict.h > @@ -3,6 +3,7 @@ > > #include "qobject.h" > #include "qlist.h" > +#include "qstring.h" > #include "qemu-queue.h" > #include > > @@ -43,6 +44,8 @@ int qdict_get_bool(const QDict *qdict, const char *key); > QList *qdict_get_qlist(const QDict *qdict, const char *key); > QDict *qdict_get_qdict(const QDict *qdict, const char *key); > const char *qdict_get_str(const QDict *qdict, const char *key); > +void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque); > +QString *qdict_to_qstring(const QDict *qdict); > int64_t qdict_get_try_int(const QDict *qdict, const char *key, > int64_t err_value); > const char *qdict_get_try_str(const QDict *qdict, const char *key);