From f4f6480042b4ef3691a18cfd32274deb088faf5b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 29 May 2006 00:08:30 +0000 Subject: [PATCH] Add a GMarkupParseFlags flag for treating CDATA as text. 2006-05-28 Matthias Clasen * glib/gmarkup.h: Add a GMarkupParseFlags flag for treating CDATA as text. * glib/gmarkup.c (g_markup_parse_context_parse): Implement it here. --- ChangeLog | 8 +++++++ ChangeLog.pre-2-12 | 8 +++++++ docs/reference/ChangeLog | 4 ++++ docs/reference/glib/tmpl/markup.sgml | 31 ++++++++++++++++++++-------- glib/gmarkup.c | 15 ++++++++++++-- glib/gmarkup.h | 5 ++--- 6 files changed, 57 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb1f1cc22..acd157414 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-05-28 Matthias Clasen + + * 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 * tests/markups/expected-*: Output that test-markup diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index fb1f1cc22..acd157414 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2006-05-28 Matthias Clasen + + * 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 * tests/markups/expected-*: Output that test-markup diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index b8b1f6f6b..3f3870a71 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2006-05-28 Matthias Clasen + + * glib/tmpl/markup.sgml: Document G_MARKUP_TREAT_CDATA_AS_TEXT. + 2006-05-16 Matthias Clasen * glib/glib-sections.txt: Add g_ascii_strtoll diff --git a/docs/reference/glib/tmpl/markup.sgml b/docs/reference/glib/tmpl/markup.sgml index c14026f32..29e8efe76 100644 --- a/docs/reference/glib/tmpl/markup.sgml +++ b/docs/reference/glib/tmpl/markup.sgml @@ -115,11 +115,16 @@ error domains. -There are no flags right now. Pass "0" for the flags argument to all -functions. +Flags that affect the behaviour of the parser. @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 + <![CDATA[ and ]]>) is + passed to the @text function. This flag was added in GLib 2.12. + @@ -141,14 +146,22 @@ g_markup_parse_context_parse() will report that error back to its caller. @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 + <empty/>. @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. + diff --git a/glib/gmarkup.c b/glib/gmarkup.c index fad05d2c4..484d448ef 100644 --- a/glib/gmarkup.c +++ b/glib/gmarkup.c @@ -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, "partial_chunk->str, "]]>")) + { + if (context->parser->text) + (*context->parser->text) (context, + context->partial_chunk->str + strlen ("partial_chunk->len - strlen (""), + context->user_data, + &tmp_error); + } + else if (context->parser->passthrough) (*context->parser->passthrough) (context, context->partial_chunk->str, context->partial_chunk->len, diff --git a/glib/gmarkup.h b/glib/gmarkup.h index 47e3e8753..b272d5ca7 100644 --- a/glib/gmarkup.h +++ b/glib/gmarkup.h @@ -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;