Skip to content

Commit

Permalink
Override more methods in agi::fs::path
Browse files Browse the repository at this point in the history
operator<< is used in logging, among other places, and generic_string()
needs to be forced to use UTF-8 just like string()

Fixes #261.
  • Loading branch information
arch1t3cht committed Jan 2, 2025
1 parent 45af6c5 commit a09565a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libaegisub/include/libaegisub/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class path : public std::filesystem::path {
return std::string(reinterpret_cast<const char *>(result.c_str()), result.size());
}

inline std::string generic_string() const {
const auto result = std::filesystem::path::generic_u8string();
return std::string(reinterpret_cast<const char *>(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.

Expand All @@ -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 <typename C, typename T>
inline friend std::basic_ostream<C, T>& operator<<(std::basic_ostream<C, T> &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()); \
Expand Down

0 comments on commit a09565a

Please sign in to comment.