2006-11-15 Ryan Lortie <desrt@desrt.ca>
+ * docs/reference/glib/tmpl/markup.sgml:
+ * glib/gmarkup.h:
+ * glib/gmarkup.c: new flag G_MARKUP_PREFIX_ERROR_POSITION to cause the
+ parser to prepend location information (ie: "Error on line %d, char
+ %d:") to errors generated by the GMarkupParser callbacks.
+
+ Closes #496046.
+
+2006-11-15 Ryan Lortie <desrt@desrt.ca>
+
* docs/reference/glib/glib-sections.txt:
* glib/glib.symbols:
* glib/gerror.h:
@G_MARKUP_ERROR_PARSE: document was ill-formed
@G_MARKUP_ERROR_UNKNOWN_ELEMENT: error should be set by #GMarkupParser functions; element wasn't known
@G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE: error should be set by #GMarkupParser functions; attribute wasn't known
-@G_MARKUP_ERROR_INVALID_CONTENT: error should be set by #GMarkupParser functions; something was wrong with contents of the document, e.g. invalid attribute value
+@G_MARKUP_ERROR_INVALID_POSITION: error should be set by #GMarkupParser functions; something was wrong with contents of the document, e.g. invalid attribute value
<!-- ##### MACRO G_MARKUP_ERROR ##### -->
<para>
the parser. Instead, the content of the section (without the
<literal><![CDATA[</literal> and <literal>]]></literal>) is
passed to the @text function. This flag was added in GLib 2.12.
+@G_MARKUP_PREFIX_ERROR_POSITION: Normally errors caught by GMarkup
+ itself have line/column information prefixed to them to let the
+ caller know the location of the error. When this flag is set the
+ location information is also prefixed to errors generated by the
+ #GMarkupParser implementation functions.
<!-- ##### STRUCT GMarkupParseContext ##### -->
<para>
s = g_strdup_vprintf (format, args);
va_end (args);
- tmp_error = g_error_new (G_MARKUP_ERROR,
- code,
- _("Error on line %d char %d: %s"),
- context->line_number,
- context->char_number,
- s);
-
+ tmp_error = g_error_new_literal (G_MARKUP_ERROR, code, s);
g_free (s);
+ g_prefix_error (&tmp_error,
+ _("Error on line %d char %d: "),
+ context->line_number,
+ context->char_number);
+
mark_error (context, tmp_error);
g_propagate_error (error, tmp_error);
}
+static void
+propagate_error (GMarkupParseContext *context,
+ GError **dest,
+ GError *src)
+{
+ if (context->flags & G_MARKUP_PREFIX_ERROR_POSITION)
+ g_prefix_error (&src,
+ _("Error on line %d char %d: "),
+ context->line_number,
+ context->char_number);
+
+ mark_error (context, src);
+
+ g_propagate_error (dest, src);
+}
/* To make these faster, we first use the ascii-only tests, then check
* for the usual non-alnum name-end chars, and only then call the
context->attr_values[0] == NULL);
if (tmp_error != NULL)
- {
- mark_error (context, tmp_error);
- g_propagate_error (error, tmp_error);
- }
+ propagate_error (context, error, tmp_error);
}
}
break;
context->start = context->iter;
}
else
- {
- mark_error (context, tmp_error);
- g_propagate_error (error, tmp_error);
- }
+ propagate_error (context, error, tmp_error);
}
truncate_partial (context);
context->tag_stack);
if (tmp_error)
- {
- mark_error (context, tmp_error);
- g_propagate_error (error, tmp_error);
- }
+ propagate_error (context, error, tmp_error);
}
g_free (close_name);
context->start = context->iter; /* could begin text */
}
else
- {
- mark_error (context, tmp_error);
- g_propagate_error (error, tmp_error);
- }
+ propagate_error (context, error, tmp_error);
}
break;