2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
2015-03-05 08:21:51 +01:00
|
|
|
|
2015-11-06 09:09:02 +01:00
|
|
|
#include "WStringCompare.hxx"
|
2015-03-05 08:21:51 +01:00
|
|
|
|
2019-08-15 17:57:20 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2015-03-05 08:21:51 +01:00
|
|
|
bool
|
2017-05-08 14:44:49 +02:00
|
|
|
StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept
|
2015-03-05 08:21:51 +01:00
|
|
|
{
|
2015-10-16 19:17:54 +02:00
|
|
|
const size_t haystack_length = StringLength(haystack);
|
|
|
|
const size_t needle_length = StringLength(needle);
|
2015-03-05 08:21:51 +01:00
|
|
|
|
2015-10-16 19:17:54 +02:00
|
|
|
return haystack_length >= needle_length &&
|
|
|
|
StringIsEqual(haystack + haystack_length - needle_length, needle);
|
2015-03-05 08:21:51 +01:00
|
|
|
}
|
|
|
|
|
2018-09-06 19:29:25 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-03-05 08:21:51 +01:00
|
|
|
const wchar_t *
|
2017-05-08 14:44:49 +02:00
|
|
|
FindStringSuffix(const wchar_t *p, const wchar_t *suffix) noexcept
|
2015-03-05 08:21:51 +01:00
|
|
|
{
|
|
|
|
const size_t p_length = StringLength(p);
|
|
|
|
const size_t suffix_length = StringLength(suffix);
|
|
|
|
|
|
|
|
if (p_length < suffix_length)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const auto *q = p + p_length - suffix_length;
|
|
|
|
return memcmp(q, suffix, suffix_length * sizeof(*suffix)) == 0
|
|
|
|
? q
|
|
|
|
: nullptr;
|
|
|
|
}
|