Skip to content

Commit a4714bc

Browse files
authored
Merge pull request #5697 from ab9rf/fix-5688
change `Filesystem::as_string` to always use utf-8
2 parents a0f37ee + fb0e17c commit a4714bc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Template for new versions:
5959
## New Features
6060

6161
## Fixes
62+
# ``Filesystem::as_string`` now always uses UTF-8 encoding rather than using the system locale encoding
6263

6364
## Misc Improvements
6465

library/include/modules/Filesystem.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ namespace DFHack {
7777
DFHACK_EXPORT std::filesystem::path canonicalize(std::filesystem::path p) noexcept;
7878
inline std::string as_string(const std::filesystem::path path) noexcept
7979
{
80-
auto pStr = path.string();
81-
if constexpr (std::filesystem::path::preferred_separator != '/')
82-
{
83-
std::ranges::replace(pStr, std::filesystem::path::preferred_separator, '/');
84-
}
85-
return pStr;
80+
// this just mashes the utf-8 into a std::string without any conversion
81+
// this is largely because we use utf-8 everywhere internally as much as we can
82+
// but we should ultimately convert to using u8strings for strings that are utf-8
83+
// and use a different string type for strings encoded in cp437 or in the locale codepage
84+
std::u8string pstr = path.generic_u8string();
85+
return std::string((char*)pstr.c_str());
86+
8687
}
8788
DFHACK_EXPORT std::filesystem::path getInstallDir() noexcept;
8889
DFHACK_EXPORT std::filesystem::path getBaseDir() noexcept;

0 commit comments

Comments
 (0)