storage/curl: use std::string_view instead of StringView

This commit is contained in:
Max Kellermann 2022-07-04 14:52:41 +02:00
parent cfd255a014
commit c7a8fc91c0
1 changed files with 14 additions and 14 deletions

View File

@ -40,7 +40,7 @@
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/StringFormat.hxx" #include "util/StringFormat.hxx"
#include "util/StringView.hxx" #include "util/StringSplit.hxx"
#include "util/UriExtract.hxx" #include "util/UriExtract.hxx"
#include <cassert> #include <cassert>
@ -510,28 +510,28 @@ private:
* to the base file name. * to the base file name.
*/ */
gcc_pure gcc_pure
StringView HrefToEscapedName(const char *href) const noexcept { std::string_view HrefToEscapedName(const char *href) const noexcept {
StringView path = uri_get_path(href); std::string_view path = uri_get_path(href);
if (path == nullptr) if (path.data() == nullptr)
return nullptr; return {};
/* kludge: ignoring case in this comparison to avoid /* kludge: ignoring case in this comparison to avoid
false negatives if the web server uses a different false negatives if the web server uses a different
case */ case */
path = StringAfterPrefixIgnoreCase(path, base_path.c_str()); path = StringAfterPrefixIgnoreCase(path, base_path.c_str());
if (path == nullptr || path.empty()) if (path.empty())
return nullptr; return {};
const char *slash = path.Find('/'); const auto slash = path.find('/');
if (slash == nullptr) if (slash == path.npos)
/* regular file */ /* regular file */
return path; return path;
else if (slash == &path.back()) else if (slash + 1 == path.size())
/* trailing slash: collection; strip the slash */ /* trailing slash: collection; strip the slash */
return {path.data, slash}; return path.substr(0, slash);
else else
/* strange, better ignore it */ /* strange, better ignore it */
return nullptr; return {};
} }
protected: protected:
@ -542,10 +542,10 @@ protected:
std::string href = CurlUnescape(GetEasy(), r.href.c_str()); std::string href = CurlUnescape(GetEasy(), r.href.c_str());
const auto name = HrefToEscapedName(href.c_str()); const auto name = HrefToEscapedName(href.c_str());
if (name.IsNull()) if (name.data() == nullptr)
return; return;
entries.emplace_front(std::string(name.data, name.size)); entries.emplace_front(name);
auto &info = entries.front().info; auto &info = entries.front().info;
info = StorageFileInfo(r.collection info = StorageFileInfo(r.collection