From 66704ec87910a7be1cb4cd62c1ff14d6753387ca Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 4 Jul 2022 14:59:37 +0200 Subject: [PATCH] util/UriExtract: use std::string_view instead of StringView --- src/util/UriExtract.cxx | 21 +++++++++++---------- src/util/UriExtract.hxx | 9 +++------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/util/UriExtract.cxx b/src/util/UriExtract.cxx index 34717201b..27fad417e 100644 --- a/src/util/UriExtract.cxx +++ b/src/util/UriExtract.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 Max Kellermann + * Copyright 2008-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,9 +29,9 @@ #include "UriExtract.hxx" #include "CharUtil.hxx" -#include "StringView.hxx" +#include "StringSplit.hxx" -#include +#include static constexpr bool IsValidSchemeStart(char ch) @@ -121,10 +121,10 @@ uri_get_path(std::string_view uri) noexcept } [[gnu::pure]] -static StringView -UriWithoutQueryString(StringView uri) noexcept +static std::string_view +UriWithoutQueryString(std::string_view uri) noexcept { - return uri.Split('?').first; + return Split(uri, '?').first; } /* suffixes should be ascii only characters */ @@ -133,13 +133,14 @@ uri_get_suffix(std::string_view _uri) noexcept { const auto uri = UriWithoutQueryString(_uri); - const char *dot = uri.FindLast('.'); - if (dot == nullptr || dot == uri.data || - dot[-1] == '/' || dot[-1] == '\\') + const auto dot = uri.rfind('.'); + if (dot == uri.npos || dot == 0 || + uri[dot - 1] == '/' || uri[dot - 1] == '\\') return {}; auto suffix = uri.substr(dot + 1); - if (suffix.Find('/') != nullptr || suffix.Find('\\') != nullptr) + if (suffix.find('/') != suffix.npos || + suffix.find('\\') != suffix.npos) /* this was not the last path segment */ return {}; diff --git a/src/util/UriExtract.hxx b/src/util/UriExtract.hxx index 69cd7496c..6770e2989 100644 --- a/src/util/UriExtract.hxx +++ b/src/util/UriExtract.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 Max Kellermann + * Copyright 2008-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,8 +27,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef URI_EXTRACT_HXX -#define URI_EXTRACT_HXX +#pragma once #include @@ -67,10 +66,8 @@ uri_get_suffix(std::string_view uri) noexcept; * Returns the URI fragment, i.e. the portion after the '#', but * without the '#'. If there is no '#', this function returns * nullptr; if there is a '#' but no fragment text, it returns an - * empty StringView. + * empty std::string_view. */ [[gnu::pure]] [[gnu::nonnull]] const char * uri_get_fragment(const char *uri) noexcept; - -#endif