util/StringCompare: use std::string_view instead of StringView

This commit is contained in:
Max Kellermann 2022-05-31 13:18:42 +02:00
parent 759da033fc
commit d256d3dabe
9 changed files with 35 additions and 30 deletions

View File

@ -34,6 +34,7 @@
#include <cdio/iso9660.h>
#include <array>
#include <span>
#include <utility>
#include <stdlib.h>

View File

@ -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"

View File

@ -19,6 +19,7 @@
#include "Traits.hxx"
#include "util/StringCompare.hxx"
#include "util/StringView.hxx"
#include "util/UriExtract.hxx"
#include <string.h>

View File

@ -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 <cassert>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
*
* 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{};
}
/**

View File

@ -31,6 +31,7 @@
#include "UriExtract.hxx"
#include "StringAPI.hxx"
#include "StringCompare.hxx"
#include "StringView.hxx"
#include "Compiler.h"
#include <cassert>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
*
* 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 <string_view>
@ -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;
}