From 8636d3558523fe30a2be84549c2b6eb5e125e97c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 29 Apr 2026 18:26:15 +0300 Subject: feat(String): Implement S_substr function --- String.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'String.c') diff --git a/String.c b/String.c index fb003d8..7723525 100644 --- a/String.c +++ b/String.c @@ -240,3 +240,20 @@ S_find(String s, char c) { return index; } + +String +S_substr(MemoryManager *mm, String s, usize start, usize length) { + if (NULL == s) + return NULL; + + struct StringMeta *sm = S_metadata(s); + + if (start >= sm->length || 0 == length) + return S_newlen(mm, 0); + + String result = S_newlen(mm, length); + strncpy(result, s + start, length); + result[length] = '\0'; + + return result; +} -- cgit v1.2.3