c++ - Boost property tree ini parsing gives error if any comment is appended to key-value -
i have working illustration programme parses ini formatted info boost property_tree. when append comment key-value pairs coredump. have searched comment trim function on property_tree cannot find anything.
the working program:
static std::string inidata = r"( # comment [section1] key1 = 15 key2=val )"; void read_data(std::istream &is) { using boost::property_tree::ptree; ptree pt; read_ini(is, pt); boost::optional<uint32_t> sect1_key1 = pt.get_optional<uint32_t>(ptree::path_type("section1/key1", '/')); boost::optional<std::string> sect1_key2 = pt.get_optional<std::string>(ptree::path_type("section1/key2", '/')); std::cout << "section1.key1: " << *sect1_key1 << std::endl; std::cout << "section1.key2: " << *sect1_key2 << std::endl; }
the comment appended config:
static std::string inidata = r"( # comment [section1] key1 = 15 # comment added! key2=val )";
the core dump output:
/usr/local/include/boost/optional/optional.hpp:992: boost::optional<t>::reference_type boost::optional<t>::get() [with t = unsigned int; boost::optional<t>::reference_type = unsigned int&]: assertion `this->is_initialized()' failed. aborted (core dumped)
the comment style **is not supported*.
you can see moving comment on text value, results in:
section1.key1: 15 section1.key2: val # woah
tester shows #
special in first non-whitespace column: live on coliru
#include <boost/property_tree/ini_parser.hpp> #include <iostream> static std::string inidata = r"( # comment [section1] key1 = 15 key2=val # woah k#ey3=whoops )"; using boost::property_tree::ptree; void read_data(std::istream &is) { ptree pt; read_ini(is, pt); (auto section : pt) (auto key : section.second) std::cout << "debug: " << key.first << "=" << key.second.get_value<std::string>() << "\n"; } #include <sstream> int main() { std::istringstream iss(inidata); read_data(iss); }
c++ boost
No comments:
Post a Comment