util/StringCompare: add StringIsEqual() with string_view

This commit is contained in:
Max Kellermann 2020-03-13 20:36:48 +01:00
parent 8a1f1fbe06
commit 85b072b3d3
2 changed files with 32 additions and 0 deletions

View File

@ -45,6 +45,22 @@ StringIsEmpty(const char *string) noexcept
return *string == 0; return *string == 0;
} }
gcc_pure
static inline bool
StringIsEqual(std::string_view a, std::string_view b) noexcept
{
return a.size() == b.size() &&
StringIsEqual(a.data(), b.data(), b.size());
}
gcc_pure
static inline bool
StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept
{
return a.size() == b.size() &&
StringIsEqualIgnoreCase(a.data(), b.data(), b.size());
}
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
static inline bool static inline bool
StringStartsWith(const char *haystack, StringView needle) noexcept StringStartsWith(const char *haystack, StringView needle) noexcept

View File

@ -43,6 +43,22 @@ StringIsEmpty(const wchar_t *string) noexcept
return *string == 0; return *string == 0;
} }
gcc_pure
static inline bool
StringIsEqual(std::wstring_view a, std::wstring_view b) noexcept
{
return a.size() == b.size() &&
StringIsEqual(a.data(), b.data(), b.size());
}
gcc_pure
static inline bool
StringIsEqualIgnoreCase(std::wstring_view a, std::wstring_view b) noexcept
{
return a.size() == b.size() &&
StringIsEqualIgnoreCase(a.data(), b.data(), b.size());
}
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
static inline bool static inline bool
StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept