From 64d98cdcfc5d4fda17a75fc89b3e9d93cbd8e03c Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Thu, 22 Jul 2010 13:13:10 +0000 Subject: CDATA section is output as multiple sections if it contains ]]> git-svn-id: http://pugixml.googlecode.com/svn/trunk@616 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 3792c40..76745e2 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -2762,6 +2762,28 @@ namespace } } + void text_output_cdata(xml_buffered_writer& writer, const char_t* s) + { + do + { + writer.write('<', '!', '[', 'C', 'D'); + writer.write('A', 'T', 'A', '['); + + const char_t* prev = s; + + // look for ]]> sequence - we can't output it as is since it terminates CDATA + while (*s && !(s[0] == ']' && s[1] == ']' && s[2] == '>')) ++s; + + // skip ]] if we stopped at ]]>, > will go to the next CDATA section + if (*s) s += 2; + + writer.write(prev, static_cast(s - prev)); + + writer.write(']', ']', '>'); + } + while (*s); + } + void node_output_attributes(xml_buffered_writer& writer, const xml_node& node) { const char_t* default_name = PUGIXML_TEXT(":anonymous"); @@ -2855,10 +2877,7 @@ namespace break; case node_cdata: - writer.write('<', '!', '[', 'C', 'D'); - writer.write('A', 'T', 'A', '['); - writer.write(node.value()); - writer.write(']', ']', '>'); + text_output_cdata(writer, node.value()); if ((flags & format_raw) == 0) writer.write('\n'); break; -- cgit v1.2.3