diff --git a/tests/test_acceptor.cpp b/tests/test_acceptor.cpp index 3dbcb52..dfce2eb 100644 --- a/tests/test_acceptor.cpp +++ b/tests/test_acceptor.cpp @@ -102,8 +102,8 @@ BOOST_AUTO_TEST_CASE(test_basic_inline_string) BOOST_CHECK(is_valid::invoke(invalid_escape.cbegin(), invalid_escape.cend()) == invalid_escape.cbegin()); } { - const std::string invalid_charactor("\"foo\10bar\""); - BOOST_CHECK(is_valid::invoke(invalid_charactor.cbegin(), invalid_charactor.cend()) == invalid_charactor.cbegin()); + const std::string invalid_character("\"foo\10bar\""); + BOOST_CHECK(is_valid::invoke(invalid_character.cbegin(), invalid_character.cend()) == invalid_character.cbegin()); } { const std::string multi("\"\"\"multiline\"\"\""); @@ -144,8 +144,8 @@ BOOST_AUTO_TEST_CASE(test_basic_multiline_string) BOOST_CHECK(is_valid::invoke(invalid_escape.cbegin(), invalid_escape.cend()) == invalid_escape.cbegin()); } { - const std::string invalid_charactor("\"\"\"foo\10bar\"\"\""); - BOOST_CHECK(is_valid::invoke(invalid_charactor.cbegin(), invalid_charactor.cend()) == invalid_charactor.cbegin()); + const std::string invalid_character("\"\"\"foo\10bar\"\"\""); + BOOST_CHECK(is_valid::invoke(invalid_character.cbegin(), invalid_character.cend()) == invalid_character.cbegin()); } { const std::string single("\"singleline\""); @@ -178,8 +178,8 @@ BOOST_AUTO_TEST_CASE(test_literal_inline_string) BOOST_CHECK(is_valid::invoke(newline.cbegin(), newline.cend()) == newline.cbegin()); } { - const std::string invalid_charactor("'foo\10bar'"); - BOOST_CHECK(is_valid::invoke(invalid_charactor.cbegin(), invalid_charactor.cend()) == invalid_charactor.cbegin()); + const std::string invalid_character("'foo\10bar'"); + BOOST_CHECK(is_valid::invoke(invalid_character.cbegin(), invalid_character.cend()) == invalid_character.cbegin()); } { const std::string multi("'''multiline'''"); @@ -212,8 +212,8 @@ BOOST_AUTO_TEST_CASE(test_literal_multiline_string) } { - const std::string invalid_charactor("'''foo\10bar'''"); - BOOST_CHECK(is_valid::invoke(invalid_charactor.cbegin(), invalid_charactor.cend()) == invalid_charactor.cbegin()); + const std::string invalid_character("'''foo\10bar'''"); + BOOST_CHECK(is_valid::invoke(invalid_character.cbegin(), invalid_character.cend()) == invalid_character.cbegin()); } { const std::string single("'singleline'"); diff --git a/tests/test_parser.cpp b/tests/test_parser.cpp index 6b66b2c..3a04c13 100644 --- a/tests/test_parser.cpp +++ b/tests/test_parser.cpp @@ -14,7 +14,7 @@ BOOST_AUTO_TEST_CASE(test_parse_basic_inline_string) { typedef toml::parse_basic_inline_string parser; - typedef toml::is_basic_inline_string acceptor; + typedef toml::is_basic_inline_string acceptor; { const std::string source("\"simple\""); const std::string expected("simple"); @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(test_parse_basic_inline_string) BOOST_AUTO_TEST_CASE(test_parse_basic_multiline_string) { typedef toml::parse_basic_multiline_string parser; - typedef toml::is_basic_multiline_string acceptor; + typedef toml::is_basic_multiline_string acceptor; { //XXX ifdef windows platform const std::string source("\"\"\"\nRoses are red\nViolets are blue\"\"\""); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(test_parse_basic_multiline_string) BOOST_AUTO_TEST_CASE(test_parse_literal_inline_string) { typedef toml::parse_literal_inline_string parser; - typedef toml::is_literal_inline_string acceptor; + typedef toml::is_literal_inline_string acceptor; { const std::string source("'C:\\Users\\nodejs\\templates'"); const std::string expected("C:\\Users\\nodejs\\templates"); @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(test_parse_literal_inline_string) BOOST_AUTO_TEST_CASE(test_parse_literal_multiline_string) { typedef toml::parse_literal_multiline_string parser; - typedef toml::is_literal_multiline_string acceptor; + typedef toml::is_literal_multiline_string acceptor; { const std::string source("'''I [dw]on't need \\d{2} apples'''"); const std::string expected("I [dw]on't need \\d{2} apples"); @@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE(test_parse_literal_multiline_string) BOOST_AUTO_TEST_CASE(test_parse_string) { typedef toml::parse_string parser; - typedef toml::is_string acceptor; + typedef toml::is_string acceptor; { const std::string source("\"string\""); const std::string expected("string"); @@ -195,7 +195,7 @@ BOOST_AUTO_TEST_CASE(test_parse_string) BOOST_AUTO_TEST_CASE(test_integer) { typedef toml::parse_integer parser; - typedef toml::is_integer acceptor; + typedef toml::is_integer acceptor; { const std::string source("42"); const toml::Integer expected(42); @@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(test_integer) BOOST_AUTO_TEST_CASE(test_float) { typedef toml::parse_float parser; - typedef toml::is_float acceptor; + typedef toml::is_float acceptor; { const std::string source("42.0"); const toml::Float expected(42.0); @@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(test_float) BOOST_AUTO_TEST_CASE(test_parse_boolean) { typedef toml::parse_boolean parser; - typedef toml::is_boolean acceptor; + typedef toml::is_boolean acceptor; { const std::string source("true"); const toml::Boolean expected(true); @@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(test_parse_boolean) BOOST_AUTO_TEST_CASE(test_parse_local_time) { typedef toml::parse_local_time parser; - typedef toml::is_local_time acceptor; + typedef toml::is_local_time acceptor; { const std::string source("12:34:56"); const toml::Datetime expected(12, 34, 56, 0, 0); @@ -371,7 +371,7 @@ BOOST_AUTO_TEST_CASE(test_parse_local_time) BOOST_AUTO_TEST_CASE(test_parse_local_date) { typedef toml::parse_local_date parser; - typedef toml::is_local_date acceptor; + typedef toml::is_local_date acceptor; { const std::string source("1979-09-27"); const toml::Datetime expected(1979, 9, 27); @@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(test_parse_local_date) BOOST_AUTO_TEST_CASE(test_parse_local_date_time) { typedef toml::parse_local_date_time parser; - typedef toml::is_local_date_time acceptor; + typedef toml::is_local_date_time acceptor; { const std::string source("1979-09-27T12:34:56"); const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0); @@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(test_parse_local_date_time) BOOST_AUTO_TEST_CASE(test_parse_offset_date_time) { typedef toml::parse_offset_date_time parser; - typedef toml::is_offset_date_time acceptor; + typedef toml::is_offset_date_time acceptor; { const std::string source("1979-09-27T12:34:56Z"); const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 0, 0); @@ -481,7 +481,7 @@ BOOST_AUTO_TEST_CASE(test_parse_offset_date_time) BOOST_AUTO_TEST_CASE(test_parse_datetime) { typedef toml::parse_datetime parser; - typedef toml::is_datetime acceptor; + typedef toml::is_datetime acceptor; { const std::string source("1979-09-27T12:34:56Z"); const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 0, 0); @@ -525,8 +525,8 @@ BOOST_AUTO_TEST_CASE(test_parse_datetime) BOOST_AUTO_TEST_CASE(test_parse_array) { - typedef toml::parse_array parser; - typedef toml::is_array acceptor; + typedef toml::parse_array parser; + typedef toml::is_array acceptor; { const std::string source("[1,2,3]"); const toml::Array expected{1, 2, 3}; @@ -630,8 +630,8 @@ BOOST_AUTO_TEST_CASE(test_parse_array) BOOST_AUTO_TEST_CASE(test_parse_inline_table) { - typedef toml::parse_inline_table parser; - typedef toml::is_inline_table acceptor; + typedef toml::parse_inline_table parser; + typedef toml::is_inline_table acceptor; { const std::string source("{foo=1,bar=2.0,baz='str'}"); const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}}; @@ -679,7 +679,7 @@ BOOST_AUTO_TEST_CASE(test_parse_inline_table) BOOST_AUTO_TEST_CASE(test_parse_barekey) { typedef toml::parse_barekey parser; - typedef toml::is_barekey acceptor; + typedef toml::is_barekey acceptor; { const std::string source("hoge"); const toml::key expected("hoge"); diff --git a/toml/acceptor.hpp b/toml/acceptor.hpp index db0c2be..11844ea 100644 --- a/toml/acceptor.hpp +++ b/toml/acceptor.hpp @@ -9,7 +9,7 @@ namespace toml { template -struct is_charactor +struct is_character { typedef charT value_type; constexpr static value_type target = c; @@ -240,9 +240,9 @@ struct is_not_but }; template -using is_space = is_charactor; +using is_space = is_character; template -using is_tab = is_charactor; +using is_tab = is_character; template using is_number = is_in_range; template @@ -261,17 +261,17 @@ using is_any_num_of_ws = is_ignorable, repeat_infinite()>>; template -using is_newline = is_one_of, - is_chain_of, is_charactor>>; +using is_newline = is_one_of, + is_chain_of, is_character>>; template using is_barekey_component = is_one_of, is_number, - is_charactor, is_charactor>; + is_character, is_character>; template using is_barekey = is_repeat_of, repeat_infinite()>; template using is_comment = is_chain_of< - is_charactor, + is_character, is_repeat_of>, repeat_infinite()>, is_newline >; @@ -279,73 +279,73 @@ using is_comment = template using is_basic_inline_string_component = is_one_of< - is_none_of< is_in_range, is_charactor, - is_charactor, is_newline>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor, + is_none_of< is_in_range, is_character, + is_character, is_newline>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character, is_repeat_of, 4>>, - is_chain_of, is_charactor, + is_chain_of, is_character, is_repeat_of, 8>> >; template using is_basic_inline_string = is_not_but< - is_repeat_of, 3>, // not multiline + is_repeat_of, 3>, // not multiline is_chain_of< - is_charactor, + is_character, is_ignorable, repeat_infinite()>>, - is_charactor + is_character > >; template using is_basic_multiline_string_component = is_one_of< is_none_of< is_in_range, - is_repeat_of, 3>, - is_charactor>, + is_repeat_of, 3>, + is_character>, is_newline, - is_chain_of, is_newline>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor>, - is_chain_of, is_charactor, + is_chain_of, is_newline>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character>, + is_chain_of, is_character, is_repeat_of, 4>>, - is_chain_of, is_charactor, + is_chain_of, is_character, is_repeat_of, 8>> >; template using is_basic_multiline_string = is_chain_of< - is_repeat_of, 3>, + is_repeat_of, 3>, is_ignorable, repeat_infinite()>>, - is_repeat_of, 3> + is_repeat_of, 3> >; template using is_literal_inline_string_component = - is_none_of, is_charactor>; + is_none_of, is_character>; template using is_literal_inline_string = is_not_but< - is_repeat_of, 3>, + is_repeat_of, 3>, is_chain_of< - is_charactor, + is_character, is_ignorable, repeat_infinite()>>, - is_charactor + is_character > >; @@ -353,17 +353,17 @@ template using is_literal_multiline_string_component = is_one_of< is_none_of, - is_repeat_of, 3>>, + is_repeat_of, 3>>, is_newline >; template using is_literal_multiline_string = is_chain_of< - is_repeat_of, 3>, + is_repeat_of, 3>, is_ignorable, repeat_infinite()>>, - is_repeat_of, 3> + is_repeat_of, 3> >; template @@ -377,16 +377,16 @@ using is_string = template -using is_sign = is_one_of, is_charactor>; +using is_sign = is_one_of, is_character>; template using is_nonzero_number = is_in_range; template using is_integer_component = is_not_but< - is_repeat_of, 2>, + is_repeat_of, 2>, is_one_of< - is_charactor, is_number + is_character, is_number > >; template @@ -394,7 +394,7 @@ using is_integer = is_chain_of< is_ignorable>, is_one_of< - is_charactor, + is_character, is_chain_of< is_nonzero_number, is_ignorable, @@ -407,13 +407,13 @@ using is_integer = template using is_fractional_part = is_chain_of< - is_charactor, + is_character, is_repeat_of, repeat_infinite()> >; template using is_exponent_part = is_chain_of< - is_one_of, is_charactor>, + is_one_of, is_character>, is_integer >; template @@ -438,17 +438,17 @@ template using is_boolean = is_one_of< is_chain_of< - is_charactor, - is_charactor, - is_charactor, - is_charactor + is_character, + is_character, + is_character, + is_character >, is_chain_of< - is_charactor, - is_charactor, - is_charactor, - is_charactor, - is_charactor + is_character, + is_character, + is_character, + is_character, + is_character > >; @@ -456,13 +456,13 @@ template using is_local_time = is_chain_of< is_repeat_of, 2>, - is_charactor, + is_character, is_repeat_of, 2>, - is_charactor, + is_character, is_repeat_of, 2>, is_ignorable< is_chain_of< - is_charactor, + is_character, is_repeat_of, repeat_infinite()> > > @@ -472,9 +472,9 @@ template using is_local_date = is_chain_of< is_repeat_of, 4>, - is_charactor, + is_character, is_repeat_of, 2>, - is_charactor, + is_character, is_repeat_of, 2> >; @@ -482,18 +482,18 @@ template using is_local_date_time = is_chain_of< is_local_date, - is_charactor, + is_character, is_local_time >; template using is_offset = is_one_of< - is_charactor, + is_character, is_chain_of< is_sign, is_repeat_of, 2>, - is_charactor, + is_character, is_repeat_of, 2> > >; @@ -551,14 +551,14 @@ using is_key = template using is_fixed_type_array = is_chain_of< - is_charactor, + is_character, is_ignorable< is_repeat_of< is_chain_of< is_ignorable>, is_array_component, is_ignorable>, - is_charactor + is_character >, repeat_infinite() > @@ -568,11 +568,11 @@ using is_fixed_type_array = is_ignorable>, is_array_component, is_ignorable>, - is_ignorable> + is_ignorable> > >, is_ignorable>, - is_charactor + is_character >; template @@ -614,21 +614,21 @@ struct is_inline_table is_any_num_of_ws, is_key, is_any_num_of_ws, - is_charactor, is_any_num_of_ws, is_component, is_any_num_of_ws > is_inline_key_value_pair; typedef is_chain_of< - is_charactor, + is_character, is_ignorable< is_repeat_of< is_chain_of< is_any_num_of_ws, is_inline_key_value_pair, is_any_num_of_ws, - is_charactor + is_character >, repeat_infinite() > @@ -638,11 +638,11 @@ struct is_inline_table is_any_num_of_ws, is_inline_key_value_pair, is_any_num_of_ws, - is_ignorable> + is_ignorable> > >, is_any_num_of_ws, - is_charactor + is_character > entity; return entity::invoke(iter, end); } @@ -657,42 +657,42 @@ template using is_table_definition = is_chain_of< is_any_num_of_ws, - is_charactor, + is_character, is_any_num_of_ws, is_key, is_ignorable< is_repeat_of< is_chain_of< is_any_num_of_ws, - is_charactor, + is_character, is_any_num_of_ws, is_key, is_any_num_of_ws >, repeat_infinite()> >, - is_charactor + is_character >; template using is_array_of_table_definition = is_chain_of< is_any_num_of_ws, - is_repeat_of, 2>, + is_repeat_of, 2>, is_any_num_of_ws, is_key, is_ignorable< is_repeat_of< is_chain_of< is_any_num_of_ws, - is_charactor, + is_character, is_any_num_of_ws, is_key, is_any_num_of_ws >, repeat_infinite()> >, - is_repeat_of, 2> + is_repeat_of, 2> >; template @@ -701,7 +701,7 @@ using is_key_value_pair = is_any_num_of_ws, is_key, is_any_num_of_ws, - is_charactor, is_any_num_of_ws, is_value, is_any_num_of_ws diff --git a/toml/format.hpp b/toml/format.hpp index b3ab6ce..c4726dc 100644 --- a/toml/format.hpp +++ b/toml/format.hpp @@ -2,8 +2,8 @@ #define TOML11_FORMAT #include "value.hpp" #include -#include #include +#include #include #include @@ -16,24 +16,24 @@ namespace toml // std::cout << toml::make_inline(80) << value; // std::cout << toml::forceinline << value; -template, - typename alloc = std::allocator> -std::basic_string +template, + typename alloc = std::allocator> +std::basic_string format(const value& v); -template, - typename alloc = std::allocator> -std::basic_string +template, + typename alloc = std::allocator> +std::basic_string format(const value& v, std::size_t mk); -template, - typename alloc = std::allocator> -std::basic_string +template, + typename alloc = std::allocator> +std::basic_string format(const toml::key& k, const value& v); -template, - typename alloc = std::allocator> -std::basic_string +template, + typename alloc = std::allocator> +std::basic_string format(const toml::key& k, const value& v, std::size_t mk); template @@ -43,7 +43,7 @@ template<> struct format_impl { typedef detail::toml_default_type::type type; - std::basic_string + std::basic_string operator()(const type& val) { return val ? "true" : "false"; @@ -54,7 +54,7 @@ template<> struct format_impl { typedef detail::toml_default_type::type type; - std::basic_string + std::basic_string operator()(const type& val) { return std::to_string(val); @@ -65,10 +65,10 @@ template<> struct format_impl { typedef detail::toml_default_type::type type; - std::basic_string + std::basic_string operator()(const type& val) { - std::basic_ostringstream oss; + std::basic_ostringstream oss; oss << std::showpoint << val; if(oss.str().back() == '.') oss << '0'; return oss.str(); @@ -84,7 +84,7 @@ template<> struct format_impl format_impl() : max_length(80){} format_impl(std::size_t mx) : max_length(mx){} - std::basic_string + std::basic_string operator()(const type& val) { auto tmp = make_inline(val); @@ -95,10 +95,10 @@ template<> struct format_impl private: - std::basic_string - make_inline(std::basic_string&& val) + std::basic_string + make_inline(const std::basic_string& val) { - std::basic_string str; + std::basic_string str; str += '"'; for(const auto& c : val) { @@ -114,11 +114,11 @@ template<> struct format_impl default: { str += 'u'; - std::basic_ostringstream oss; + std::basic_ostringstream oss; oss << std::setw(4) << std::setfill('0') << std::hex << static_cast(c); auto hexdig = oss.str(); - std::transform(hexdig.begin(), hexdig.end(), std::toupper); + std::transform(hexdig.begin(), hexdig.end(), hexdig.begin(), ::toupper); str += oss.str(); break; } @@ -141,10 +141,10 @@ template<> struct format_impl return str; } - std::basic_string - convert_multiline(std::basic_string&& val) + std::basic_string + convert_multiline(std::basic_string&& val) { - std::basic_string str; str.reserve(val.size() + 6); + std::basic_string str; str.reserve(val.size() + 6); str += "\"\"\"\n"; std::size_t current = 0; for(auto iter = val.begin()+1; iter != val.end()-1; ++iter) @@ -178,10 +178,10 @@ template<> struct format_impl { typedef detail::toml_default_type::type type; - std::basic_string + std::basic_string operator()(const type& val) { - std::basic_ostringstream oss; + std::basic_ostringstream oss; oss << val; return oss.str(); } @@ -194,12 +194,15 @@ template<> struct format_impl std::size_t max_length; - std::basic_string + format_impl() : max_length(80){} + format_impl(std::size_t mx) : max_length(mx){} + + std::basic_string operator()(const type& val) { - std::basic_string retval; + std::basic_string retval; retval += '['; - for(const auto&& item : val) + for(const auto& item : val) { auto tmp = format(val, max_length - 1); retval += tmp; @@ -207,7 +210,7 @@ template<> struct format_impl if(tmp.size() * 2 > max_length) retval += '\n'; } retval += ']'; - return ; + return retval; } }; @@ -216,23 +219,28 @@ template<> struct format_impl { typedef detail::toml_default_type::type type; - std::basic_string + std::size_t max_length; + + format_impl() : max_length(80){} + format_impl(std::size_t mx) : max_length(mx){} + + std::basic_string operator()(const type& val) { - std::basic_string retval; - for(const auto&& item : val) + std::basic_string retval; + for(const auto& item : val) { - retval += val.first; - retval += " = " - retval += format(val.second); + retval += item.first; + retval += " = "; + retval += format(item.second); retval += '\n'; } - return ; + return retval; } }; template -std::basic_string +std::basic_string format(const value& v) { switch(v.type()) @@ -244,23 +252,52 @@ format(const value& v) case value_t::Datetime: return format_impl{}(v.template cast()); case value_t::Array : return format_impl{}(v.template cast()); case value_t::Table : return format_impl{}(v.template cast()); - case value_t::Empty : return format_impl{}(v.template cast()); - case value_t::Unknown : return format_impl{}(v.template cast()); - default throw std::logic_error("toml::format: unknown enum value"); + case value_t::Empty : throw std::runtime_error("toml::format: empty value"); + case value_t::Unknown : throw std::runtime_error("toml::format: unknown value"); + default: throw std::logic_error("toml::format: unknown enum value"); } } template -std::basic_string -format(std::basic_string&& key, const value& val) +std::basic_string +format(const value& v, std::size_t inl) { - std::basic_string retval( - std::forward>(key)); + switch(v.type()) + { + case value_t::Boolean : return format_impl{}(v.template cast()); + case value_t::Integer : return format_impl{}(v.template cast()); + case value_t::Float : return format_impl{}(v.template cast()); + case value_t::String : return format_impl{inl}(v.template cast()); + case value_t::Datetime: return format_impl{}(v.template cast()); + case value_t::Array : return format_impl{inl}(v.template cast()); + case value_t::Table : return format_impl{inl}(v.template cast()); + case value_t::Empty : throw std::runtime_error("toml::format: empty value"); + case value_t::Unknown : throw std::runtime_error("toml::format: unknown value"); + default: throw std::logic_error("toml::format: unknown enum value"); + } +} + +template +std::basic_string +format(std::basic_string key, const value& val) +{ + std::basic_string retval(std::move(key)); retval += " = "; retval += format(val); return retval; } +template +std::basic_string +format(std::basic_string key, const value& val, std::size_t mk) +{ + std::basic_string retval(std::move(key)); + retval += " = "; + retval += format(val, mk); + return retval; +} + + // ----------------------------- stream operators ----------------------------- namespace detail @@ -274,7 +311,7 @@ struct inline_limit T limit; inline_limit() = default; ~inline_limit() = default; - constexpr make_inline(T i): limit(i){} + constexpr inline_limit(T i): limit(i){} constexpr operator T() const {return limit;} static void callback(std::ios_base::event ev, std::ios_base& ios, int idx) @@ -305,9 +342,9 @@ const int inline_limit::index = std::ios_base::xalloc(); } //detail -template> -std::basic_ostream& -operator<<(std::basic_ostream& os, +template> +std::basic_ostream& +operator<<(std::basic_ostream& os, const detail::inline_limit& inl) { void*& info = os.pword(detail::inline_limit::index); @@ -327,21 +364,21 @@ operator<<(std::basic_ostream& os, return os; } -constexpr static detail::inline_limit forceinline = - detail::inline_limit(std::numeric_limits::max()); +constexpr static detail::inline_limit forceinline( + std::numeric_limits::max()); inline detail::inline_limit make_inline(std::size_t sz) { return detail::inline_limit(sz); } -template -std::basic_ostream& -operator<<(std::basic_ostream& os, +template> +std::basic_ostream& +operator<<(std::basic_ostream& os, const toml::value& v) { std::size_t* info = - static_cast(os.pword(inline_limit::index)); + static_cast(os.pword(detail::inline_limit::index)); return os << (info == nullptr ? toml::format(v) : toml::format(v, *info)); } diff --git a/toml/parser.hpp b/toml/parser.hpp index 6e4fb48..27a6a99 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -56,7 +56,7 @@ struct result struct parse_escape_sequence { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef toml::String string_type; typedef detail::result result_type; @@ -105,36 +105,36 @@ struct parse_escape_sequence static string_type utf8_to_char(const unsigned int codepoint) { - string_type charactor; + string_type character; if(codepoint < 0x80) { - charactor += static_cast(codepoint); + character += static_cast(codepoint); } else if(codepoint < 0x800) { - charactor += static_cast(0xC0| codepoint >> 6); - charactor += static_cast(0x80|(codepoint & 0x3F)); + character += static_cast(0xC0| codepoint >> 6); + character += static_cast(0x80|(codepoint & 0x3F)); } else if(codepoint < 0x10000) { - charactor += static_cast(0xE0| codepoint >>12); - charactor += static_cast(0x80|(codepoint >>6&0x3F)); - charactor += static_cast(0x80|(codepoint & 0x3F)); + character += static_cast(0xE0| codepoint >>12); + character += static_cast(0x80|(codepoint >>6&0x3F)); + character += static_cast(0x80|(codepoint & 0x3F)); } else { - charactor += static_cast(0xF0| codepoint >>18); - charactor += static_cast(0x80|(codepoint >>12&0x3F)); - charactor += static_cast(0x80|(codepoint >>6 &0x3F)); - charactor += static_cast(0x80|(codepoint & 0x3F)); + character += static_cast(0xF0| codepoint >>18); + character += static_cast(0x80|(codepoint >>12&0x3F)); + character += static_cast(0x80|(codepoint >>6 &0x3F)); + character += static_cast(0x80|(codepoint & 0x3F)); } - return charactor; + return character; } }; struct parse_basic_inline_string { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result result_type; template result_type; - typedef is_chain_of, is_newline> + typedef is_chain_of, is_newline> is_line_ending_backslash; typedef is_repeat_of, is_newline>, repeat_infinite()> ws_nl_after_backslash_remover; @@ -228,7 +228,7 @@ struct parse_basic_multiline_string struct parse_literal_inline_string { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result result_type; template result_type; - typedef is_chain_of, is_newline> + typedef is_chain_of, is_newline> is_line_ending_backslash; typedef is_repeat_of, is_newline>, repeat_infinite()> ws_nl_after_backslash_remover; @@ -292,7 +292,7 @@ struct parse_literal_multiline_string struct parse_string { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result result_type; template string_type; typedef detail::result result_type; @@ -337,7 +337,7 @@ struct parse_integer struct parse_float { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef std::basic_string string_type; typedef detail::result result_type; @@ -366,7 +366,7 @@ struct parse_float struct parse_boolean { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result result_type; template string_type; typedef detail::result result_type; typedef typename toml::Datetime::number_type number_type; template - using nums = is_repeat_of, N>; - typedef is_charactor delim; - typedef is_charactor fract; + using nums = is_repeat_of, N>; + typedef is_character delim; + typedef is_character fract; template::value_type, @@ -445,12 +445,12 @@ struct parse_local_time struct parse_local_date { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef std::basic_string string_type; typedef detail::result result_type; template using nums = is_repeat_of, N>; - typedef is_charactor delim; + typedef is_character delim; template::value_type, @@ -481,12 +481,12 @@ struct parse_local_date struct parse_local_date_time { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef std::basic_string string_type; typedef detail::result result_type; template - using nums = is_repeat_of, N>; - typedef is_charactor delim; + using nums = is_repeat_of, N>; + typedef is_character delim; template::value_type, @@ -517,12 +517,12 @@ struct parse_local_date_time struct parse_offset_date_time { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef std::basic_string string_type; typedef detail::result result_type; template - using nums = is_repeat_of, N>; - typedef is_charactor delim; + using nums = is_repeat_of, N>; + typedef is_character delim; template::value_type, @@ -561,7 +561,7 @@ struct parse_offset_date_time struct parse_datetime { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result result_type; template struct parse_fixed_type_array { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result result_type; typedef acceptorT acceptor_type; typedef parserT parser_type; @@ -614,7 +614,7 @@ struct parse_fixed_type_array result.emplace_back(next.first.move()); iter = tmp; iter = skippable::invoke(iter, last); - iter = is_charactor::invoke(iter, last); + iter = is_character::invoke(iter, last); iter = skippable::invoke(iter, last); } return std::make_pair(result, end); @@ -628,7 +628,7 @@ template struct parse_array { typedef charT value_type; - static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); typedef detail::result result_type; typedef is_skippable_in_array skippable; @@ -669,7 +669,7 @@ template struct parse_value { typedef charT value_type; - static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); typedef detail::result result_type; template result_type; template result_type; template struct parse_key_value_pair { typedef charT value_type; - static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); typedef detail::result> result_type; template::invoke(std::next(iter), range_end); - auto tmp_value = parse_value::invoke(iter, range_end); + auto tmp_value = parse_value::invoke(iter, range_end); if(!tmp_value.first.ok()) throw syntax_error("invalid key value pair"); @@ -771,7 +771,7 @@ template struct parse_inline_table { typedef charT value_type; - static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); typedef detail::result result_type; template::invoke(iter, last); - iter = is_charactor::invoke(iter, last); + iter = is_character::invoke(iter, last); iter = is_any_num_of_ws::invoke(iter, last); } return std::make_pair(result, end); @@ -805,7 +805,7 @@ struct parse_inline_table struct parse_table_definition { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result> result_type; template::invoke(iter, last); + iter = is_character::invoke(iter, last); iter = is_any_num_of_ws::invoke(iter, last); tmp = parse_key::invoke(iter, last); @@ -846,7 +846,7 @@ struct parse_table_definition struct parse_array_of_table_definition { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef detail::result> result_type; template::invoke(iter, last); + iter = is_character::invoke(iter, last); iter = is_any_num_of_ws::invoke(iter, last); tmp = parse_key::invoke(iter, last); @@ -890,7 +890,7 @@ struct parse_array_of_table_definition struct parse_data { - typedef toml::charactor value_type; + typedef toml::character value_type; typedef toml::Table result_type; template> -toml::Table parse(std::basic_istream& is) +template> +toml::Table parse(std::basic_istream& is) { const auto initial = is.tellg(); is.seekg(0, std::ios::end); const auto eofpos = is.tellg(); const std::size_t size = eofpos - initial; is.seekg(initial); - std::vector contents(size); + std::vector contents(size); is.read(contents.data(), size); return parse_data::invoke(contents.cbegin(), contents.cend()); } diff --git a/toml/value.hpp b/toml/value.hpp index ac534a8..3cd307a 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -13,15 +13,15 @@ namespace toml { -using charactor = char; +using character = char; class value; -using key = std::basic_string; +using key = std::basic_string; using Boolean = bool; using Integer = std::int64_t; using Float = double; -using String = std::basic_string; +using String = std::basic_string; using Datetime = basic_datetime; using Array = std::vector; using Table = std::unordered_map; @@ -39,7 +39,7 @@ enum class value_t : std::uint8_t Unknown = 255, }; -template> +template> inline std::basic_ostream& operator<<(std::basic_ostream& os, value_t t) { @@ -58,7 +58,7 @@ operator<<(std::basic_ostream& os, value_t t) } } -template, +template, typename alloc = std::allocator> inline std::basic_string stringize(value_t t)