Add unix_path() to entry_view

This commit is contained in:
Marcus Holland-Moritz 2023-06-26 21:32:33 +02:00
parent 2232796f20
commit a0f51660f5
2 changed files with 13 additions and 0 deletions

View File

@ -160,6 +160,7 @@ class dir_entry_view {
std::optional<dir_entry_view> parent() const;
std::string path() const;
std::string unix_path() const;
std::filesystem::path fs_path() const;
std::wstring wpath() const;

View File

@ -668,6 +668,18 @@ std::string dir_entry_view::path() const {
return u8string_to_string(fs_path().u8string());
}
std::string dir_entry_view::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
}
std::wstring dir_entry_view::wpath() const { return fs_path().wstring(); }
std::filesystem::path dir_entry_view::fs_path() const {