Add a GMarkupParseFlags flag for treating CDATA as text.

2006-05-28  Matthias Clasen  <mclasen@redhat.com>

	* glib/gmarkup.h: Add a GMarkupParseFlags flag for
	treating CDATA as text.

	* glib/gmarkup.c (g_markup_parse_context_parse):
	Implement it here.
This commit is contained in:
Matthias Clasen 2006-05-29 00:08:30 +00:00 committed by Matthias Clasen
parent c8922bb143
commit f4f6480042
6 changed files with 57 additions and 14 deletions

View File

@ -1,3 +1,11 @@
2006-05-28 Matthias Clasen <mclasen@redhat.com>
* glib/gmarkup.h: Add a GMarkupParseFlags flag for
treating CDATA as text.
* glib/gmarkup.c (g_markup_parse_context_parse):
Implement it here.
2006-05-28 Matthias Clasen <mclasen@redhat.com>
* tests/markups/expected-*: Output that test-markup

View File

@ -1,3 +1,11 @@
2006-05-28 Matthias Clasen <mclasen@redhat.com>
* glib/gmarkup.h: Add a GMarkupParseFlags flag for
treating CDATA as text.
* glib/gmarkup.c (g_markup_parse_context_parse):
Implement it here.
2006-05-28 Matthias Clasen <mclasen@redhat.com>
* tests/markups/expected-*: Output that test-markup

View File

@ -1,3 +1,7 @@
2006-05-28 Matthias Clasen <mclasen@redhat.com>
* glib/tmpl/markup.sgml: Document G_MARKUP_TREAT_CDATA_AS_TEXT.
2006-05-16 Matthias Clasen <mclasen@redhat.com>
* glib/glib-sections.txt: Add g_ascii_strtoll

View File

@ -115,11 +115,16 @@ error domains.
<!-- ##### ENUM GMarkupParseFlags ##### -->
<para>
There are no flags right now. Pass "0" for the flags argument to all
functions.
Flags that affect the behaviour of the parser.
</para>
@G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG: flag you should not use.
@G_MARKUP_TREAT_CDATA_AS_TEXT: When this flag is set, CDATA marked
sections are not passed literally to the @passthrough function of
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.
<!-- ##### STRUCT GMarkupParseContext ##### -->
<para>
@ -141,14 +146,22 @@ g_markup_parse_context_parse() will report that error back to its caller.
</para>
@start_element: Callback to invoke when the opening tag of an element
is seen.
@end_element: Callback to invoke when the closing tag of an element is seen
is seen.
@end_element: Callback to invoke when the closing tag of an element is seen.
Note that this is also called for empty tags like
<literal>&lt;empty/&gt;</literal>.
@text: Callback to invoke when some text is seen (text is always
inside an element)
@passthrough: Callback to invoke for comments, processing
instructions and doctype declarations; if you're re-writing the parsed document, write the
passthrough text back out in the same position
@error: Callback to invoke when an error occurs
inside an element). Note that the text of an element may be spread
over multiple calls of this function. If the %G_MARKUP_TREAT_CDATA_AS_TEXT
flag is set, this function is also called for the content of CDATA marked
sections.
@passthrough: Callback to invoke for comments, processing instructions
and doctype declarations; if you're re-writing the parsed document,
write the passthrough text back out in the same position. If the
%G_MARKUP_TREAT_CDATA_AS_TEXT flag is not set, this function is also
called for CDATA marked sections.
@error: Callback to invoke when an error occurs.
<!-- ##### FUNCTION g_markup_escape_text ##### -->
<para>

View File

@ -1646,7 +1646,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
/* The passthrough hasn't necessarily ended. Merge with
* partial chunk, leave state unchanged.
*/
add_to_partial (context, context->start, context->iter);
add_to_partial (context, context->start, context->iter);
}
else
{
@ -1660,7 +1660,18 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
advance_char (context); /* advance past close angle */
add_to_partial (context, context->start, context->iter);
if (context->parser->passthrough)
if (context->flags & G_MARKUP_TREAT_CDATA_AS_TEXT &&
g_str_has_prefix (context->partial_chunk->str, "<![CDATA[") &&
g_str_has_suffix (context->partial_chunk->str, "]]>"))
{
if (context->parser->text)
(*context->parser->text) (context,
context->partial_chunk->str + strlen ("<![CDATA["),
context->partial_chunk->len - strlen ("<![CDATA[" "]]>"),
context->user_data,
&tmp_error);
}
else if (context->parser->passthrough)
(*context->parser->passthrough) (context,
context->partial_chunk->str,
context->partial_chunk->len,

View File

@ -46,9 +46,8 @@ GQuark g_markup_error_quark (void);
typedef enum
{
/* Hmm, can't think of any at the moment */
G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0
G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1
} GMarkupParseFlags;
typedef struct _GMarkupParseContext GMarkupParseContext;