mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 09:08:08 +08:00
feat: add std::filesystem::path support
This commit is contained in:
@@ -12,6 +12,13 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#if __has_include(<filesystem>)
|
||||||
|
#define TOML11_HAS_STD_FILESYSTEM
|
||||||
|
#include <filesystem>
|
||||||
|
#endif // has_include(<string_view>)
|
||||||
|
#endif // cplusplus >= C++17
|
||||||
|
|
||||||
namespace toml
|
namespace toml
|
||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -2094,5 +2101,21 @@ basic_value<Comment, Table, Array> parse(const std::string& fname)
|
|||||||
return parse<Comment, Table, Array>(ifs, fname);
|
return parse<Comment, Table, Array>(ifs, fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOML11_HAS_STD_FILESYSTEM
|
||||||
|
template<typename Comment = ::toml::discard_comments,
|
||||||
|
template<typename ...> class Table = std::unordered_map,
|
||||||
|
template<typename ...> class Array = std::vector>
|
||||||
|
basic_value<Comment, Table, Array> parse(const std::filesystem::path& fpath)
|
||||||
|
{
|
||||||
|
std::ifstream ifs(fpath, std::ios_base::binary);
|
||||||
|
if(!ifs.good())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("toml::parse: file open error -> " +
|
||||||
|
fpath.string());
|
||||||
|
}
|
||||||
|
return parse<Comment, Table, Array>(ifs, fname);
|
||||||
|
}
|
||||||
|
#endif // TOML11_HAS_STD_FILESYSTEM
|
||||||
|
|
||||||
} // toml
|
} // toml
|
||||||
#endif// TOML11_PARSER_HPP
|
#endif// TOML11_PARSER_HPP
|
||||||
|
Reference in New Issue
Block a user