12 VirtualPath() =
default;
14 explicit VirtualPath(std::string_view path)
19 explicit VirtualPath(
const char* path)
20 : logical_path_(path ? path :
"")
24 VirtualPath(
const VirtualPath&) =
default;
25 VirtualPath(VirtualPath&&)
noexcept =
default;
27 VirtualPath& operator=(
const VirtualPath&) =
default;
28 VirtualPath& operator=(VirtualPath&&)
noexcept =
default;
30 ~VirtualPath() =
default;
32 [[nodiscard]]
const char* c_str()
const noexcept
34 return logical_path_.c_str();
37 [[nodiscard]]
const std::string& logical_path()
const noexcept
42 [[nodiscard]]
bool empty()
const noexcept
44 return logical_path_.empty();
47 [[nodiscard]] std::wstring to_wstring()
const
49 return std::wstring(logical_path_.begin(), logical_path_.end());
52 [[nodiscard]]
bool has_extension(std::string_view ext)
const noexcept
54 return extension() == ext;
57 [[nodiscard]] std::string_view extension()
const noexcept
59 const std::size_t last_forward_slash = logical_path_.rfind(
'/');
60 const std::size_t last_backslash = logical_path_.rfind(
'\\');
61 const std::size_t last_separator = last_forward_slash == std::string::npos ? last_backslash
62 : last_backslash == std::string::npos
64 : (last_forward_slash > last_backslash ? last_forward_slash : last_backslash);
65 const std::size_t segment_start = last_separator == std::string::npos ? 0u : last_separator + 1u;
66 const std::size_t dot_position = logical_path_.rfind(
'.');
67 if (dot_position != std::string::npos && dot_position >= segment_start)
69 return std::string_view(logical_path_).substr(dot_position);
71 return std::string_view{};
75 std::string logical_path_;