mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-01-03 06:21:08 +00:00
restore parser and test
This commit is contained in:
commit
2c92142d5c
@ -123,3 +123,33 @@ BOOST_AUTO_TEST_CASE(test_hard_example)
|
||||
BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
|
||||
expected_multi_line_array);
|
||||
}
|
||||
|
||||
// BOOST_AUTO_TEST_CASE(test_hard_example_unicode)
|
||||
// {
|
||||
// const auto data = toml::parse("toml/tests/hard_example_unicode.toml");
|
||||
//
|
||||
// const auto the = toml::get<toml::Table>(data.at("the"));
|
||||
// BOOST_CHECK_EQUAL(toml::get<std::string>(the.at("test_string")),
|
||||
// u8"Ýôú'ℓℓ λáƭè ₥è áƒƭèř ƭλïƨ - #");
|
||||
//
|
||||
// const auto hard = toml::get<toml::Table>(the.at("hard"));
|
||||
// const std::vector<std::string> expected_the_hard_test_array{"] ", " # "};
|
||||
// BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array")) ==
|
||||
// expected_the_hard_test_array);
|
||||
// const std::vector<std::string> expected_the_hard_test_array2{
|
||||
// u8"Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ", u8"Éжƥèřï₥èñƭ #9 ωáƨ á ƨúççèƨƨ"};
|
||||
// BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array2")) ==
|
||||
// expected_the_hard_test_array2);
|
||||
// BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("another_test_string")),
|
||||
// u8"§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #");
|
||||
// BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("harder_test_string")),
|
||||
// u8" Âñδ ωλèñ \"'ƨ ářè ïñ ƭλè ƨƭřïñϱ, áℓôñϱ ωïƭλ # \"");
|
||||
//
|
||||
// const auto bit = toml::get<toml::Table>(hard.at(std::string(u8"βïƭ#")));
|
||||
// BOOST_CHECK_EQUAL(toml::get<std::string>(bit.at(std::string(u8"ωλáƭ?"))),
|
||||
// u8"Ýôú δôñ'ƭ ƭλïñƙ ƨô₥è úƨèř ωôñ'ƭ δô ƭλáƭ?");
|
||||
// const std::vector<std::string> expected_multi_line_array{"]"};
|
||||
// BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
|
||||
// expected_multi_line_array);
|
||||
//
|
||||
// }
|
||||
|
@ -7,8 +7,6 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
|
||||
namespace toml
|
||||
{
|
||||
@ -1058,40 +1056,6 @@ struct parse_data
|
||||
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
template<typename traits = std::char_traits<wchar_t>>
|
||||
toml::Table parse(std::basic_istream<wchar_t, traits>& is)
|
||||
{
|
||||
const auto curloc = is.getloc();
|
||||
is.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
|
||||
|
||||
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<wchar_t> contents(size);
|
||||
is.read(contents.data(), size);
|
||||
is.imbue(curloc);
|
||||
|
||||
std::wstring wstr(size, ' ');
|
||||
std::copy(contents.cbegin(), contents.cend(), wstr.begin());
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cvter;
|
||||
std::string u8str = cvter.to_bytes(wstr);
|
||||
|
||||
return parse_data::invoke(u8str.cbegin(), u8str.cend());
|
||||
}
|
||||
|
||||
toml::Table parse(const std::string& filename)
|
||||
{
|
||||
std::wifstream ifs(filename);
|
||||
if(!ifs.good()) throw std::runtime_error("file open error: " + filename);
|
||||
return parse(ifs);
|
||||
}
|
||||
|
||||
#else
|
||||
template<typename traits = std::char_traits<toml::character>>
|
||||
toml::Table parse(std::basic_istream<toml::character, traits>& is)
|
||||
{
|
||||
@ -1111,8 +1075,6 @@ toml::Table parse(const std::string& filename)
|
||||
if(!ifs.good()) throw std::runtime_error("file open error: " + filename);
|
||||
return parse(ifs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}// toml
|
||||
#endif// TOML11_PARSER
|
||||
|
Loading…
Reference in New Issue
Block a user