[gtk+] builder tool: Canonicalize property names



commit f16e58e9a76a8ea3778923cae5e1f396fb2571ca
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 6 13:42:30 2016 -0400

    builder tool: Canonicalize property names
    
    When simplifying, convert property names to canonical form,
    so we don't waste time while looking them up later.

 gtk/gtk-builder-tool.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtk-builder-tool.c b/gtk/gtk-builder-tool.c
index 612efbd..63bcc7f 100644
--- a/gtk/gtk-builder-tool.c
+++ b/gtk/gtk-builder-tool.c
@@ -42,6 +42,27 @@ typedef struct {
   gint indent;
 } MyParserData;
 
+static void
+canonicalize_key (gchar *key)
+{
+  gchar *p;
+
+  for (p = key; *p != 0; p++)
+    {
+      gchar c = *p;
+
+      /* We may meet something like AtkObject::accessible-name */
+      if (c == ':' && ((p > key && p[-1] == ':') || p[1] == ':'))
+        continue;
+
+      if (c != '-' &&
+          (c < '0' || c > '9') &&
+          (c < 'A' || c > 'Z') &&
+          (c < 'a' || c > 'z'))
+        *p = '-';
+    }
+}
+
 static GParamSpec *
 get_property_pspec (MyParserData *data,
                     const gchar  *class_name,
@@ -58,7 +79,7 @@ get_property_pspec (MyParserData *data,
 
   class = g_type_class_ref (type);
   canonical_name = g_strdup (property_name);
-  g_strdelimit (canonical_name, "_", '-');
+  canonicalize_key (canonical_name);
   if (data->packing)
     pspec = gtk_container_class_find_child_property (class, canonical_name);
   else if (data->cell_packing)
@@ -299,6 +320,10 @@ maybe_emit_property (MyParserData *data)
         continue;
 
       escaped = g_markup_escape_text (data->attribute_values[i], -1);
+
+      if (strcmp (data->attribute_names[i], "name") == 0)
+        canonicalize_key (escaped);
+
       g_printf (" %s=\"%s\"", data->attribute_names[i], escaped);
       g_free (escaped);
     }


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