diff --git a/toml/parser.hpp b/toml/parser.hpp index 45c3012..deeab7c 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -1057,6 +1057,34 @@ struct parse_data }; +#ifdef _MSC_VER + +template> +toml::Table parse(std::basic_istream& is) +{ + const auto curloc = is.getloc(); + is.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8)); + + 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); + 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> toml::Table parse(std::basic_istream& 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