new flag G_MARKUP_PREFIX_ERROR_POSITION to cause the parser to prepend

006-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.

svn path=/trunk/; revision=5860
This commit is contained in:
Ryan Lortie 2007-11-16 03:36:51 +00:00 committed by Ryan Lortie
parent f2a5aa6700
commit 1e2c77ecbc
4 changed files with 43 additions and 25 deletions

View File

@ -1,3 +1,13 @@
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:

View File

@ -102,7 +102,7 @@ Error codes returned by markup parsing.
@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>
@ -124,6 +124,11 @@ Flags that affect the behaviour of the parser.
the parser. Instead, the content of the section (without the
<literal>&lt;![CDATA[</literal> and <literal>]]&gt;</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>

View File

@ -221,20 +221,34 @@ set_error (GMarkupParseContext *context,
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
@ -1347,10 +1361,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
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;
@ -1500,10 +1511,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
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);
@ -1613,10 +1621,7 @@ g_markup_parse_context_parse (GMarkupParseContext *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);
@ -1700,10 +1705,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
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;

View File

@ -48,7 +48,8 @@ GQuark g_markup_error_quark (void);
typedef enum
{
G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1
G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
G_MARKUP_PREFIX_ERROR_POSITION = 1 << 2
} GMarkupParseFlags;
typedef struct _GMarkupParseContext GMarkupParseContext;