[gnome-builder/wip/slaf/xml-pack: 557/572] xml-pack: fetch node attributes when parsing



commit db5fbb24f1b5cae952671b954ef125f47b23e72f
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sun May 14 22:29:05 2017 +0200

    xml-pack: fetch node attributes when parsing

 plugins/xml-pack/ide-xml-parser-generic.c |    1 +
 plugins/xml-pack/ide-xml-parser-private.h |    1 +
 plugins/xml-pack/ide-xml-parser-ui.c      |    1 +
 plugins/xml-pack/ide-xml-parser.c         |   27 +++++++++++++++++++++++++++
 4 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-parser-generic.c b/plugins/xml-pack/ide-xml-parser-generic.c
index 4526901..40607de 100644
--- a/plugins/xml-pack/ide-xml-parser-generic.c
+++ b/plugins/xml-pack/ide-xml-parser-generic.c
@@ -70,6 +70,7 @@ ide_xml_parser_generic_start_element_sax_cb (ParserState    *state,
   node = ide_xml_symbol_node_new (label, NULL, NULL, IDE_SYMBOL_XML_ELEMENT, NULL, 0, 0, 0, 0, 0);
   g_object_set (node, "use-markup", TRUE, NULL);
 
+  state->attributes = (const gchar **)attributes;
   ide_xml_parser_state_processing (self, state, (const gchar *)name, node, 
IDE_XML_SAX_CALLBACK_TYPE_START_ELEMENT, FALSE);
 }
 
diff --git a/plugins/xml-pack/ide-xml-parser-private.h b/plugins/xml-pack/ide-xml-parser-private.h
index 6dc35c2..f6ead64 100644
--- a/plugins/xml-pack/ide-xml-parser-private.h
+++ b/plugins/xml-pack/ide-xml-parser-private.h
@@ -71,6 +71,7 @@ typedef struct _ParserState
   IdeXmlSymbolNode  *root_node;
   IdeXmlSymbolNode  *parent_node;
   IdeXmlSymbolNode  *current_node;
+  const gchar      **attributes;
   BuildState         build_state;
   gint               current_depth;
   GArray            *schemas;
diff --git a/plugins/xml-pack/ide-xml-parser-ui.c b/plugins/xml-pack/ide-xml-parser-ui.c
index 7993110..efc5087 100644
--- a/plugins/xml-pack/ide-xml-parser-ui.c
+++ b/plugins/xml-pack/ide-xml-parser-ui.c
@@ -198,6 +198,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState    *state,
                                       IDE_SYMBOL_UI_ITEM, NULL, 0, 0, 0, 00, 0);
     }
 
+  state->attributes = (const gchar **)attributes;
   ide_xml_parser_state_processing (self, state, (const gchar *)name, node, 
IDE_XML_SAX_CALLBACK_TYPE_START_ELEMENT, is_internal);
 }
 
diff --git a/plugins/xml-pack/ide-xml-parser.c b/plugins/xml-pack/ide-xml-parser.c
index 755bb6c..d3fef5e 100644
--- a/plugins/xml-pack/ide-xml-parser.c
+++ b/plugins/xml-pack/ide-xml-parser.c
@@ -147,6 +147,28 @@ ide_xml_parser_create_diagnostic (ParserState            *state,
   return diagnostic;
 }
 
+static gchar **
+fetch_attributes_names (IdeXmlParser  *self,
+                        const gchar  **attributes)
+{
+  GPtrArray *attrs;
+
+  g_assert (IDE_IS_XML_PARSER (self));
+
+  if (attributes == NULL)
+    return NULL;
+
+  attrs = g_ptr_array_new ();
+  while (attributes [0] != NULL)
+    {
+      g_ptr_array_add (attrs, g_strdup (attributes [0]));
+      attributes += 2;
+    }
+
+  g_ptr_array_add (attrs, NULL);
+  return (gchar**)g_ptr_array_free (attrs, FALSE);
+}
+
 void
 ide_xml_parser_state_processing (IdeXmlParser          *self,
                                  ParserState           *state,
@@ -189,6 +211,9 @@ ide_xml_parser_state_processing (IdeXmlParser          *self,
           ide_xml_stack_push (self->stack, element_name, node, state->parent_node, depth);
           ide_xml_symbol_node_take_internal_child (state->parent_node, node);
           state->parent_node = node;
+
+          ide_xml_symbol_node_take_attributes_names (node, fetch_attributes_names (self, state->attributes));
+          state->attributes = NULL;
         }
       else if (callback_type == IDE_XML_SAX_CALLBACK_TYPE_END_ELEMENT)
         {
@@ -244,6 +269,8 @@ ide_xml_parser_state_processing (IdeXmlParser          *self,
         ide_xml_symbol_node_take_child (state->parent_node, node);
 
       state->parent_node = node;
+      ide_xml_symbol_node_take_attributes_names (node, fetch_attributes_names (self, state->attributes));
+      state->attributes = NULL;
     }
   else if (callback_type == IDE_XML_SAX_CALLBACK_TYPE_END_ELEMENT)
     {


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