mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-11-27 00:43:47 +00:00
Make ini parser use a map of string_ref
It is important that you keep your IniFile object around if you access stuff in the map returned by parsed() at this point.
This commit is contained in:
parent
2dd4ebe515
commit
41e1d35c7a
2 changed files with 23 additions and 26 deletions
|
@ -38,7 +38,7 @@
|
|||
|
||||
namespace tawashi {
|
||||
namespace {
|
||||
typedef std::string string_type;
|
||||
typedef boost::string_ref string_type;
|
||||
|
||||
template <typename Iterator, typename Skipper>
|
||||
struct IniGrammar : boost::spirit::qi::grammar<Iterator, IniFile::IniMapType(), Skipper> {
|
||||
|
@ -65,32 +65,28 @@ namespace tawashi {
|
|||
using boost::spirit::_1;
|
||||
using boost::spirit::qi::char_;
|
||||
using boost::spirit::qi::eol;
|
||||
typedef IniFile::KeyValueMapType refpair;
|
||||
using boost::spirit::qi::raw;
|
||||
using boost::string_ref;
|
||||
typedef IniFile::KeyValueMapType::value_type refpair;
|
||||
|
||||
section_head = '[' >> +(char_ - ']') >> ']' >> eol;
|
||||
key = +(char_ - '=');
|
||||
key_value = key >> '=' >> *(char_ - eol) >> eol;
|
||||
section_head = '[' >> raw[+(char_ - ']')][_val = px::bind(
|
||||
&string_ref::substr,
|
||||
px::construct<string_ref>(px::ref(*m_master_string)),
|
||||
px::begin(_1) - px::ref(m_begin), px::size(_1)
|
||||
)] >> ']' >> eol;
|
||||
key = raw[+(char_ - '=')][_val = px::bind(
|
||||
&string_ref::substr,
|
||||
px::construct<string_ref>(px::ref(*m_master_string)),
|
||||
px::begin(_1) - px::ref(m_begin), px::size(_1)
|
||||
)];
|
||||
key_value = key[px::bind(&refpair::first, _val) = _1] >> '=' >>
|
||||
raw[*(char_ - eol)][px::bind(&refpair::second, _val) = px::bind(
|
||||
&string_ref::substr,
|
||||
px::construct<string_ref>(px::ref(*m_master_string)),
|
||||
px::begin(_1) - px::ref(m_begin), px::size(_1)
|
||||
)] >> eol;
|
||||
key_values = *key_value;
|
||||
start = *(section_head >> key_values);
|
||||
|
||||
//start %= *(section_head >> key_values);
|
||||
//key_values %= *key_value;
|
||||
//key_value = key[px::bind(&refpair::first, _val) = _1] >> '=' >>
|
||||
// raw[*char_][px::bind(&refpair::second, _val) = px::bind(
|
||||
// &string_ref::substr,
|
||||
// px::construct<string_ref>(px::ref(*m_master_string)),
|
||||
// px::begin(_1) - px::ref(m_begin), px::size(_1)
|
||||
//)];
|
||||
//key = as_string[+(char_ - '=')][_val = px::bind(
|
||||
// &string_ref::substr,
|
||||
// px::construct<string_ref>(px::ref(*m_master_string)),
|
||||
// px::begin(_1) - px::ref(m_begin), px::size(_1)
|
||||
//)];
|
||||
//section_head = '[' >> as_string[(+char_ - ']')][_val = px::bind(
|
||||
// &string_ref::substr,
|
||||
// px::construct<string_ref>(px::ref(*m_master_string)),
|
||||
// px::begin(_1) - px::ref(m_begin), px::size(_1)
|
||||
//)] >> ']';
|
||||
}
|
||||
|
||||
IniFile::IniMapType parse_ini (const std::string* parIni) {
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <iterator>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace tawashi {
|
||||
class IniFile {
|
||||
public:
|
||||
typedef boost::container::flat_map<std::string, std::string> KeyValueMapType;
|
||||
typedef boost::container::flat_map<std::string, KeyValueMapType> IniMapType;
|
||||
typedef boost::container::flat_map<boost::string_ref, boost::string_ref> KeyValueMapType;
|
||||
typedef boost::container::flat_map<boost::string_ref, KeyValueMapType> IniMapType;
|
||||
|
||||
IniFile (std::istream_iterator<char> parInputFrom, std::istream_iterator<char> parInputEnd);
|
||||
explicit IniFile (std::string&& parIniData);
|
||||
|
|
Loading…
Reference in a new issue