From a09565ae179530c919dedef8965233d4379cd5fe Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 2 Jan 2025 16:33:13 +0100 Subject: [PATCH] Override more methods in agi::fs::path operator<< is used in logging, among other places, and generic_string() needs to be forced to use UTF-8 just like string() Fixes #261. --- libaegisub/include/libaegisub/fs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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()); \