Intial Commit for merge_pcdata

This commit is contained in:
vineeth-11316 2023-08-19 09:17:54 +05:30
parent 980cf57ff4
commit e15adbe704
2 changed files with 29 additions and 3 deletions

View File

@ -270,6 +270,18 @@ PUGI_IMPL_NS_BEGIN
return static_cast<size_t>(end - s); return static_cast<size_t>(end - s);
#endif #endif
} }
// concat two strings and store it in the first one
PUGI_IMPL_FN void strconcat(char_t* dst,const char_t* src)
{
assert(dst && src);
#ifdef PUGIXML_WCHAR_MODE
wcscat(dst, src);
#else
strcat(dst, src);
#endif
}
PUGI_IMPL_NS_END PUGI_IMPL_NS_END
// auto_ptr-like object for exception recovery // auto_ptr-like object for exception recovery
@ -3478,6 +3490,15 @@ PUGI_IMPL_NS_BEGIN
cursor->value = s; // Save the offset. cursor->value = s; // Save the offset.
} }
else else
{
xml_node_struct* cursor_last_child = cursor->first_child ? cursor->first_child->prev_sibling_c + 0 : 0;
if(PUGI_IMPL_OPTSET(parse_merge_pcdata) && cursor_last_child && PUGI_IMPL_NODETYPE(cursor_last_child) == node_pcdata)
{
strconcat(cursor_last_child->value, s);
s = cursor_last_child->value;
}
else
{ {
PUGI_IMPL_PUSHNODE(node_pcdata); // Append a new node on the tree. PUGI_IMPL_PUSHNODE(node_pcdata); // Append a new node on the tree.
@ -3485,6 +3506,7 @@ PUGI_IMPL_NS_BEGIN
PUGI_IMPL_POPNODE(); // Pop since this is a standalone. PUGI_IMPL_POPNODE(); // Pop since this is a standalone.
} }
}
s = strconv_pcdata(s); s = strconv_pcdata(s);

View File

@ -213,6 +213,10 @@ namespace pugi
// This flag is off by default. // This flag is off by default.
const unsigned int parse_embed_pcdata = 0x2000; const unsigned int parse_embed_pcdata = 0x2000;
// This flag determines whether determines whether the the two pcdata should be merged or not, if no intermediatory data are parsed in the document.
// This flag is off by default.
const unsigned int parse_merge_pcdata = 0x4000;
// The default parsing mode. // The default parsing mode.
// Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded, // 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. // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.