rcx

library of miscellaneous bits of C code
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

commit e42145751d82907da00115a1b17e31e5ed9ad8be
parent 065f93cebe1ab19cc333af3bde015d55b237bf45
Author: Robert Russell <robertrussell.72001@gmail.com>
Date:   Sat, 30 Sep 2023 23:06:46 -0700

Add str_find_byte

Diffstat:
Minc/string.h | 6++++++
1 file changed, 6 insertions(+), 0 deletions(-)

diff --git a/inc/string.h b/inc/string.h @@ -51,6 +51,12 @@ str_eq(Str s, Str t) { return s.len == t.len && !memcmp(s.data, t.data, s.len); } +static inline isize +str_find_byte(Str s, u8 b) { + u8 *match = memchr(s.data, b, s.len); + return match ? match - s.data : -1; +} + static inline usize str_utf8_decode(rune *c, Str s) { return r_utf8_decode(c, (char *)s.data, s.len);