util/StringCompare: use std::string_view instead of StringView
This commit is contained in:
parent
759da033fc
commit
d256d3dabe
@ -34,6 +34,7 @@
|
|||||||
#include <cdio/iso9660.h>
|
#include <cdio/iso9660.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <span>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "input/Error.hxx"
|
#include "input/Error.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
|
#include "util/StringView.hxx"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Traits.hxx"
|
#include "Traits.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
|
#include "util/StringView.hxx"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
#include "util/StringFormat.hxx"
|
#include "util/StringFormat.hxx"
|
||||||
|
#include "util/StringView.hxx"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -30,7 +30,6 @@
|
|||||||
#ifndef STRING_COMPARE_HXX
|
#ifndef STRING_COMPARE_HXX
|
||||||
#define STRING_COMPARE_HXX
|
#define STRING_COMPARE_HXX
|
||||||
|
|
||||||
#include "StringView.hxx"
|
|
||||||
#include "StringAPI.hxx"
|
#include "StringAPI.hxx"
|
||||||
|
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
@ -64,9 +63,9 @@ StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept
|
|||||||
|
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline bool
|
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]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
@ -84,26 +83,27 @@ StringEndsWithIgnoreCase(const char *haystack, const char *needle) noexcept;
|
|||||||
*/
|
*/
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline const char *
|
static inline const char *
|
||||||
StringAfterPrefix(const char *haystack, StringView needle) noexcept
|
StringAfterPrefix(const char *haystack, std::string_view needle) noexcept
|
||||||
{
|
{
|
||||||
return StringStartsWith(haystack, needle)
|
return StringStartsWith(haystack, needle)
|
||||||
? haystack + needle.size
|
? haystack + needle.size()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline bool
|
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]]
|
[[gnu::pure]]
|
||||||
static inline bool
|
static inline bool
|
||||||
StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept
|
StringStartsWithIgnoreCase(std::string_view haystack, std::string_view needle) noexcept
|
||||||
{
|
{
|
||||||
return haystack.size >= needle.size &&
|
return haystack.size() >= needle.size() &&
|
||||||
StringIsEqualIgnoreCase(haystack.data, needle.data, needle.size);
|
StringIsEqualIgnoreCase(haystack.data(),
|
||||||
|
needle.data(), needle.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,21 +114,21 @@ StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept
|
|||||||
*/
|
*/
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline const char *
|
static inline const char *
|
||||||
StringAfterPrefixIgnoreCase(const char *haystack, StringView needle) noexcept
|
StringAfterPrefixIgnoreCase(const char *haystack, std::string_view needle) noexcept
|
||||||
{
|
{
|
||||||
return StringStartsWithIgnoreCase(haystack, needle)
|
return StringStartsWithIgnoreCase(haystack, needle)
|
||||||
? haystack + needle.size
|
? haystack + needle.size()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
static inline StringView
|
static inline std::string_view
|
||||||
StringAfterPrefixIgnoreCase(StringView haystack,
|
StringAfterPrefixIgnoreCase(std::string_view haystack,
|
||||||
StringView needle) noexcept
|
std::string_view needle) noexcept
|
||||||
{
|
{
|
||||||
return StringStartsWithIgnoreCase(haystack, needle)
|
return StringStartsWithIgnoreCase(haystack, needle)
|
||||||
? haystack.substr(needle.size)
|
? haystack.substr(needle.size())
|
||||||
: nullptr;
|
: std::string_view{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "UriExtract.hxx"
|
#include "UriExtract.hxx"
|
||||||
#include "StringAPI.hxx"
|
#include "StringAPI.hxx"
|
||||||
#include "StringCompare.hxx"
|
#include "StringCompare.hxx"
|
||||||
|
#include "StringView.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -30,7 +30,6 @@
|
|||||||
#ifndef WSTRING_COMPARE_HXX
|
#ifndef WSTRING_COMPARE_HXX
|
||||||
#define WSTRING_COMPARE_HXX
|
#define WSTRING_COMPARE_HXX
|
||||||
|
|
||||||
#include "WStringView.hxx"
|
|
||||||
#include "WStringAPI.hxx"
|
#include "WStringAPI.hxx"
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@ -62,9 +61,9 @@ StringIsEqualIgnoreCase(std::wstring_view a, std::wstring_view b) noexcept
|
|||||||
|
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline bool
|
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]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
@ -83,19 +82,19 @@ StringEndsWithIgnoreCase(const wchar_t *haystack,
|
|||||||
*/
|
*/
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline const wchar_t *
|
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)
|
return StringStartsWith(haystack, needle)
|
||||||
? haystack + needle.size
|
? haystack + needle.size()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline bool
|
static inline bool
|
||||||
StringStartsWithIgnoreCase(const wchar_t *haystack,
|
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]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
static inline const wchar_t *
|
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)
|
return StringStartsWithIgnoreCase(haystack, needle)
|
||||||
? haystack + needle.size
|
? haystack + needle.size()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user