util/StringAPI: add memrchr() wrapper

This commit is contained in:
Max Kellermann
2019-09-07 23:59:59 +02:00
parent 2c3eb5b8ad
commit 0b956cf968
3 changed files with 41 additions and 0 deletions

View File

@@ -90,6 +90,21 @@ StringFindLast(wchar_t *haystack, wchar_t needle) noexcept
return wcsrchr(haystack, needle);
}
gcc_pure gcc_nonnull_all
static inline const wchar_t *
StringFindLast(const wchar_t *haystack, wchar_t needle, size_t size) noexcept
{
/* there's no wmemrchr() unfortunately */
const auto *p = haystack + size;
while (p > haystack) {
--p;
if (*p == needle)
return p;
}
return nullptr;
}
gcc_pure gcc_nonnull_all
static inline const wchar_t *
StringFindAny(const wchar_t *haystack, const wchar_t *accept) noexcept