diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2019-06-28 19:42:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-28 19:42:34 +0200 |
| commit | 58c78a495d783de3cb6928abd0c7810777decfc7 (patch) | |
| tree | d2bb4b10b0c4cc42b101d9a91e53d14c727c7bfd /Source/Core/Common/StringUtil.cpp | |
| parent | 6fd435fdffdbde75807186cb92b34ee3f2b5718b (diff) | |
| parent | c0a6fa5dcc5a1335ee9eeb940bdfc6934ed01656 (diff) | |
Merge pull request #8213 from JosJuice/filesystem-u8string
Work around C++20 std::filesystem changes related to u8string
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 0df4b595cd..275c1e2af0 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -623,3 +623,26 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size) } #endif + +#ifdef HAS_STD_FILESYSTEM +// This is a replacement for path::u8path, which is deprecated starting with C++20. +std::filesystem::path StringToPath(std::string_view path) +{ +#ifdef _MSC_VER + return std::filesystem::path(UTF8ToUTF16(std::string(path))); +#else + return std::filesystem::path(path); +#endif +} + +// This is a replacement for path::u8string that always has the return type std::string. +// path::u8string returns std::u8string starting with C++20, which is annoying to convert. +std::string PathToString(const std::filesystem::path& path) +{ +#ifdef _MSC_VER + return UTF16ToUTF8(path.native()); +#else + return path.native(); +#endif +} +#endif |
