mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 19:10:11 +08:00
add parse_data
This commit is contained in:
@@ -294,6 +294,12 @@ BOOST_AUTO_TEST_CASE(test_float)
|
|||||||
BOOST_CHECK(!result.first.ok());
|
BOOST_CHECK(!result.first.ok());
|
||||||
BOOST_CHECK(result.second == source.begin());
|
BOOST_CHECK(result.second == source.begin());
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("42");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_parse_boolean)
|
BOOST_AUTO_TEST_CASE(test_parse_boolean)
|
||||||
@@ -354,6 +360,12 @@ BOOST_AUTO_TEST_CASE(test_parse_local_time)
|
|||||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("10");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_parse_local_date)
|
BOOST_AUTO_TEST_CASE(test_parse_local_date)
|
||||||
@@ -368,6 +380,12 @@ BOOST_AUTO_TEST_CASE(test_parse_local_date)
|
|||||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("10");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_parse_local_date_time)
|
BOOST_AUTO_TEST_CASE(test_parse_local_date_time)
|
||||||
@@ -390,6 +408,12 @@ BOOST_AUTO_TEST_CASE(test_parse_local_date_time)
|
|||||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("1000-11-11");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_parse_offset_date_time)
|
BOOST_AUTO_TEST_CASE(test_parse_offset_date_time)
|
||||||
@@ -446,6 +470,12 @@ BOOST_AUTO_TEST_CASE(test_parse_offset_date_time)
|
|||||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("1000-11-11");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_parse_datetime)
|
BOOST_AUTO_TEST_CASE(test_parse_datetime)
|
||||||
@@ -484,6 +514,12 @@ BOOST_AUTO_TEST_CASE(test_parse_datetime)
|
|||||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("12");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -583,6 +619,12 @@ BOOST_AUTO_TEST_CASE(test_parse_array)
|
|||||||
BOOST_CHECK(result.first.get() == expected);
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[dummy]");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -626,207 +668,268 @@ BOOST_AUTO_TEST_CASE(test_parse_inline_table)
|
|||||||
BOOST_CHECK(result.first.get() == expected);
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const std::string source("{dummy}");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(!result.first.ok());
|
||||||
|
BOOST_CHECK(result.second == source.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// // BOOST_AUTO_TEST_CASE(test_parse_barekey)
|
|
||||||
// // {
|
|
||||||
// // {
|
|
||||||
// // const std::string source("hoge");
|
|
||||||
// // const std::string result = toml::parse_barekey<char>::invoke(
|
|
||||||
// // source.cbegin(), toml::is_barekey<char>::invoke(source.cbegin()));
|
|
||||||
// // BOOST_CHECK_EQUAL(source, result);
|
|
||||||
// // }
|
|
||||||
// // {
|
|
||||||
// // const std::string source("bare-key");
|
|
||||||
// // const std::string result = toml::parse_barekey<char>::invoke(
|
|
||||||
// // source.cbegin(), toml::is_barekey<char>::invoke(source.cbegin()));
|
|
||||||
// // BOOST_CHECK_EQUAL(source, result);
|
|
||||||
// // }
|
|
||||||
// // {
|
|
||||||
// // const std::string source("bare_key");
|
|
||||||
// // const std::string result = toml::parse_barekey<char>::invoke(
|
|
||||||
// // source.cbegin(), toml::is_barekey<char>::invoke(source.cbegin()));
|
|
||||||
// // BOOST_CHECK_EQUAL(source, result);
|
|
||||||
// // }
|
|
||||||
// // {
|
|
||||||
// // const std::string source("42");
|
|
||||||
// // const std::string result = toml::parse_barekey<char>::invoke(
|
|
||||||
// // source.cbegin(), toml::is_barekey<char>::invoke(source.cbegin()));
|
|
||||||
// // BOOST_CHECK_EQUAL(source, result);
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// BOOST_AUTO_TEST_CASE(test_key_value_pair)
|
|
||||||
// {
|
|
||||||
// typedef toml::parse_key_value_pair<char> parser;
|
|
||||||
// typedef toml::is_key_value_pair<char> acceptor;
|
|
||||||
// {
|
|
||||||
// const std::string source("key=1");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", 1};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key =\t1");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", 1};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = true");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", true};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = -42");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", -42};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = -42.0");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", -42.};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = \"string\"");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", "string"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = 1901-01-01T00:00:00");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", toml::Datetime(1901, 1,1,0,0,0,0,0)};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = [1,2,3]");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key", {1,2,3}};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("key = {foo=1,bar=2.0,baz='3'}");
|
|
||||||
// const std::pair<toml::key, toml::value> expected{"key",
|
|
||||||
// {{"foo", 1}, {"bar", 2.0}, {"baz", "3"}}};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// BOOST_AUTO_TEST_CASE(test_table_definition)
|
|
||||||
// {
|
|
||||||
// typedef toml::parse_standard_table_definition<char> parser;
|
|
||||||
// typedef toml::is_table_definition<char> acceptor;
|
|
||||||
// {
|
|
||||||
// const std::string source("[foo]");
|
|
||||||
// const std::vector<toml::key> expected{"foo"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[foo.bar.baz]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[foo . bar. baz]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[foo . \"bar\" . baz]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[foo . \"b\\tar\" . baz]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "b\tar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// BOOST_AUTO_TEST_CASE(test_array_of_table_definition)
|
|
||||||
// {
|
|
||||||
// typedef toml::parse_array_of_table_definition<char> parser;
|
|
||||||
// typedef toml::is_array_of_table_definition<char> acceptor;
|
|
||||||
// {
|
|
||||||
// const std::string source("[[foo]]");
|
|
||||||
// const std::vector<toml::key> expected{"foo"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[[foo.bar.baz]]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[[foo . bar. baz]]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[[foo . \"bar\" . baz]]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// const std::string source("[[foo . \"b\\tar\" . baz]]");
|
|
||||||
// const std::vector<toml::key> expected{"foo", "b\tar", "baz"};
|
|
||||||
// const auto result = parser::invoke(
|
|
||||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
|
||||||
// const bool check = result == expected;
|
|
||||||
// BOOST_CHECK(check);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_parse_barekey)
|
||||||
|
{
|
||||||
|
typedef toml::parse_barekey parser;
|
||||||
|
typedef toml::is_barekey<toml::charactor> acceptor;
|
||||||
|
{
|
||||||
|
const std::string source("hoge");
|
||||||
|
const toml::key expected("hoge");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("bare-key");
|
||||||
|
const toml::key expected("bare-key");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("bare_key");
|
||||||
|
const toml::key expected("bare_key");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("42");
|
||||||
|
const toml::key expected("42");
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_key_value_pair)
|
||||||
|
{
|
||||||
|
typedef toml::parse_key_value_pair<char> parser;
|
||||||
|
typedef toml::is_key_value_pair<char> acceptor;
|
||||||
|
{
|
||||||
|
const std::string source("key=1");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", 1};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key =\t1");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", 1};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = true");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", true};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = -42");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", -42};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = -42.0");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", -42.};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = \"string\"");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", "string"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = 1901-01-01T00:00:00");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", toml::Datetime(1901, 1,1,0,0,0,0,0)};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = [1,2,3]");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key", {1,2,3}};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = {foo=1,bar=2.0,baz='3'}");
|
||||||
|
const std::pair<toml::key, toml::value> expected{"key",
|
||||||
|
{{"foo", 1}, {"bar", 2.0}, {"baz", "3"}}};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_table_definition)
|
||||||
|
{
|
||||||
|
typedef toml::parse_table_definition parser;
|
||||||
|
typedef toml::is_table_definition<char> acceptor;
|
||||||
|
{
|
||||||
|
const std::string source("[foo]");
|
||||||
|
const std::vector<toml::key> expected{"foo"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[foo.bar.baz]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[foo . bar. baz]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[foo . \"bar\" . baz]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[foo . \"b\\tar\" . baz]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "b\tar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_array_of_table_definition)
|
||||||
|
{
|
||||||
|
typedef toml::parse_array_of_table_definition parser;
|
||||||
|
typedef toml::is_array_of_table_definition<char> acceptor;
|
||||||
|
{
|
||||||
|
const std::string source("[[foo]]");
|
||||||
|
const std::vector<toml::key> expected{"foo"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[[foo.bar.baz]]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[[foo . bar. baz]]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[[foo . \"bar\" . baz]]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "bar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[[foo . \"b\\tar\" . baz]]");
|
||||||
|
const std::vector<toml::key> expected{"foo", "b\tar", "baz"};
|
||||||
|
const auto result = parser::invoke(source.cbegin());
|
||||||
|
BOOST_CHECK(result.first.ok());
|
||||||
|
BOOST_CHECK(result.first.get() == expected);
|
||||||
|
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_parse_data)
|
||||||
|
{
|
||||||
|
typedef toml::parse_data parser;
|
||||||
|
{
|
||||||
|
const std::string source("#hogehoge");
|
||||||
|
const toml::Table expected{};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = 'value'");
|
||||||
|
const toml::Table expected{{"key", "value"}};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("key = 'value' #hoge");
|
||||||
|
const toml::Table expected{{"key", "value"}};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[table]\nkey = 'value' #hoge");
|
||||||
|
const toml::Table expected{{"table", {{"key", "value"}} }};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[table]\n\tkey = 'value'\n\t#hoge");
|
||||||
|
const toml::Table expected{{"table", {{"key", "value"}} }};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[table]\n\tkey = 'value'\n\t#hoge");
|
||||||
|
const toml::Table expected{{"table", {{"key", "value"}} }};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string source("[nested.table]\n\tkey = 'value'\n\t#hoge");
|
||||||
|
const toml::Table expected{{"nested", {{"table", {{"key", "value"}}}}}};
|
||||||
|
const auto result = parser::invoke(source.cbegin(), source.cend());
|
||||||
|
BOOST_CHECK(result == expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
405
toml/parser.hpp
405
toml/parser.hpp
@@ -757,197 +757,220 @@ struct parse_inline_table
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// template<typename charT>
|
struct parse_table_definition
|
||||||
// struct parse_table_contents
|
{
|
||||||
// {
|
typedef toml::charactor value_type;
|
||||||
// typedef charT value_type;
|
typedef detail::result<std::vector<toml::key>> result_type;
|
||||||
// typedef toml::Table result_type;
|
|
||||||
//
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
// template<typename Iterator, class = typename std::enable_if<
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
value_type>::value>::type>
|
||||||
// value_type>::value>::type>
|
static std::pair<result_type, Iterator> invoke(Iterator iter)
|
||||||
// static result_type invoke(Iterator iter, Iterator end)
|
{
|
||||||
// {
|
const Iterator end = is_table_definition<value_type>::invoke(iter);
|
||||||
// result_type result;
|
if(iter == end) return std::make_pair(result_type{}, iter);
|
||||||
// while(iter != end)
|
|
||||||
// {
|
std::vector<toml::key> result;
|
||||||
// iter = is_empty_lines<charT>::invoke(iter);
|
result.reserve(std::count(iter, end, '.')+1);
|
||||||
//
|
|
||||||
// Iterator tmp = is_key_value_pair<charT>::invoke(iter);
|
const Iterator last = std::prev(end);
|
||||||
// result.emplace(parse_key_value_pair<charT>::invoke(iter, tmp));
|
iter = is_any_num_of_ws<value_type>::invoke(iter);
|
||||||
// iter = is_one_of<is_comment<charT>, is_newline<charT>>::invoke(tmp);
|
iter = is_any_num_of_ws<value_type>::invoke(std::next(iter));
|
||||||
//
|
|
||||||
// iter = is_empty_lines<charT>::invoke(iter);
|
auto tmp = parse_key::invoke(iter);
|
||||||
// }
|
if(!tmp.first.ok()) throw syntax_error("table definition");
|
||||||
// return result;
|
result.emplace_back(tmp.first.move());
|
||||||
// }
|
iter = is_any_num_of_ws<value_type>::invoke(tmp.second);
|
||||||
// };
|
|
||||||
//
|
while(iter != last)
|
||||||
// template<typename charT>
|
{
|
||||||
// struct parse_standard_table_definition
|
iter = is_charactor<value_type, '.'>::invoke(iter);
|
||||||
// {
|
iter = is_any_num_of_ws<value_type>::invoke(iter);
|
||||||
// typedef charT value_type;
|
|
||||||
// typedef std::vector<toml::key> result_type;
|
tmp = parse_key::invoke(iter);
|
||||||
//
|
if(!tmp.first.ok()) throw syntax_error("table definition");
|
||||||
// template<typename Iterator, class = typename std::enable_if<
|
result.emplace_back(tmp.first.move());
|
||||||
// std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
iter = is_any_num_of_ws<value_type>::invoke(tmp.second);
|
||||||
// value_type>::value>::type>
|
}
|
||||||
// static result_type invoke(Iterator iter, Iterator end)
|
return std::make_pair(result, end);
|
||||||
// {
|
}
|
||||||
// result_type result;
|
};
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(iter);
|
|
||||||
// --end;
|
struct parse_array_of_table_definition
|
||||||
// assert(*iter == '[' && *end == ']');
|
{
|
||||||
// ++iter;
|
typedef toml::charactor value_type;
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(iter);
|
typedef detail::result<std::vector<toml::key>> result_type;
|
||||||
//
|
|
||||||
// Iterator tmp = is_key<charT>::invoke(iter);
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
// result.emplace_back(parse_key<charT>::invoke(iter, tmp));
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(tmp);
|
value_type>::value>::type>
|
||||||
//
|
static std::pair<result_type, Iterator> invoke(Iterator iter)
|
||||||
// while(iter != end)
|
{
|
||||||
// {
|
const Iterator end = is_array_of_table_definition<value_type>::invoke(iter);
|
||||||
// iter = is_charactor<charT, '.'>::invoke(iter);
|
if(iter == end) return std::make_pair(result_type{}, iter);
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(iter);
|
|
||||||
//
|
std::vector<toml::key> result;
|
||||||
// tmp = is_key<charT>::invoke(iter);
|
result.reserve(std::count(iter, end, '.')+1);
|
||||||
// result.emplace_back(parse_key<charT>::invoke(iter, tmp));
|
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(tmp);
|
const Iterator last = end - 2;
|
||||||
// }
|
iter = is_any_num_of_ws<value_type>::invoke(iter) + 2;
|
||||||
// return result;
|
iter = is_any_num_of_ws<value_type>::invoke(iter);
|
||||||
// }
|
|
||||||
// };
|
auto tmp = parse_key::invoke(iter);
|
||||||
//
|
if(!tmp.first.ok()) throw syntax_error("array of table definition");
|
||||||
// template<typename charT>
|
result.emplace_back(tmp.first.move());
|
||||||
// struct parse_array_of_table_definition
|
iter = is_any_num_of_ws<value_type>::invoke(tmp.second);
|
||||||
// {
|
|
||||||
// typedef charT value_type;
|
while(iter != last)
|
||||||
// typedef std::vector<toml::key> result_type;
|
{
|
||||||
//
|
iter = is_charactor<value_type, '.'>::invoke(iter);
|
||||||
// template<typename Iterator, class = typename std::enable_if<
|
iter = is_any_num_of_ws<value_type>::invoke(iter);
|
||||||
// std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
|
||||||
// value_type>::value>::type>
|
tmp = parse_key::invoke(iter);
|
||||||
// static result_type invoke(Iterator iter, Iterator end)
|
if(!tmp.first.ok()) throw syntax_error("array of table definition");
|
||||||
// {
|
result.emplace_back(tmp.first.move());
|
||||||
// result_type result;
|
iter = is_any_num_of_ws<value_type>::invoke(tmp.second);
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(iter);
|
}
|
||||||
// --end;
|
return std::make_pair(result, end);
|
||||||
// assert(*iter == '[' && *std::next(iter) == '[' &&
|
}
|
||||||
// *end == ']' && *std::prev(end) == ']');
|
};
|
||||||
// ++iter; ++iter; --end;
|
|
||||||
//
|
struct parse_data
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(iter);
|
{
|
||||||
//
|
typedef toml::charactor value_type;
|
||||||
// Iterator tmp = is_key<charT>::invoke(iter);
|
typedef toml::Table result_type;
|
||||||
// result.emplace_back(parse_key<charT>::invoke(iter, tmp));
|
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(tmp);
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
//
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// while(iter != end)
|
value_type>::value>::type>
|
||||||
// {
|
static result_type invoke(Iterator iter, const Iterator end)
|
||||||
// iter = is_charactor<charT, '.'>::invoke(iter);
|
{
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(iter);
|
toml::Table result;
|
||||||
//
|
auto noname = parse_table_contents(iter, end);
|
||||||
// tmp = is_key<charT>::invoke(iter);
|
result = std::move(noname.first);
|
||||||
// result.emplace_back(parse_key<charT>::invoke(iter, tmp));
|
iter = skip_empty(noname.second, end);
|
||||||
// iter = is_any_num_of_ws<charT>::invoke(tmp);
|
|
||||||
// }
|
while(iter != end)
|
||||||
// return result;
|
{
|
||||||
// }
|
iter = skip_empty(iter, end);
|
||||||
// };
|
std::pair<detail::result<std::vector<toml::key>>, Iterator> tabname;
|
||||||
//
|
if((tabname = parse_table_definition::invoke(iter)).first.ok())
|
||||||
// template<typename charT>
|
{
|
||||||
// struct parse_data
|
auto contents = parse_table_contents(tabname.second, end);
|
||||||
// {
|
push_table(result, std::move(contents.first),
|
||||||
// typedef charT value_type;
|
tabname.first.get().begin(), tabname.first.get().end());
|
||||||
// typedef toml::Table result_type;
|
iter = contents.second;
|
||||||
//
|
}
|
||||||
// template<typename Iterator, class = typename std::enable_if<
|
else if((tabname = parse_array_of_table_definition::invoke(iter)).first.ok())
|
||||||
// std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
{
|
||||||
// value_type>::value>::type>
|
auto contents = parse_table_contents(tabname.second, end);
|
||||||
// static result_type invoke(Iterator iter, Iterator end)
|
push_array_of_table(result, std::move(contents.first),
|
||||||
// {
|
tabname.first.get().begin(), tabname.first.get().end());
|
||||||
// result_type result;
|
iter = contents.second;
|
||||||
//
|
}
|
||||||
// Iterator tmp = is_table_contents<charT>::invoke(iter);
|
else
|
||||||
// if(tmp != iter)
|
throw syntax_error("parse_data: unknown line");
|
||||||
// {
|
}
|
||||||
// result = parse_table_contents<charT>::invoke(iter, tmp);
|
return result;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// while(iter != end)
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
// {
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// if(iter != (tmp = is_table_definition<charT>::invoke(iter)))
|
value_type>::value>::type>
|
||||||
// {
|
static Iterator
|
||||||
// auto k = parse_standard_table_definition<charT>::invoke(iter, tmp);
|
skip_empty(Iterator iter, Iterator end)
|
||||||
// iter = tmp;
|
{
|
||||||
// tmp = is_table_contents<charT>::invoke(iter);
|
while(iter != end)
|
||||||
// auto tab = parse_table_contents<charT>::invoke(iter, tmp);
|
{
|
||||||
// push_table(result, std::move(tab), std::begin(k), std::end(k));
|
if(*iter == '#')
|
||||||
// }
|
{
|
||||||
// else if(iter != (tmp=is_array_of_table_definition<charT>::invoke(iter)))
|
while(iter != end &&
|
||||||
// {
|
iter == is_newline<value_type>::invoke(iter)){++iter;}
|
||||||
// auto k = parse_array_of_table_definition<charT>::invoke(iter, tmp);
|
}
|
||||||
// iter = tmp;
|
else if(iter == is_newline<value_type>::invoke(iter) &&
|
||||||
// tmp = is_table_contents<charT>::invoke(iter);
|
iter == is_whitespace<value_type>::invoke(iter))
|
||||||
// auto tab = parse_table_contents<charT>::invoke(iter, tmp);
|
{
|
||||||
// push_array_of_table(result, std::move(tab),
|
return iter;
|
||||||
// std::begin(k), std::end(k));
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// throw internal_error("no array ");
|
++iter;
|
||||||
// }
|
}
|
||||||
// return result;
|
}
|
||||||
// }
|
return iter;
|
||||||
//
|
}
|
||||||
// template<typename Iterator, class = typename std::enable_if<
|
|
||||||
// std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
// toml::key>::value>::type>
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// static void
|
value_type>::value>::type>
|
||||||
// push_table(toml::Table& data, toml::Table&& v, Iterator iter, Iterator end)
|
static std::pair<toml::Table, Iterator>
|
||||||
// {
|
parse_table_contents(Iterator iter, Iterator end)
|
||||||
// if(iter == std::prev(end))
|
{
|
||||||
// {
|
toml::Table table;
|
||||||
// if(data.count(*iter) == 1)
|
iter = skip_empty(iter, end);
|
||||||
// throw syntax_error("duplicate key");
|
while(iter != end)
|
||||||
// data.emplace(*iter, std::move(v));
|
{
|
||||||
// }
|
auto kv = parse_key_value_pair<value_type>::invoke(iter);
|
||||||
//
|
if(!kv.first.ok()) return std::make_pair(table, iter);
|
||||||
// if(data.count(*iter) == 0)
|
|
||||||
// data.emplace(*iter, toml::Table());
|
table.emplace(kv.first.move());
|
||||||
// else if(data[*iter].type() != value_t::Table)
|
iter = kv.second;
|
||||||
// throw syntax_error("duplicate key");
|
iter = skip_empty(iter, end);
|
||||||
//
|
}
|
||||||
// return push_table(data[*iter].template cast<value_t::Table>(),
|
return std::make_pair(table, iter);
|
||||||
// std::move(v), std::next(iter), end);
|
}
|
||||||
// }
|
|
||||||
//
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
// template<typename Iterator, class = typename std::enable_if<
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
toml::key>::value>::type>
|
||||||
// toml::key>::value>::type>
|
static void
|
||||||
// static void
|
push_table(toml::Table& data, toml::Table&& v, Iterator iter, Iterator end)
|
||||||
// push_array_of_table(toml::Table& data, toml::Table&& v,
|
{
|
||||||
// Iterator iter, Iterator end)
|
if(iter == std::prev(end))
|
||||||
// {
|
{
|
||||||
// if(iter == std::prev(end))
|
if(data.count(*iter) == 1)
|
||||||
// {
|
throw syntax_error("duplicate key");
|
||||||
// if(data.count(*iter) == 0)
|
data.emplace(*iter, std::move(v));
|
||||||
// data.emplace(*iter, toml::Array());
|
return;
|
||||||
// else if(data.at(*iter).type() != value_t::Array)
|
}
|
||||||
// throw syntax_error("duplicate key");
|
|
||||||
//
|
if(data.count(*iter) == 0)
|
||||||
// data[*iter].template cast<value_t::Array>().emplace_back(std::move(v));
|
data.emplace(*iter, toml::Table());
|
||||||
// }
|
else if(data[*iter].type() != value_t::Table)
|
||||||
//
|
throw syntax_error("duplicate key");
|
||||||
// if(data.count(*iter) == 0)
|
|
||||||
// data.emplace(*iter, toml::Table());
|
return push_table(data[*iter].template cast<value_t::Table>(),
|
||||||
// else if(data[*iter].type() != value_t::Table)
|
std::move(v), std::next(iter), end);
|
||||||
// throw syntax_error("duplicate key");
|
}
|
||||||
//
|
|
||||||
// return push_array_of_table(data[*iter].template cast<value_t::Table>(),
|
template<typename Iterator, class = typename std::enable_if<
|
||||||
// std::move(v), std::next(iter), end);
|
std::is_same<typename std::iterator_traits<Iterator>::value_type,
|
||||||
// }
|
toml::key>::value>::type>
|
||||||
//
|
static void
|
||||||
// };
|
push_array_of_table(toml::Table& data, toml::Table&& v,
|
||||||
|
Iterator iter, Iterator end)
|
||||||
|
{
|
||||||
|
if(iter == std::prev(end))
|
||||||
|
{
|
||||||
|
if(data.count(*iter) == 0)
|
||||||
|
data.emplace(*iter, toml::Array());
|
||||||
|
else if(data.at(*iter).type() != value_t::Array)
|
||||||
|
throw syntax_error("duplicate key");
|
||||||
|
|
||||||
|
data[*iter].template cast<value_t::Array>().emplace_back(std::move(v));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.count(*iter) == 0)
|
||||||
|
data.emplace(*iter, toml::Table());
|
||||||
|
else if(data[*iter].type() != value_t::Table)
|
||||||
|
throw syntax_error("duplicate key");
|
||||||
|
|
||||||
|
return push_array_of_table(data[*iter].template cast<value_t::Table>(),
|
||||||
|
std::move(v), std::next(iter), end);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}// toml
|
}// toml
|
||||||
#endif// TOML11_PARSER
|
#endif// TOML11_PARSER
|
||||||
|
Reference in New Issue
Block a user