diff options
author | segunkayode1 <segunkayode456@gmail.com> | 2024-02-26 01:52:17 +1100 |
---|---|---|
committer | segunkayode1 <segunkayode456@gmail.com> | 2024-02-26 01:52:17 +1100 |
commit | 7e4e763d8f2e15c4f2b2a77402f4fe0c4e8b5f68 (patch) | |
tree | 1d4b3a7b497afca3d4ce17a64828510ea0c66ba7 /src/std/str.c | |
parent | 06ed6edcedf30fd8f7e036fffe8f81e8ca89d4b0 (diff) |
string subview functions
Diffstat (limited to 'src/std/str.c')
-rw-r--r-- | src/std/str.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/std/str.c b/src/std/str.c index 3b2770e..1e092bc 100644 --- a/src/std/str.c +++ b/src/std/str.c @@ -41,4 +41,28 @@ str8 str8_concat(arena* a, str8 left, str8 right) { dest[n_bytes - 1] = '\0'; return str8_create(dest, n_bytes); -}
\ No newline at end of file +} + +str8 str8_substr(str8 s, u64 min, u64 max){ + s.buf = s.buf + (ptrdiff_t)min; + s.len = max - min; + return s; +} + +str8 str8_take(str8 s, u64 first_n){ + return str8_substr(s, 0, first_n); +} + +str8 str8_drop(str8 s, u64 last_n){ + return str8_substr(s, s.len - last_n, s.len); +} + +str8 str8_skip(str8 s, u64 n){ + return str8_substr(s, n, s.len); +} + +str8 str8_chop(str8 s, u64 n){ + return str8_substr(s, 0, s.len - n); +} + + |