Commit 728e4e9a authored by Max Kellermann's avatar Max Kellermann

util/StringCompare: add StringEndsWithIgnoreCase(), StringStartsWithIgnoreCase()

parent 2d6f9f9a
......@@ -40,6 +40,17 @@ StringEndsWith(const char *haystack, const char *needle) noexcept
needle, needle_length) == 0;
}
bool
StringEndsWithIgnoreCase(const char *haystack, const char *needle) noexcept
{
const size_t haystack_length = StringLength(haystack);
const size_t needle_length = StringLength(needle);
return haystack_length >= needle_length &&
StringIsEqualIgnoreCase(haystack + haystack_length - needle_length,
needle);
}
const char *
FindStringSuffix(const char *p, const char *suffix) noexcept
{
......
......@@ -56,6 +56,10 @@ gcc_pure gcc_nonnull_all
bool
StringEndsWith(const char *haystack, const char *needle) noexcept;
gcc_pure gcc_nonnull_all
bool
StringEndsWithIgnoreCase(const char *haystack, const char *needle) noexcept;
/**
* Returns the portion of the string after a prefix. If the string
* does not begin with the specified prefix, this function returns
......@@ -70,6 +74,13 @@ StringAfterPrefix(const char *haystack, StringView needle) noexcept
: nullptr;
}
gcc_pure gcc_nonnull_all
static inline bool
StringStartsWithIgnoreCase(const char *haystack, StringView needle) noexcept
{
return StringIsEqualIgnoreCase(haystack, needle.data, needle.size);
}
/**
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
......
......@@ -39,6 +39,18 @@ StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept
StringIsEqual(haystack + haystack_length - needle_length, needle);
}
bool
StringEndsWithIgnoreCase(const wchar_t *haystack,
const wchar_t *needle) noexcept
{
const size_t haystack_length = StringLength(haystack);
const size_t needle_length = StringLength(needle);
return haystack_length >= needle_length &&
StringIsEqualIgnoreCase(haystack + haystack_length - needle_length,
needle);
}
const wchar_t *
FindStringSuffix(const wchar_t *p, const wchar_t *suffix) noexcept
{
......
......@@ -54,6 +54,11 @@ gcc_pure gcc_nonnull_all
bool
StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept;
gcc_pure gcc_nonnull_all
bool
StringEndsWithIgnoreCase(const wchar_t *haystack,
const wchar_t *needle) noexcept;
/**
* Returns the portion of the string after a prefix. If the string
* does not begin with the specified prefix, this function returns
......@@ -68,6 +73,14 @@ StringAfterPrefix(const wchar_t *haystack, WStringView needle) noexcept
: nullptr;
}
gcc_pure gcc_nonnull_all
static inline bool
StringStartsWithIgnoreCase(const wchar_t *haystack,
WStringView needle) noexcept
{
return StringIsEqualIgnoreCase(haystack, needle.data, needle.size);
}
/**
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment