util/StringAPI: add memrchr() wrapper
This commit is contained in:
@@ -94,6 +94,27 @@ StringFindLast(char *haystack, char needle) noexcept
|
||||
return strrchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringFindLast(const char *haystack, char needle, size_t size) noexcept
|
||||
{
|
||||
#if defined(__GLIBC__) || defined(__BIONIC__)
|
||||
/* memrchr() is a GNU extension (and also available on
|
||||
Android) */
|
||||
return (const char *)memrchr(haystack, needle, size);
|
||||
#else
|
||||
/* emulate for everybody else */
|
||||
const auto *p = haystack + size;
|
||||
while (p > haystack) {
|
||||
--p;
|
||||
if (*p == needle)
|
||||
return p;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringFindAny(const char *haystack, const char *accept) noexcept
|
||||
|
||||
Reference in New Issue
Block a user