[glib] GVariant: Stop lexing format strings at :



commit 409a3a61ece7bbdacbf2469eb7b86c3aa3c44653
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Mar 26 08:01:51 2010 -0500

    GVariant: Stop lexing format strings at :
    
    Lets us parse this successfully: {%s: %s}.

 glib/gvariant-parser.c |    7 ++++---
 glib/tests/gvariant.c  |    1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c
index 5bb2c35..1020633 100644
--- a/glib/gvariant-parser.c
+++ b/glib/gvariant-parser.c
@@ -167,11 +167,12 @@ token_stream_prepare (TokenStream *stream)
       break;
 
     case '@': case '%':
-      /* stop at the first space, comma or unmatched bracket.
-       * deals nicely with cases like (%i, %i).
+      /* stop at the first space, comma, colon or unmatched bracket.
+       * deals nicely with cases like (%i, %i) or {%i: %i}.
        */
       for (end = stream->stream + 1;
-           end != stream->end && *end != ',' && !g_ascii_isspace (*end);
+           end != stream->end && *end != ',' &&
+           *end != ':' && !g_ascii_isspace (*end);
            end++)
 
         if (*end == '(' || *end == '{')
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index 1a51268..b37f5a7 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -3678,6 +3678,7 @@ test_parse_positional (void)
                                 " ('three', %u)]", "two", 3);
   g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("a(su)")));
   check_and_free (value, "[('one', 1), ('two', 2), ('three', 3)]");
+  check_and_free (g_variant_new_parsed ("{%s:%i}", "one", 1), "{'one': 1}");
 
   if (do_failed_test ("*GVariant format string*"))
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]