Skip to content

Commit a09565a

Browse files
committed
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.
1 parent 45af6c5 commit a09565a

File tree

1 file changed

+14
-0
lines changed
  • libaegisub/include/libaegisub

1 file changed

+14
-0
lines changed

libaegisub/include/libaegisub/fs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class path : public std::filesystem::path {
5454
return std::string(reinterpret_cast<const char *>(result.c_str()), result.size());
5555
}
5656

57+
inline std::string generic_string() const {
58+
const auto result = std::filesystem::path::generic_u8string();
59+
return std::string(reinterpret_cast<const char *>(result.c_str()), result.size());
60+
}
61+
5762
// We do not override wstring() here: While the conversion method for this is technically unspecified here,
5863
// it seems to always return UTF-16 in practice. If this ever changes, wstring() can be overwritten or deleted here.
5964

@@ -63,6 +68,15 @@ class path : public std::filesystem::path {
6368
return path(lhs_ / rhs_);
6469
}
6570

71+
// This will only work if C is char, but for other calls we will get a compiler error, which
72+
// is what we want. If operator<< for wostreams is ever needed, the compiler will complain and
73+
// an implementation can be added.
74+
template <typename C, typename T>
75+
inline friend std::basic_ostream<C, T>& operator<<(std::basic_ostream<C, T> &ostr, path const& rhs) {
76+
ostr << std::quoted(rhs.string());
77+
return ostr;
78+
}
79+
6680
#define WRAP_SFP(name) \
6781
inline path name() const { \
6882
return path(std::filesystem::path::name()); \

0 commit comments

Comments
 (0)