diff --git a/libaegisub/include/libaegisub/fs.h b/libaegisub/include/libaegisub/fs.h index 718b7dce0c..be5fcc7338 100644 --- a/libaegisub/include/libaegisub/fs.h +++ b/libaegisub/include/libaegisub/fs.h @@ -54,6 +54,11 @@ class path : public std::filesystem::path { return std::string(reinterpret_cast(result.c_str()), result.size()); } + inline std::string generic_string() const { + const auto result = std::filesystem::path::generic_u8string(); + return std::string(reinterpret_cast(result.c_str()), result.size()); + } + // We do not override wstring() here: While the conversion method for this is technically unspecified here, // it seems to always return UTF-16 in practice. If this ever changes, wstring() can be overwritten or deleted here. @@ -63,6 +68,15 @@ class path : public std::filesystem::path { return path(lhs_ / rhs_); } + // This will only work if C is char, but for other calls we will get a compiler error, which + // is what we want. If operator<< for wostreams is ever needed, the compiler will complain and + // an implementation can be added. + template + inline friend std::basic_ostream& operator<<(std::basic_ostream &ostr, path const& rhs) { + ostr << std::quoted(rhs.string()); + return ostr; + } + #define WRAP_SFP(name) \ inline path name() const { \ return path(std::filesystem::path::name()); \