From 5fb2db2380b678381ef455a18c8210a6a3314e60 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sat, 1 Nov 2025 19:49:31 +0500 Subject: [PATCH] implemented str_slice --- include/tlibc/collections/Array.h | 3 ++- include/tlibc/string/str.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/tlibc/collections/Array.h b/include/tlibc/collections/Array.h index 631db5a..6b433a0 100755 --- a/include/tlibc/collections/Array.h +++ b/include/tlibc/collections/Array.h @@ -38,11 +38,12 @@ static inline Array_ Array_copy(Array_ src){ #define struct_castTo_Array(STRUCT_PTR) Array_construct_size((STRUCT_PTR), sizeof(*STRUCT_PTR)) +///@return a[0..n] static inline Array(u8) Array_sliceBefore(Array(u8) a, u32 n){ return Array_construct_size(a.data, n); } - +///@return a[n...] static inline Array(u8) Array_sliceAfter(Array(u8) a, u32 n){ return Array_construct_size((u8*)a.data + n, a.size - n); } diff --git a/include/tlibc/string/str.h b/include/tlibc/string/str.h index 866961d..43903ee 100755 --- a/include/tlibc/string/str.h +++ b/include/tlibc/string/str.h @@ -59,3 +59,14 @@ str hex_to_str(Array(u8) buf, bool uppercase); /// @brief removes blank characters from start and end of the line void str_trim(str* line, bool set_zero_at_end); + + +///@return s[0..n] +static inline str str_sliceBefore(str s, u32 n){ + return str_construct(s.data, n, false); +} + +///@return s[n...] +static inline str str_sliceAfter(str s, u32 n){ + return str_construct(s.data + n, s.size - n, s.isZeroTerminated); +}