[glib] GMarkup: share some common code for closing tags
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GMarkup: share some common code for closing tags
- Date: Mon, 28 Oct 2013 22:25:10 +0000 (UTC)
commit cbccbaeacfbde66f4b611b37752b0d96e77ca91e
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Oct 28 13:56:26 2013 -0700
GMarkup: share some common code for closing tags
The code for dealing with </foo> and the second half of <foo/> was
largely duplicated. We can share a lot of it by using a common
function.
This slightly changes the behaviour of the parser under error
circumstances: previously the parser would deal with '<foo/}' by first
issuing the end_element callback and then flagging the error due to the
unexpected character. Now we will flag the unexpected character error
first, skipping the callback.
This behaviour change required modifying the testsuite.
https://bugzilla.gnome.org/show_bug.cgi?id=665634
glib/gmarkup.c | 113 +++++++++++++++-------------------
glib/tests/markups/fail-44.expected | 1 -
glib/tests/markups/fail-8.expected | 1 -
3 files changed, 50 insertions(+), 65 deletions(-)
---
diff --git a/glib/gmarkup.c b/glib/gmarkup.c
index fb02a42..0b1278b 100644
--- a/glib/gmarkup.c
+++ b/glib/gmarkup.c
@@ -1038,6 +1038,37 @@ emit_start_element (GMarkupParseContext *context,
propagate_error (context, error, tmp_error);
}
+static void
+emit_end_element (GMarkupParseContext *context,
+ GError **error)
+{
+ /* We need to pop the tag stack and call the end_element
+ * function, since this is the close tag
+ */
+ GError *tmp_error = NULL;
+
+ g_assert (context->tag_stack != NULL);
+
+ possibly_finish_subparser (context);
+
+ tmp_error = NULL;
+ if (context->parser->end_element)
+ (* context->parser->end_element) (context,
+ current_element (context),
+ context->user_data,
+ &tmp_error);
+
+ ensure_no_outstanding_subparser (context);
+
+ if (tmp_error)
+ {
+ mark_error (context, tmp_error);
+ g_propagate_error (error, tmp_error);
+ }
+
+ pop_tag (context);
+}
+
/**
* g_markup_parse_context_parse:
* @context: a #GMarkupParseContext
@@ -1184,54 +1215,25 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
case STATE_AFTER_ELISION_SLASH:
/* Possible next state: AFTER_CLOSE_ANGLE */
+ if (*context->iter == '>')
+ {
+ /* move after the close angle */
+ advance_char (context);
+ context->state = STATE_AFTER_CLOSE_ANGLE;
+ emit_end_element (context, error);
+ }
+ else
+ {
+ gchar buf[8];
- {
- /* We need to pop the tag stack and call the end_element
- * function, since this is the close tag
- */
- GError *tmp_error = NULL;
-
- g_assert (context->tag_stack != NULL);
-
- possibly_finish_subparser (context);
-
- tmp_error = NULL;
- if (context->parser->end_element)
- (* context->parser->end_element) (context,
- current_element (context),
- context->user_data,
- &tmp_error);
-
- ensure_no_outstanding_subparser (context);
-
- if (tmp_error)
- {
- mark_error (context, tmp_error);
- g_propagate_error (error, tmp_error);
- }
- else
- {
- if (*context->iter == '>')
- {
- /* move after the close angle */
- advance_char (context);
- context->state = STATE_AFTER_CLOSE_ANGLE;
- }
- else
- {
- gchar buf[8];
-
- set_error (context,
- error,
- G_MARKUP_ERROR_PARSE,
- _("Odd character '%s', expected a '>' character "
- "to end the empty-element tag '%s'"),
- utf8_str (context->iter, buf),
- current_element (context));
- }
- }
- pop_tag (context);
- }
+ set_error (context,
+ error,
+ G_MARKUP_ERROR_PARSE,
+ _("Odd character '%s', expected a '>' character "
+ "to end the empty-element tag '%s'"),
+ utf8_str (context->iter, buf),
+ current_element (context));
+ }
break;
case STATE_INSIDE_OPEN_TAG_NAME:
@@ -1589,26 +1591,11 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
}
else
{
- GError *tmp_error;
advance_char (context);
context->state = STATE_AFTER_CLOSE_ANGLE;
context->start = NULL;
- possibly_finish_subparser (context);
-
- /* call the end_element callback */
- tmp_error = NULL;
- if (context->parser->end_element)
- (* context->parser->end_element) (context,
- close_name->str,
- context->user_data,
- &tmp_error);
-
- ensure_no_outstanding_subparser (context);
- pop_tag (context);
-
- if (tmp_error)
- propagate_error (context, error, tmp_error);
+ emit_end_element (context, error);
}
context->partial_chunk = close_name;
truncate_partial (context);
diff --git a/glib/tests/markups/fail-44.expected b/glib/tests/markups/fail-44.expected
index 2548050..533eef7 100644
--- a/glib/tests/markups/fail-44.expected
+++ b/glib/tests/markups/fail-44.expected
@@ -1,3 +1,2 @@
ELEMENT 'foo'
-END 'foo'
ERROR Error on line 1 char 6: Odd character '≻', expected a '>' character to end the empty-element tag 'foo'
diff --git a/glib/tests/markups/fail-8.expected b/glib/tests/markups/fail-8.expected
index 2448220..31651aa 100644
--- a/glib/tests/markups/fail-8.expected
+++ b/glib/tests/markups/fail-8.expected
@@ -1,3 +1,2 @@
ELEMENT 'foo'
-END 'foo'
ERROR Error on line 1 char 6: Odd character '}', expected a '>' character to end the empty-element tag 'foo'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]