rcx

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

commit e757da1b5e257fe22dff240ae4e70c2a97c8520d
parent 53dd7357a28620b688077cbbfa316c0fbaa6ca45
Author: Robert Russell <robertrussell.72001@gmail.com>
Date:   Sun, 20 Aug 2023 17:05:19 -0700

Add back str_slice_to_end

Changed my mind again...

Note to future self: str_slice(s, l) is not very readable, so
keep str_slice_to_end, you fool!

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

diff --git a/inc/string.h b/inc/string.h @@ -56,10 +56,8 @@ str_utf8_decode(rune *c, Str s) { return r_utf8_decode(c, (char *)s.data, s.len); } -#define str_slice(s, l, ...) r_str_slice_((s), (l), VA_DEFAULT(,##__VA_ARGS__, str_len(s))) - static inline Str -r_str_slice_(Str s, isize l, isize u) { +str_slice(Str s, isize l, isize u) { if (l < 0) l += s.len; ASSERT(0 <= l && l <= s.len, "str_slice: lower index out of bounds"); @@ -72,6 +70,11 @@ r_str_slice_(Str s, isize l, isize u) { }; } +static inline Str +str_slice_to_end(Str s, isize l) { + return str_slice(s, l, str_len(s)); +} + /* Like sprintf and vsprintf, but for Str's. The result must be freed with * free(str_bytes(*str)). */ int str_alloc_printf(Str *str, char *fmt, ...);