Skip to content

Commit

Permalink
refactor: Remove pre-C++20 fs code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarcoFalke committed Dec 11, 2023
1 parent fa00098 commit fa3d930
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/util/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ class path : public std::filesystem::path

std::string u8string() const
{
const auto& utf8_str{std::filesystem::path::u8string()};
// utf8_str might either be std::string (C++17) or std::u8string
// (C++20). Convert both to std::string. This method can be removed
// after switching to C++20.
const std::u8string& utf8_str{std::filesystem::path::u8string()};
// Convert to std::string as a convenience for use in RPC code.
return std::string{utf8_str.begin(), utf8_str.end()};
}

Expand All @@ -71,11 +69,7 @@ class path : public std::filesystem::path

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()});
#endif
}

// Disallow implicit std::string conversion for absolute to avoid
Expand Down

0 comments on commit fa3d930

Please sign in to comment.