refactor: Remove pre-C++20 fs code

Treating std::string as UTF-8 is deprecated in std::filesystem::path
since C++20.

However, it makes this codebase easier to read and maintain to retain
the ability for std::string to hold UTF-8.
pull/29040/head
MarcoFalke 11 months ago
parent fa00098e1a
commit fa3d9304e8
No known key found for this signature in database

@ -56,10 +56,8 @@ public:
std::string u8string() const std::string u8string() const
{ {
const auto& utf8_str{std::filesystem::path::u8string()}; const std::u8string& utf8_str{std::filesystem::path::u8string()};
// utf8_str might either be std::string (C++17) or std::u8string // Convert to std::string as a convenience for use in RPC code.
// (C++20). Convert both to std::string. This method can be removed
// after switching to C++20.
return std::string{utf8_str.begin(), utf8_str.end()}; return std::string{utf8_str.begin(), utf8_str.end()};
} }
@ -71,11 +69,7 @@ public:
static inline path u8path(const std::string& utf8_str) static inline path u8path(const std::string& utf8_str)
{ {
#if __cplusplus < 202002L
return std::filesystem::u8path(utf8_str);
#else
return std::filesystem::path(std::u8string{utf8_str.begin(), utf8_str.end()}); return std::filesystem::path(std::u8string{utf8_str.begin(), utf8_str.end()});
#endif
} }
// Disallow implicit std::string conversion for absolute to avoid // Disallow implicit std::string conversion for absolute to avoid

Loading…
Cancel
Save