From a28252205adf5edcac5e2076a4a49f4eece60994 Mon Sep 17 00:00:00 2001 From: vineeth-11316 Date: Sun, 20 Aug 2023 10:21:26 +0530 Subject: [PATCH] Final Commit --- docs/manual.adoc | 2 +- src/pugixml.cpp | 6 +++--- tests/test_parse.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/docs/manual.adoc b/docs/manual.adoc index b9ed8b4..592d413 100644 --- a/docs/manual.adoc +++ b/docs/manual.adoc @@ -749,7 +749,7 @@ These flags control the resulting tree contents: * [[parse_embed_pcdata]]`parse_embed_pcdata` determines if PCDATA contents is to be saved as element values. Normally element nodes have names but not values; this flag forces the parser to store the contents as a value if PCDATA is the first child of the element node (otherwise PCDATA node is created as usual). This can significantly reduce the memory required for documents with many PCDATA nodes. To retrieve the data you can use `xml_node::value()` on the element nodes or any of the higher-level functions like `child_value` or `text`. This flag is *off* by default. Since this flag significantly changes the DOM structure it is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments. This flag is *off* by default. -* [[parse_merge_pcdata]]`parse_merge_pcdata` determines if PCDATA contents is to be merged with the previous PCDATA node, if no intermediary nodes are present between them.If the PCDATA contains CDATA sections , PI nodes , comments in between and either of the flags <> ,<> ,<> is not set means, the contents of PCDATA will be merged with the previous one.Since this flag significantly changes the DOM structure it is only recommended for parsing documents with PCDATA nodes in memory-constrained environments. This flag is *off* by default. +* [[parse_merge_pcdata]]`parse_merge_pcdata` determines if PCDATA contents is to be merged with the previous PCDATA node, if no intermediary nodes are present between them.If the PCDATA contains CDATA sections , PI nodes , comments in between and either of the flags <> ,<> ,<> is not set means, the contents of PCDATA will be merged with the previous one. This flag is *off* by default. * [[parse_fragment]]`parse_fragment` determines if document should be treated as a fragment of a valid XML. Parsing document as a fragment leads to top-level PCDATA content (i.e. text that is not located inside a node) to be added to a tree, and additionally treats documents without element nodes as valid and permits multiple top-level element nodes (currently multiple top-level element nodes are also permitted when the flag is off, but that behavior should not be relied on). This flag is *off* by default. diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 40cd5a1..d1190e1 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -276,11 +276,11 @@ PUGI_IMPL_NS_BEGIN { assert(dst && src); -#ifdef PUGIXML_WCHAR_MODE + #ifdef PUGIXML_WCHAR_MODE wcscat(dst, src); -#else + #else strcat(dst, src); -#endif + #endif } PUGI_IMPL_NS_END diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 180c70a..f4d50a2 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -1252,6 +1252,53 @@ TEST_XML_FLAGS(parse_embed_pcdata_comment, "text1text2", parse_emb CHECK_STRING(n.last_child().value(), STR("text2")); } +TEST(parse_merge_pcdata) +{ + + const unsigned int default_parse = parse_escapes | parse_wconv_attribute | parse_eol; + + unsigned int flag_sets[] = {parse_cdata, parse_pi, parse_comments, parse_declaration}; + + for (unsigned int i = 0; i < sizeof(flag_sets) / sizeof(flag_sets[0]); ++i) + { + xml_document doc; + const unsigned int flags = default_parse | parse_merge_pcdata | flag_sets[i]; + xml_parse_result res = doc.load_string(STR("First textSecond textsome more textLast text"), flags); + CHECK(res); + + xml_node child = doc.child(STR("node")); + + if (flags & parse_comments) + { + CHECK_STRING(doc.child(STR("node")).text().get(), STR("First text")); + CHECK_STRING(child.first_child().value(), STR("First text")); + CHECK(child.first_child().next_sibling().type() == node_comment); + CHECK_NODE(doc, STR("First textSecond textsome more textLast text")); + } + else if (flags & parse_cdata) + { + CHECK_STRING(doc.child(STR("node")).text().get(), STR("First textSecond text")); + CHECK_STRING(child.first_child().value(), STR("First textSecond text")); + CHECK(child.first_child().next_sibling().type() == node_cdata); + CHECK_NODE(doc, STR("First textSecond textsome more textLast text")); + } + else if (flags & parse_pi) + { + CHECK_STRING(doc.child(STR("node")).text().get(), STR("First textSecond textsome more text")); + CHECK_STRING(child.first_child().value(), STR("First textSecond textsome more text")); + CHECK(child.first_child().next_sibling().type() == node_pi); + CHECK_NODE(doc, STR("First textSecond textsome more textLast text")); + } + else + { + CHECK(child.first_child() == child.last_child()); + CHECK(child.first_child().type() == node_pcdata); + CHECK_NODE(doc, STR("First textSecond textsome more textLast text")); + } + CHECK(child.last_child().type() == node_pcdata); + } +} + TEST(parse_encoding_detect) { char test[] = "";