diff options
Diffstat (limited to 'String.c')
| -rw-r--r-- | String.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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; +} |
