diff options
author | Max Kellermann <max@musicpd.org> | 2019-09-07 23:59:59 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-09-07 23:59:59 +0200 |
commit | 0b956cf9682da48174c0fa1dc415a48bdc0d8160 (patch) | |
tree | 13eccd2533f0d875f0a56f32b93aa24ef19ee5eb /src/util/WStringAPI.hxx | |
parent | 2c3eb5b8adf9482a2f30e94ac37437470993a41b (diff) |
util/StringAPI: add memrchr() wrapper
Diffstat (limited to 'src/util/WStringAPI.hxx')
-rw-r--r-- | src/util/WStringAPI.hxx | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util/WStringAPI.hxx b/src/util/WStringAPI.hxx index 58bc24c87..82864a9a5 100644 --- a/src/util/WStringAPI.hxx +++ b/src/util/WStringAPI.hxx @@ -92,6 +92,21 @@ StringFindLast(wchar_t *haystack, wchar_t needle) noexcept 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 { return wcspbrk(haystack, accept); |