Skip to content

Commit

Permalink
refactor(metadata_types): make ::unix_path() less Windows specific
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Oct 20, 2024
1 parent f664352 commit 53ac77f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/reader/internal/metadata_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,19 +990,18 @@ dir_entry_view_impl::name(uint32_t index, global_metadata const& g) {
}

std::string dir_entry_view_impl::path() const {
// paths in metadata are guaranteed to be valid UTF-8
return u8string_to_string(fs_path().u8string());
}

std::string dir_entry_view_impl::unix_path() const {
#ifdef _WIN32
auto p = fs_path().u8string();
std::replace(p.begin(), p.end(),
static_cast<char>(std::filesystem::path::preferred_separator),
'/');
return u8string_to_string(p);
#else
return path();
#endif
static constexpr char preferred =
static_cast<char>(std::filesystem::path::preferred_separator);
auto p = path();
if constexpr (preferred != '/') {
std::replace(p.begin(), p.end(), preferred, '/');
}
return p;
}

std::wstring dir_entry_view_impl::wpath() const { return fs_path().wstring(); }
Expand Down

0 comments on commit 53ac77f

Please sign in to comment.