From 78900703a613031a4032d310338657a6b5aaadd9 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Fri, 31 Jul 2015 17:55:24 +0300 Subject: [PATCH] Partially rebased embed_pcdata patch to current master. --- src/pugixml.cpp | 16 +++++++++++++++- src/pugixml.hpp | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 07f3a33..913aa6e 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3430,7 +3430,7 @@ PUGI__NS_BEGIN if (!PUGI__OPTSET(parse_trim_pcdata)) s = mark; - if (cursor->parent || PUGI__OPTSET(parse_fragment)) + if ((cursor->parent && !PUGI__OPTSET(parse_embed_pcdata)) || PUGI__OPTSET(parse_fragment)) { PUGI__PUSHNODE(node_pcdata); // Append a new node on the tree. cursor->value = s; // Save the offset. @@ -3439,6 +3439,14 @@ PUGI__NS_BEGIN PUGI__POPNODE(); // Pop since this is a standalone. + if (!*s) break; + } + else if (cursor->parent && PUGI__OPTSET(parse_embed_pcdata) && !cursor->value) + { + cursor->value = s; // Save the offset. + + s = strconv_pcdata(s); + if (!*s) break; } else @@ -5479,6 +5487,9 @@ namespace pugi PUGI__FN const char_t* xml_node::child_value() const { if (!_root) return PUGIXML_TEXT(""); + + if ((_root->header & impl::xml_memory_page_type_mask) + 1 == node_element && _root->value) + return _root->value; for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) if (impl::is_text_node(i) && i->value) @@ -6237,6 +6248,9 @@ namespace pugi { if (!_root || impl::is_text_node(_root)) return _root; + if ((_root->header & impl::xml_memory_page_type_mask) + 1 == node_element && _root->value) + return _root; + for (xml_node_struct* node = _root->first_child; node; node = node->next_sibling) if (impl::is_text_node(node)) return node; diff --git a/src/pugixml.hpp b/src/pugixml.hpp index cdd24b6..72aeb64 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -158,6 +158,9 @@ namespace pugi // is a valid document. This flag is off by default. const unsigned int parse_fragment = 0x1000; + // Experimental API for reduced memory consumption + const unsigned int parse_embed_pcdata = 0x0800; + // The default parsing mode. // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded, // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.