diff options
Diffstat (limited to 'src/fs/Traits.cxx')
-rw-r--r-- | src/fs/Traits.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/fs/Traits.cxx b/src/fs/Traits.cxx index f3598fdc1..35d7fa1fd 100644 --- a/src/fs/Traits.cxx +++ b/src/fs/Traits.cxx @@ -85,6 +85,22 @@ GetParentPathImpl(typename Traits::const_pointer p) noexcept } template<typename Traits> +typename Traits::string_view +GetParentPathImpl(typename Traits::string_view p) noexcept +{ + auto sep = Traits::FindLastSeparator(p); + if (sep == nullptr) + return Traits::CURRENT_DIRECTORY; + if (sep == p.data()) + return p.substr(0, 1); +#ifdef _WIN32 + if (Traits::IsDrive(p) && sep == p.data() + 2) + return p.substr(0, 3); +#endif + return p.substr(0, sep - p.data()); +} + +template<typename Traits> typename Traits::const_pointer RelativePathImpl(typename Traits::string_view base, typename Traits::const_pointer other) noexcept @@ -166,6 +182,12 @@ PathTraitsFS::GetParent(PathTraitsFS::const_pointer p) noexcept return GetParentPathImpl<PathTraitsFS>(p); } +PathTraitsFS::string_view +PathTraitsFS::GetParent(string_view p) noexcept +{ + return GetParentPathImpl<PathTraitsFS>(p); +} + PathTraitsFS::const_pointer PathTraitsFS::Relative(string_view base, const_pointer other) noexcept { @@ -210,6 +232,12 @@ PathTraitsUTF8::GetParent(const_pointer p) noexcept return GetParentPathImpl<PathTraitsUTF8>(p); } +PathTraitsUTF8::string_view +PathTraitsUTF8::GetParent(string_view p) noexcept +{ + return GetParentPathImpl<PathTraitsUTF8>(p); +} + PathTraitsUTF8::const_pointer PathTraitsUTF8::Relative(string_view base, const_pointer other) noexcept { |