[glib] Support &s as key of dict entry in format string



commit a6c57591c0928fee3d3f026289972024bd2b00ec
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Mar 23 09:17:15 2010 -0500

    Support &s as key of dict entry in format string
    
    Partial fix for bug 613618.

 glib/gvariant.c       |   26 ++++++++++++++++++--------
 glib/tests/gvariant.c |    7 +++++++
 2 files changed, 25 insertions(+), 8 deletions(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index e3e7cdc..721740f 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -2745,15 +2745,25 @@ g_variant_format_string_scan (const gchar  *string,
     case '{':
       c = next_char();
 
-      if (c == '@')
-        c = next_char ();
+      if (c == '&')
+        {
+          c = next_char ();
 
-      /* ISO/IEC 9899:1999 (C99) §7.21.5.2:
-       *    The terminating null character is considered to be
-       *    part of the string.
-       */
-      if (c != '\0' && strchr ("bynqiuxthdsog?", c) == NULL)
-        return FALSE;
+          if (c != 's' && c != 'o' && c != 'g')
+            return FALSE;
+        }
+      else
+        {
+          if (c == '@')
+            c = next_char ();
+
+          /* ISO/IEC 9899:1999 (C99) §7.21.5.2:
+           *    The terminating null character is considered to be
+           *    part of the string.
+           */
+          if (c != '\0' && strchr ("bynqiuxthdsog?", c) == NULL)
+            return FALSE;
+        }
 
       if (!g_variant_format_string_scan (string, limit, &string))
         return FALSE;
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index f756d13..1a51268 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -2699,6 +2699,13 @@ test_format_strings (void)
             *end == '\0');
   g_assert (g_variant_format_string_scan ("{yv}", NULL, &end) &&
             *end == '\0');
+  g_assert (!g_variant_format_string_scan ("{&?v}", NULL, &end));
+  g_assert (g_variant_format_string_scan ("{ ?v}", NULL, &end) &&
+            *end == '\0');
+  g_assert (!g_variant_format_string_scan ("{&@sv}", NULL, &end));
+  g_assert (!g_variant_format_string_scan ("{@&sv}", NULL, &end));
+  g_assert (g_variant_format_string_scan ("{&sv}", NULL, &end) &&
+            *end == '\0');
   g_assert (!g_variant_format_string_scan ("{vv}", NULL, &end));
   g_assert (!g_variant_format_string_scan ("{y}", NULL, &end));
   g_assert (!g_variant_format_string_scan ("{yyy}", NULL, &end));



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