C Collections

cstring · Section 3

cstring_substring

cstring_substring - create a new string from a sub-range

C Collections (libccollections, -lccollections)

#include <ccollections/cstring.h>
 
cstr cstring_substring(cstr s, size_t start, size_t length, char **err);

This function allocates a new cstring that holds the characters in the
range [start, start + length). When start + length goes past the end of
the string the range is clamped to the real end, and when start is at or
past the length of the string you get an empty cstring.

s        Source string
start    Zero-based start index
length   Number of characters to include
err      Optional pointer to receive an error string on failure

A new cstring on success
NULL when an allocation fails, with the details written to *err when err
is not NULL

You must destroy the returned cstring once you are done with it
Asserts if s is NULL

cstring_copy(3), cstring_split(3), cstring_find(3)