experimentally use wchar and wstring in parser.hpp

This commit is contained in:
ToruNiina 2017-05-17 13:04:36 +09:00
parent 1265952b97
commit 5ffc51a99d

View File

@ -1057,6 +1057,34 @@ 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);
return parse_data::invoke(contents.cbegin(), contents.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)
{
@ -1076,6 +1104,7 @@ toml::Table parse(const std::string& filename)
if(!ifs.good()) throw std::runtime_error("file open error: " + filename);
return parse(ifs);
}
#endif
}// toml