From eee5a10faf97d51dcd85a4f78b0fbd182458bddf Mon Sep 17 00:00:00 2001 From: mknaleczb <155737254+mknaleczb@users.noreply.github.com> Date: Tue, 9 Sep 2025 07:52:15 +0000 Subject: [PATCH 1/2] Added getter string_path<>::to_str() --- include/boost/property_tree/string_path.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/property_tree/string_path.hpp b/include/boost/property_tree/string_path.hpp index de2abc0a4..ae59d60e2 100644 --- a/include/boost/property_tree/string_path.hpp +++ b/include/boost/property_tree/string_path.hpp @@ -128,6 +128,8 @@ namespace boost { namespace property_tree std::string dump() const { return detail::dump_sequence(m_value); } + + const String& to_str() const { return m_value; } /// Concatenates two path components friend string_path operator /(string_path p1, const string_path &p2) From d8c0a79a0dc7bf44557d65d58705ef7b8501e22b Mon Sep 17 00:00:00 2001 From: mknaleczb <155737254+mknaleczb@users.noreply.github.com> Date: Tue, 9 Sep 2025 08:10:01 +0000 Subject: [PATCH 2/2] Modified string_path<> class - in case of standard C++17 or higher it uses std::string_view instead of const std::string& --- include/boost/property_tree/string_path.hpp | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/include/boost/property_tree/string_path.hpp b/include/boost/property_tree/string_path.hpp index ae59d60e2..e85c394a0 100644 --- a/include/boost/property_tree/string_path.hpp +++ b/include/boost/property_tree/string_path.hpp @@ -24,6 +24,9 @@ #include #include #include +#if __cplusplus >= 201703L +#include +#endif namespace boost { namespace property_tree { @@ -49,6 +52,25 @@ namespace boost { namespace property_tree it = s.begin() + idx; } + + +#if __cplusplus >= 201703L + template + inline std::string dump_sequence(const Sequence &) + { + return ""; + } + inline std::string dump_sequence(std::string_view s) + { + return std::string(s); + } +#ifndef BOOST_NO_STD_WSTRING + inline std::string dump_sequence(std::wstring_view s) + { + return narrow(s.data()); + } +#endif +#else template inline std::string dump_sequence(const Sequence &) { @@ -63,6 +85,7 @@ namespace boost { namespace property_tree { return narrow(s.c_str()); } +#endif #endif } @@ -86,9 +109,22 @@ namespace boost { namespace property_tree public: typedef typename Translator::external_type key_type; typedef typename String::value_type char_type; +#if __cplusplus >= 201703L + typedef typename std::basic_string_view strview_type; +#endif /// Create an empty path. explicit string_path(char_type separator = char_type('.')); +#if __cplusplus >= 201703L + /// Create a path by parsing the given string. + /// @param value A sequence, possibly with separators, that describes + /// the path, e.g. "one.two.three". + /// @param separator The separator used in parsing. Defaults to '.'. + /// @param tr The translator used by this path to convert the individual + /// parts to keys. + string_path(strview_type value, char_type separator = char_type('.'), + Translator tr = Translator()); +#else /// Create a path by parsing the given string. /// @param value A sequence, possibly with separators, that describes /// the path, e.g. "one.two.three". @@ -97,6 +133,7 @@ namespace boost { namespace property_tree /// parts to keys. string_path(const String &value, char_type separator = char_type('.'), Translator tr = Translator()); +#endif /// Create a path by parsing the given string. /// @param value A zero-terminated array of values. Only use if zero- /// termination makes sense for your type, and your @@ -175,6 +212,15 @@ namespace boost { namespace property_tree : m_separator(separator), m_start(m_value.begin()) {} +#if __cplusplus >= 201703L + template inline + string_path::string_path(strview_type value, + char_type separator, + Translator tr) + : m_value(value.data()), m_separator(separator), + m_tr(tr), m_start(m_value.begin()) + {} +#else template inline string_path::string_path(const String &value, char_type separator, @@ -182,6 +228,7 @@ namespace boost { namespace property_tree : m_value(value), m_separator(separator), m_tr(tr), m_start(m_value.begin()) {} +#endif template inline string_path::string_path(const char_type *value,