From d256d3dabe13448cc323b532a7b15175728edd22 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 31 May 2022 13:18:42 +0200 Subject: [PATCH] util/StringCompare: use std::string_view instead of StringView --- src/archive/plugins/Iso9660ArchivePlugin.cxx | 1 + src/db/update/Walk.cxx | 1 + src/fs/Traits.cxx | 1 + src/storage/plugins/CurlStorage.cxx | 1 + src/util/StringCompare.cxx | 2 +- src/util/StringCompare.hxx | 36 ++++++++++---------- src/util/UriRelative.cxx | 1 + src/util/WStringCompare.cxx | 2 +- src/util/WStringCompare.hxx | 20 +++++------ 9 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/archive/plugins/Iso9660ArchivePlugin.cxx b/src/archive/plugins/Iso9660ArchivePlugin.cxx index 336385cd6..d2fd91dbb 100644 --- a/src/archive/plugins/Iso9660ArchivePlugin.cxx +++ b/src/archive/plugins/Iso9660ArchivePlugin.cxx @@ -34,6 +34,7 @@ #include #include +#include #include #include diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index be71e7195..6813ad27c 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -34,6 +34,7 @@ #include "input/InputStream.hxx" #include "input/Error.hxx" #include "util/StringCompare.hxx" +#include "util/StringView.hxx" #include "util/UriExtract.hxx" #include "Log.hxx" diff --git a/src/fs/Traits.cxx b/src/fs/Traits.cxx index 32f65105a..8abaf0899 100644 --- a/src/fs/Traits.cxx +++ b/src/fs/Traits.cxx @@ -19,6 +19,7 @@ #include "Traits.hxx" #include "util/StringCompare.hxx" +#include "util/StringView.hxx" #include "util/UriExtract.hxx" #include diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index 4b5b84553..9ec3c2add 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -39,6 +39,7 @@ #include "util/RuntimeError.hxx" #include "util/StringCompare.hxx" #include "util/StringFormat.hxx" +#include "util/StringView.hxx" #include "util/UriExtract.hxx" #include diff --git a/src/util/StringCompare.cxx b/src/util/StringCompare.cxx index 3a1475ae9..039c6bd88 100644 --- a/src/util/StringCompare.cxx +++ b/src/util/StringCompare.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx index 283134b96..a5d2b2ed1 100644 --- a/src/util/StringCompare.hxx +++ b/src/util/StringCompare.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,7 +30,6 @@ #ifndef STRING_COMPARE_HXX #define STRING_COMPARE_HXX -#include "StringView.hxx" #include "StringAPI.hxx" #ifdef _UNICODE @@ -64,9 +63,9 @@ StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept [[gnu::pure]] [[gnu::nonnull]] static inline bool -StringStartsWith(const char *haystack, StringView needle) noexcept +StringStartsWith(const char *haystack, std::string_view needle) noexcept { - return StringIsEqual(haystack, needle.data, needle.size); + return StringIsEqual(haystack, needle.data(), needle.size()); } [[gnu::pure]] [[gnu::nonnull]] @@ -84,26 +83,27 @@ StringEndsWithIgnoreCase(const char *haystack, const char *needle) noexcept; */ [[gnu::pure]] [[gnu::nonnull]] static inline const char * -StringAfterPrefix(const char *haystack, StringView needle) noexcept +StringAfterPrefix(const char *haystack, std::string_view needle) noexcept { return StringStartsWith(haystack, needle) - ? haystack + needle.size + ? haystack + needle.size() : nullptr; } [[gnu::pure]] [[gnu::nonnull]] static inline bool -StringStartsWithIgnoreCase(const char *haystack, StringView needle) noexcept +StringStartsWithIgnoreCase(const char *haystack, std::string_view needle) noexcept { - return StringIsEqualIgnoreCase(haystack, needle.data, needle.size); + return StringIsEqualIgnoreCase(haystack, needle.data(), needle.size()); } [[gnu::pure]] static inline bool -StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept +StringStartsWithIgnoreCase(std::string_view haystack, std::string_view needle) noexcept { - return haystack.size >= needle.size && - StringIsEqualIgnoreCase(haystack.data, needle.data, needle.size); + return haystack.size() >= needle.size() && + StringIsEqualIgnoreCase(haystack.data(), + needle.data(), needle.size()); } /** @@ -114,21 +114,21 @@ StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept */ [[gnu::pure]] [[gnu::nonnull]] static inline const char * -StringAfterPrefixIgnoreCase(const char *haystack, StringView needle) noexcept +StringAfterPrefixIgnoreCase(const char *haystack, std::string_view needle) noexcept { return StringStartsWithIgnoreCase(haystack, needle) - ? haystack + needle.size + ? haystack + needle.size() : nullptr; } [[gnu::pure]] -static inline StringView -StringAfterPrefixIgnoreCase(StringView haystack, - StringView needle) noexcept +static inline std::string_view +StringAfterPrefixIgnoreCase(std::string_view haystack, + std::string_view needle) noexcept { return StringStartsWithIgnoreCase(haystack, needle) - ? haystack.substr(needle.size) - : nullptr; + ? haystack.substr(needle.size()) + : std::string_view{}; } /** diff --git a/src/util/UriRelative.cxx b/src/util/UriRelative.cxx index cfaaa5512..c1c2853fa 100644 --- a/src/util/UriRelative.cxx +++ b/src/util/UriRelative.cxx @@ -31,6 +31,7 @@ #include "UriExtract.hxx" #include "StringAPI.hxx" #include "StringCompare.hxx" +#include "StringView.hxx" #include "Compiler.h" #include diff --git a/src/util/WStringCompare.cxx b/src/util/WStringCompare.cxx index 97f17faaa..04f5da6d3 100644 --- a/src/util/WStringCompare.cxx +++ b/src/util/WStringCompare.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/util/WStringCompare.hxx b/src/util/WStringCompare.hxx index af4ed22f7..ce6658e49 100644 --- a/src/util/WStringCompare.hxx +++ b/src/util/WStringCompare.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,7 +30,6 @@ #ifndef WSTRING_COMPARE_HXX #define WSTRING_COMPARE_HXX -#include "WStringView.hxx" #include "WStringAPI.hxx" #include @@ -62,9 +61,9 @@ StringIsEqualIgnoreCase(std::wstring_view a, std::wstring_view b) noexcept [[gnu::pure]] [[gnu::nonnull]] static inline bool -StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept +StringStartsWith(const wchar_t *haystack, std::wstring_view needle) noexcept { - return StringIsEqual(haystack, needle.data, needle.size); + return StringIsEqual(haystack, needle.data(), needle.size()); } [[gnu::pure]] [[gnu::nonnull]] @@ -83,19 +82,19 @@ StringEndsWithIgnoreCase(const wchar_t *haystack, */ [[gnu::pure]] [[gnu::nonnull]] static inline const wchar_t * -StringAfterPrefix(const wchar_t *haystack, WStringView needle) noexcept +StringAfterPrefix(const wchar_t *haystack, std::wstring_view needle) noexcept { return StringStartsWith(haystack, needle) - ? haystack + needle.size + ? haystack + needle.size() : nullptr; } [[gnu::pure]] [[gnu::nonnull]] static inline bool StringStartsWithIgnoreCase(const wchar_t *haystack, - WStringView needle) noexcept + std::wstring_view needle) noexcept { - return StringIsEqualIgnoreCase(haystack, needle.data, needle.size); + return StringIsEqualIgnoreCase(haystack, needle.data(), needle.size()); } /** @@ -106,10 +105,11 @@ StringStartsWithIgnoreCase(const wchar_t *haystack, */ [[gnu::pure]] [[gnu::nonnull]] static inline const wchar_t * -StringAfterPrefixIgnoreCase(const wchar_t *haystack, WStringView needle) noexcept +StringAfterPrefixIgnoreCase(const wchar_t *haystack, + std::wstring_view needle) noexcept { return StringStartsWithIgnoreCase(haystack, needle) - ? haystack + needle.size + ? haystack + needle.size() : nullptr; }