[gnome-builder/wip/slaf/xml-pack: 558/572] xml-pack: get a pointer to the tag content when parsing



commit 235cf325eb06b0f5a56edb9c1d6b08b49f548e4f
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sun May 14 22:35:37 2017 +0200

    xml-pack: get a pointer to the tag content when parsing

 plugins/xml-pack/ide-xml-parser.c |    8 +++++---
 plugins/xml-pack/ide-xml-sax.c    |   31 ++++++++++++++++++++-----------
 plugins/xml-pack/ide-xml-sax.h    |    1 +
 3 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-parser.c b/plugins/xml-pack/ide-xml-parser.c
index d3fef5e..2aad156 100644
--- a/plugins/xml-pack/ide-xml-parser.c
+++ b/plugins/xml-pack/ide-xml-parser.c
@@ -120,6 +120,7 @@ ide_xml_parser_create_diagnostic (ParserState            *state,
   ide_xml_sax_get_location (self->sax_parser,
                             &start_line, &start_line_offset,
                             &end_line, &end_line_offset,
+                            NULL,
                             &size);
 
   ifile = ide_file_new (context, state->file);
@@ -180,6 +181,7 @@ ide_xml_parser_state_processing (IdeXmlParser          *self,
   IdeXmlSymbolNode *parent_node;
   G_GNUC_UNUSED IdeXmlSymbolNode *popped_node;
   g_autofree gchar *popped_element_name = NULL;
+  const gchar *content;
   gint start_line;
   gint start_line_offset;
   gint end_line;
@@ -196,7 +198,7 @@ ide_xml_parser_state_processing (IdeXmlParser          *self,
     }
 
   depth = ide_xml_sax_get_depth (self->sax_parser);
-  ide_xml_sax_get_location (self->sax_parser, &start_line, &start_line_offset, &end_line, &end_line_offset, 
&size);
+  ide_xml_sax_get_location (self->sax_parser, &start_line, &start_line_offset, &end_line, &end_line_offset, 
&content, &size);
 
   if (node == NULL)
     {
@@ -382,7 +384,7 @@ ide_xml_parser_internal_subset_sax_cb (ParserState   *state,
   printf ("internal subset:%s external_id:%s system_id:%s\n", name, external_id, system_id);
 
   entry.schema_kind = SCHEMA_KIND_DTD;
-  ide_xml_sax_get_location (self->sax_parser, &entry.schema_line, &entry.schema_col, NULL, NULL, NULL);
+  ide_xml_sax_get_location (self->sax_parser, &entry.schema_line, &entry.schema_col, NULL, NULL, NULL, NULL);
   g_array_append_val (state->schemas, entry);
 }
 
@@ -446,7 +448,7 @@ ide_xml_parser_processing_instruction_sax_cb (ParserState   *state,
           else
             goto fail;
 
-          ide_xml_sax_get_location (self->sax_parser, &entry.schema_line, &entry.schema_col, NULL, NULL, 
NULL);
+          ide_xml_sax_get_location (self->sax_parser, &entry.schema_line, &entry.schema_col, NULL, NULL, 
NULL, NULL);
           entry.schema_file = get_absolute_schema_file (state->file, schema_url);
           g_array_append_val (state->schemas, entry);
 
diff --git a/plugins/xml-pack/ide-xml-sax.c b/plugins/xml-pack/ide-xml-sax.c
index 18e9e5b..c49c072 100644
--- a/plugins/xml-pack/ide-xml-sax.c
+++ b/plugins/xml-pack/ide-xml-sax.c
@@ -181,10 +181,11 @@ ide_xml_sax_parse (IdeXmlSax   *self,
 }
 
 static void
-get_tag_location (IdeXmlSax *self,
-                  gint      *line,
-                  gint      *line_offset,
-                  gsize     *size)
+get_tag_location (IdeXmlSax    *self,
+                  gint         *line,
+                  gint         *line_offset,
+                  const gchar **content,
+                  gsize        *size)
 {
   xmlParserInput *input;
   const gchar *base;
@@ -197,6 +198,7 @@ get_tag_location (IdeXmlSax *self,
   g_assert (IDE_IS_XML_SAX (self));
   g_assert (line != NULL);
   g_assert (line_offset != NULL);
+  g_assert (content != NULL);
   g_assert (size != NULL);
 
   /* TODO: handle other types of line break */
@@ -227,6 +229,7 @@ get_tag_location (IdeXmlSax *self,
     {
       *line = start_line_number;
       *line_offset = xmlSAX2GetColumnNumber (self->context);
+      *content = NULL;
       *size = 0;
 
       return;
@@ -259,27 +262,30 @@ get_tag_location (IdeXmlSax *self,
 
   *line = start_line_number;
   *line_offset = (current - line_start) + 1;
+  *content = current;
   *size = (const gchar *)input->cur - current + size_offset;
 }
 
 gboolean
-ide_xml_sax_get_location (IdeXmlSax *self,
-                          gint      *start_line,
-                          gint      *start_line_offset,
-                          gint      *end_line,
-                          gint      *end_line_offset,
-                          gsize     *size)
+ide_xml_sax_get_location (IdeXmlSax    *self,
+                          gint         *start_line,
+                          gint         *start_line_offset,
+                          gint         *end_line,
+                          gint         *end_line_offset,
+                          const gchar **content,
+                          gsize        *size)
 {
   gint tmp_line;
   gint tmp_line_offset;
   gint tmp_end_line;
   gint tmp_end_line_offset;
+  const gchar *tmp_content;
   gsize tmp_size;
 
   g_return_val_if_fail (IDE_IS_XML_SAX (self), FALSE);
   g_return_val_if_fail (self->context != NULL, FALSE);
 
-  get_tag_location (self, &tmp_line, &tmp_line_offset, &tmp_size);
+  get_tag_location (self, &tmp_line, &tmp_line_offset, &tmp_content, &tmp_size);
 
   if (start_line != NULL)
     *start_line = tmp_line;
@@ -287,6 +293,9 @@ ide_xml_sax_get_location (IdeXmlSax *self,
   if (start_line_offset != NULL)
     *start_line_offset = tmp_line_offset;
 
+  if (content != NULL)
+    *content = tmp_content;
+
   if (size != NULL)
     *size = tmp_size;
 
diff --git a/plugins/xml-pack/ide-xml-sax.h b/plugins/xml-pack/ide-xml-sax.h
index d9c1fa3..ae64076 100644
--- a/plugins/xml-pack/ide-xml-sax.h
+++ b/plugins/xml-pack/ide-xml-sax.h
@@ -54,6 +54,7 @@ gboolean        ide_xml_sax_get_location        (IdeXmlSax              *self,
                                                  gint                   *start_line_offset,
                                                  gint                   *end_line,
                                                  gint                   *end_line_offset,
+                                                 const gchar           **content,
                                                  gsize                  *size);
 IdeXmlSax      *ide_xml_sax_new                 (void);
 gboolean        ide_xml_sax_parse               (IdeXmlSax              *self,


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