[gtk/wip/otte/listview: 1032/1040] builder-tool: Pass through CDATA where it makes sense



commit 2d4b952f9332e18c585b4528d6e7c2ead06665e9
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 13 14:03:20 2019 -0500

    builder-tool: Pass through CDATA where it makes sense
    
    This avoids a ton of escaping for
    GtkBuilderListItemFactory::bytes.

 gtk/tools/gtk-builder-tool-simplify.c | 62 ++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 20 deletions(-)
---
diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c
index 449a367aff..4a2229c378 100644
--- a/gtk/tools/gtk-builder-tool-simplify.c
+++ b/gtk/tools/gtk-builder-tool-simplify.c
@@ -263,6 +263,36 @@ keep_for_rewrite (const char *class_name,
   return found;
 }
 
+static gboolean
+has_attribute (Element    *elt,
+               const char *name,
+               const char *value)
+{
+  int i;
+
+  for (i = 0; elt->attribute_names[i]; i++)
+    {
+      if (strcmp (elt->attribute_names[i], name) == 0 &&
+          (value == NULL || strcmp (elt->attribute_values[i], value) == 0))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+is_cdata_property (Element *element)
+{
+  if (g_str_equal (element->element_name, "property") &&
+      has_attribute (element, "name", "bytes") &&
+      element->parent != NULL &&
+      g_str_equal (element->parent->element_name, "object") &&
+      has_attribute (element->parent, "class", "GtkBuilderListItemFactory"))
+    return TRUE;
+
+  return FALSE;
+}
+
 static gboolean
 is_pcdata_element (Element *element)
 {
@@ -485,23 +515,6 @@ value_is_default (Element      *element,
   return ret;
 }
 
-static gboolean
-has_attribute (Element    *elt,
-               const char *name,
-               const char *value)
-{
-  int i;
-
-  for (i = 0; elt->attribute_names[i]; i++)
-    {
-      if (strcmp (elt->attribute_names[i], name) == 0 &&
-          (value == NULL || strcmp (elt->attribute_values[i], value) == 0))
-        return TRUE;
-    }
-
-  return FALSE;
-}
-
 static const char *
 get_attribute_value (Element *element,
                      const char *name)
@@ -1693,9 +1706,18 @@ dump_element (Element *element,
         }
       else
         {
-          char *escaped = g_markup_escape_text (element->data, -1);
-          g_fprintf (output, "%s", escaped);
-          g_free (escaped);
+          if (is_cdata_property (element))
+            {
+              g_fprintf (output, "<![CDATA[");
+              g_fprintf (output, "%s", element->data);
+              g_fprintf (output, "]]>");
+            }
+          else
+            {          
+              char *escaped = g_markup_escape_text (element->data, -1);
+              g_fprintf (output, "%s", escaped);
+              g_free (escaped);
+            }
         }
       g_fprintf (output, "</%s>\n", element->element_name);
     }


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