Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Template for new versions:
## New Features

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

## Misc Improvements

Expand Down
13 changes: 7 additions & 6 deletions library/include/modules/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ namespace DFHack {
DFHACK_EXPORT std::filesystem::path canonicalize(std::filesystem::path p) noexcept;
inline std::string as_string(const std::filesystem::path path) noexcept
{
auto pStr = path.string();
if constexpr (std::filesystem::path::preferred_separator != '/')
{
std::ranges::replace(pStr, std::filesystem::path::preferred_separator, '/');
}
return pStr;
// this just mashes the utf-8 into a std::string without any conversion
// this is largely because we use utf-8 everywhere internally as much as we can
// but we should ultimately convert to using u8strings for strings that are utf-8
// and use a different string type for strings encoded in cp437 or in the locale codepage
std::u8string pstr = path.generic_u8string();
return std::string((char*)pstr.c_str());

}
DFHACK_EXPORT std::filesystem::path getInstallDir() noexcept;
DFHACK_EXPORT std::filesystem::path getBaseDir() noexcept;
Expand Down