[glib/gsettings] Variant printer: improve type annotation of arrays
- From: Ryan Lortie <ryanl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/gsettings] Variant printer: improve type annotation of arrays
- Date: Thu, 3 Sep 2009 03:31:57 +0000 (UTC)
commit 681f603c25e710b754def0a6f2a6598721e301e1
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Sep 2 23:31:22 2009 -0400
Variant printer: improve type annotation of arrays
glib/gvariant-printer.c | 26 +++++++++++++++++---------
1 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/glib/gvariant-printer.c b/glib/gvariant-printer.c
index 8c149bc..c73e6aa 100644
--- a/glib/gvariant-printer.c
+++ b/glib/gvariant-printer.c
@@ -69,25 +69,33 @@ g_variant_print_string (GVariant *value,
{
GVariantIter iter;
- if (type_annotate)
- g_string_append_printf (string, "@%s ",
- g_variant_get_type_string (value));
- g_string_append_c (string, '[');
if (g_variant_iter_init (&iter, value))
{
GVariant *element;
- /* Array elements are all of the same type which we already
- * printed, so further type annotation is pointless. */
+ g_string_append_c (string, '[');
+
+ /* only type annotate the first element (if requested) */
while ((element = g_variant_iter_next_value (&iter)))
{
- g_variant_print_string (element, string, FALSE);
+ g_variant_print_string (element, string, type_annotate);
g_string_append (string, ", ");
+ type_annotate = FALSE;
}
g_string_truncate (string, string->len - 2);
- }
- g_string_append_c (string, ']');
+ g_string_append_c (string, ']');
+ }
+ else
+ {
+ /* if there are no elements then we must type
+ * annotate the array itself (if requested)
+ */
+ if (type_annotate)
+ g_string_append_printf (string, "@%s ",
+ g_variant_get_type_string (value));
+ g_string_append (string, "[]");
+ }
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]