From c7a8fc91c07dd077fa0659550de96f0a68743ea2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 4 Jul 2022 14:52:41 +0200 Subject: [PATCH] storage/curl: use std::string_view instead of StringView --- src/storage/plugins/CurlStorage.cxx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index a518b99cf..d4e4f1328 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -40,7 +40,7 @@ #include "util/SpanCast.hxx" #include "util/StringCompare.hxx" #include "util/StringFormat.hxx" -#include "util/StringView.hxx" +#include "util/StringSplit.hxx" #include "util/UriExtract.hxx" #include @@ -510,28 +510,28 @@ private: * to the base file name. */ gcc_pure - StringView HrefToEscapedName(const char *href) const noexcept { - StringView path = uri_get_path(href); - if (path == nullptr) - return nullptr; + std::string_view HrefToEscapedName(const char *href) const noexcept { + std::string_view path = uri_get_path(href); + if (path.data() == nullptr) + return {}; /* kludge: ignoring case in this comparison to avoid false negatives if the web server uses a different case */ path = StringAfterPrefixIgnoreCase(path, base_path.c_str()); - if (path == nullptr || path.empty()) - return nullptr; + if (path.empty()) + return {}; - const char *slash = path.Find('/'); - if (slash == nullptr) + const auto slash = path.find('/'); + if (slash == path.npos) /* regular file */ return path; - else if (slash == &path.back()) + else if (slash + 1 == path.size()) /* trailing slash: collection; strip the slash */ - return {path.data, slash}; + return path.substr(0, slash); else /* strange, better ignore it */ - return nullptr; + return {}; } protected: @@ -542,10 +542,10 @@ protected: std::string href = CurlUnescape(GetEasy(), r.href.c_str()); const auto name = HrefToEscapedName(href.c_str()); - if (name.IsNull()) + if (name.data() == nullptr) return; - entries.emplace_front(std::string(name.data, name.size)); + entries.emplace_front(name); auto &info = entries.front().info; info = StorageFileInfo(r.collection