Commit 2429cc87 authored by Max Kellermann's avatar Max Kellermann

fs/Traits: convert first Relative() parameter to std::string_view

parent 3a83a6b5
...@@ -86,10 +86,9 @@ GetParentPathImpl(typename Traits::const_pointer p) noexcept ...@@ -86,10 +86,9 @@ GetParentPathImpl(typename Traits::const_pointer p) noexcept
template<typename Traits> template<typename Traits>
typename Traits::const_pointer typename Traits::const_pointer
RelativePathImpl(typename Traits::const_pointer base, RelativePathImpl(typename Traits::string_view base,
typename Traits::const_pointer other) noexcept typename Traits::const_pointer other) noexcept
{ {
assert(base != nullptr);
assert(other != nullptr); assert(other != nullptr);
other = StringAfterPrefix(other, base); other = StringAfterPrefix(other, base);
...@@ -99,7 +98,7 @@ RelativePathImpl(typename Traits::const_pointer base, ...@@ -99,7 +98,7 @@ RelativePathImpl(typename Traits::const_pointer base,
if (*other != 0) { if (*other != 0) {
if (!Traits::IsSeparator(*other)) { if (!Traits::IsSeparator(*other)) {
if (*base != 0 && Traits::IsSeparator(other[-1])) if (!base.empty() && Traits::IsSeparator(other[-1]))
/* "other" has no more slash, but the /* "other" has no more slash, but the
matching base ended with a slash: matching base ended with a slash:
enough to detect a match */ enough to detect a match */
...@@ -137,7 +136,7 @@ PathTraitsFS::GetParent(PathTraitsFS::const_pointer p) noexcept ...@@ -137,7 +136,7 @@ PathTraitsFS::GetParent(PathTraitsFS::const_pointer p) noexcept
} }
PathTraitsFS::const_pointer PathTraitsFS::const_pointer
PathTraitsFS::Relative(const_pointer base, const_pointer other) noexcept PathTraitsFS::Relative(string_view base, const_pointer other) noexcept
{ {
return RelativePathImpl<PathTraitsFS>(base, other); return RelativePathImpl<PathTraitsFS>(base, other);
} }
...@@ -175,8 +174,7 @@ PathTraitsUTF8::GetParent(const_pointer p) noexcept ...@@ -175,8 +174,7 @@ PathTraitsUTF8::GetParent(const_pointer p) noexcept
} }
PathTraitsUTF8::const_pointer PathTraitsUTF8::const_pointer
PathTraitsUTF8::Relative(const_pointer base, PathTraitsUTF8::Relative(string_view base, const_pointer other) noexcept
const_pointer other) noexcept
{ {
return RelativePathImpl<PathTraitsUTF8>(base, other); return RelativePathImpl<PathTraitsUTF8>(base, other);
} }
...@@ -147,8 +147,7 @@ struct PathTraitsFS { ...@@ -147,8 +147,7 @@ struct PathTraitsFS {
* nullptr on mismatch. * nullptr on mismatch.
*/ */
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
static const_pointer Relative(const_pointer base, static const_pointer Relative(string_view base, const_pointer other) noexcept;
const_pointer other) noexcept;
/** /**
* Constructs the path from the given components. * Constructs the path from the given components.
...@@ -256,8 +255,7 @@ struct PathTraitsUTF8 { ...@@ -256,8 +255,7 @@ struct PathTraitsUTF8 {
* nullptr on mismatch. * nullptr on mismatch.
*/ */
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
static const_pointer Relative(const_pointer base, static const_pointer Relative(string_view base, const_pointer other) noexcept;
const_pointer other) noexcept;
/** /**
* Constructs the path from the given components. * Constructs the path from the given components.
......
...@@ -81,7 +81,7 @@ CurlStorage::MapUTF8(const char *uri_utf8) const noexcept ...@@ -81,7 +81,7 @@ CurlStorage::MapUTF8(const char *uri_utf8) const noexcept
const char * const char *
CurlStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept CurlStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base.c_str(), return PathTraitsUTF8::Relative(base,
CurlUnescape(uri_utf8).c_str()); CurlUnescape(uri_utf8).c_str());
} }
......
...@@ -129,7 +129,7 @@ LocalStorage::MapFS(const char *uri_utf8) const noexcept ...@@ -129,7 +129,7 @@ LocalStorage::MapFS(const char *uri_utf8) const noexcept
const char * const char *
LocalStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept LocalStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base_utf8.c_str(), uri_utf8); return PathTraitsUTF8::Relative(base_utf8, uri_utf8);
} }
StorageFileInfo StorageFileInfo
......
...@@ -246,7 +246,7 @@ NfsStorage::MapUTF8(const char *uri_utf8) const noexcept ...@@ -246,7 +246,7 @@ NfsStorage::MapUTF8(const char *uri_utf8) const noexcept
const char * const char *
NfsStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept NfsStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base.c_str(), uri_utf8); return PathTraitsUTF8::Relative(base, uri_utf8);
} }
static void static void
......
...@@ -87,7 +87,7 @@ SmbclientStorage::MapUTF8(const char *uri_utf8) const noexcept ...@@ -87,7 +87,7 @@ SmbclientStorage::MapUTF8(const char *uri_utf8) const noexcept
const char * const char *
SmbclientStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept SmbclientStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base.c_str(), uri_utf8); return PathTraitsUTF8::Relative(base, uri_utf8);
} }
static StorageFileInfo static StorageFileInfo
......
...@@ -347,7 +347,7 @@ UdisksStorage::MapUTF8(const char *uri_utf8) const noexcept ...@@ -347,7 +347,7 @@ UdisksStorage::MapUTF8(const char *uri_utf8) const noexcept
const char * const char *
UdisksStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept UdisksStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base_uri.c_str(), uri_utf8); return PathTraitsUTF8::Relative(base_uri, uri_utf8);
} }
static std::unique_ptr<Storage> static std::unique_ptr<Storage>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment