From 88a66df9d67dd156dcdf145348a5e2d1a464aa66 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 1 Jul 2022 16:47:46 +0200 Subject: [PATCH] lib/curl/Adapter: use std::string_view internally --- src/lib/curl/Adapter.cxx | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/lib/curl/Adapter.cxx b/src/lib/curl/Adapter.cxx index f3c3c8489..266c7455e 100644 --- a/src/lib/curl/Adapter.cxx +++ b/src/lib/curl/Adapter.cxx @@ -32,12 +32,14 @@ #include "Handler.hxx" #include "util/CharUtil.hxx" #include "util/RuntimeError.hxx" +#include "util/StringSplit.hxx" #include "util/StringStrip.hxx" -#include "util/StringView.hxx" #include #include +using std::string_view_literals::operator""sv; + void CurlResponseHandlerAdapter::Install(CurlEasy &easy) { @@ -109,19 +111,17 @@ CurlResponseHandlerAdapter::Done(CURLcode result) noexcept [[gnu::pure]] static bool -IsResponseBoundaryHeader(StringView s) noexcept +IsResponseBoundaryHeader(std::string_view s) noexcept { - return s.size > 5 && (s.StartsWith("HTTP/") || - /* the proprietary "ICY 200 OK" is - emitted by Shoutcast */ - s.StartsWith("ICY 2")); + return s.size() > 5 && (s.starts_with("HTTP/"sv) || + /* the proprietary "ICY 200 OK" is + emitted by Shoutcast */ + s.starts_with("ICY 2"sv)); } inline void -CurlResponseHandlerAdapter::HeaderFunction(std::string_view _s) noexcept +CurlResponseHandlerAdapter::HeaderFunction(std::string_view s) noexcept { - const StringView s{_s}; - if (state > State::HEADERS) return; @@ -132,27 +132,15 @@ CurlResponseHandlerAdapter::HeaderFunction(std::string_view _s) noexcept return; } - const char *header = s.data; - const char *end = StripRight(header, header + s.size); - - const char *value = s.Find(':'); - if (value == nullptr) + auto [_name, value] = Split(StripRight(s), ':'); + if (_name.empty() || value.data() == nullptr) return; - std::string name(header, value); + std::string name{_name}; std::transform(name.begin(), name.end(), name.begin(), static_cast(ToLowerASCII)); - /* skip the colon */ - - ++value; - - /* strip the value */ - - value = StripLeft(value, end); - end = StripRight(value, end); - - headers.emplace(std::move(name), std::string(value, end)); + headers.emplace(std::move(name), value); } std::size_t