From dd14e2605da5e878c99c803d96580c48e2eb0386 Mon Sep 17 00:00:00 2001 From: Timo Strunk Date: Wed, 17 Feb 2016 14:02:51 +0100 Subject: [PATCH] Added new trim whitespace option, which does not collapse internal whitespace. --- .../property_tree/detail/xml_parser_flags.hpp | 8 +++++++- .../detail/xml_parser_read_rapidxml.hpp | 19 +++++++++++++++---- include/boost/property_tree/xml_parser.hpp | 2 ++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/boost/property_tree/detail/xml_parser_flags.hpp b/include/boost/property_tree/detail/xml_parser_flags.hpp index 9340fe2516..4a0971a0ed 100644 --- a/include/boost/property_tree/detail/xml_parser_flags.hpp +++ b/include/boost/property_tree/detail/xml_parser_flags.hpp @@ -20,10 +20,16 @@ namespace boost { namespace property_tree { namespace xml_parser static const int no_comments = 0x2; /// Whitespace should be collapsed and trimmed. static const int trim_whitespace = 0x4; + /// Whitespace should only be trimmed. + static const int trim_whitespace_without_normalization = 0x8; inline bool validate_flags(int flags) { - return (flags & ~(no_concat_text | no_comments | trim_whitespace)) == 0; + return (flags & ~(no_concat_text + | no_comments + | trim_whitespace + | trim_whitespace_without_normalization + )) == 0; } } } } diff --git a/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp b/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp index 9c04219189..7bb8ab43ca 100644 --- a/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp +++ b/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp @@ -103,6 +103,9 @@ namespace boost { namespace property_tree { namespace xml_parser try { // Parse using appropriate flags + const int f_tws_n = parse_trim_whitespace; + const int f_tws_n_c = parse_trim_whitespace + | parse_comment_nodes; const int f_tws = parse_normalize_whitespace | parse_trim_whitespace; const int f_c = parse_comment_nodes; @@ -114,13 +117,21 @@ namespace boost { namespace property_tree { namespace xml_parser if (flags & no_comments) { if (flags & trim_whitespace) doc.BOOST_NESTED_TEMPLATE parse(&v.front()); - else - doc.BOOST_NESTED_TEMPLATE parse<0>(&v.front()); + else { + if (flags & trim_whitespace_without_normalization) + doc.BOOST_NESTED_TEMPLATE parse(&v.front()); + else + doc.BOOST_NESTED_TEMPLATE parse<0>(&v.front()); + } } else { if (flags & trim_whitespace) doc.BOOST_NESTED_TEMPLATE parse(&v.front()); - else - doc.BOOST_NESTED_TEMPLATE parse(&v.front()); + else { + if (flags & trim_whitespace_without_normalization) + doc.BOOST_NESTED_TEMPLATE parse(&v.front()); + else + doc.BOOST_NESTED_TEMPLATE parse(&v.front()); + } } // Create ptree from nodes diff --git a/include/boost/property_tree/xml_parser.hpp b/include/boost/property_tree/xml_parser.hpp index 0544c55544..f892df6d54 100644 --- a/include/boost/property_tree/xml_parser.hpp +++ b/include/boost/property_tree/xml_parser.hpp @@ -41,6 +41,8 @@ namespace boost { namespace property_tree { namespace xml_parser * @li @c no_comments -- Skip XML comments. * @li @c trim_whitespace -- Trim leading and trailing whitespace from text, * and collapse sequences of whitespace. + * @li @c trim_whitespace_without_normalization -- Trim leading and trailing + * whitespace from text. */ template void read_xml(std::basic_istream<