CBuild wiki
Implementation of string view in C.
License: GPL-3.0-or-later.
String view datatype
char*
data Pointer into data. This pointer
does not “own” its data.size_t size Length of string view. Data in range
from data to data+size is
guaranteed to be valid.Format description for string view for printf-style formatters.
Format argument for string view for printf-style formatters.
Create new string view from raw parts
Create new string view from C-string.
Create new string view from C-string literal (compile-time).
Trim whitespaces from a string view starting from the left.
size_t Number of
characters removed.
Trim whitespaces from a string view starting from the right.
size_t Number of
characters removed.
Trim whitespaces from a string view starting from both sides.
size_t Number of
characters removed.
Chop sizesize_t
characters from string view starting from the left.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.size_t size Number of character that will be
chopped.cbuild_sv_t New string
view containing chopped characters.
Chop sizesize_t
characters from string view starting from the right.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.size_t size Number of character that will be
chopped.cbuild_sv_t New string
view containing chopped characters.
Chop characters from string view starting from the left until delimchar
is found.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.char delim Delimiter character.cbuild_sv_t New string
view containing chopped characters. delimchar
will not be included.
Chop characters from string view starting from the right until delimchar
is found.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.char delim Delimiter character.cbuild_sv_t New string
view containing chopped characters. delimchar
will not be included.
Chop characters from string view starting from the left until delimcbuild_sv_t is found.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.cbuild_sv_t delim Delimiter string view.cbuild_sv_t New string
view containing chopped characters. delimcbuild_sv_t will not be
included.
Chop characters from string view starting from the right until delimcbuild_sv_t is found.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.cbuild_sv_t delim Delimiter string view.cbuild_sv_t New string
view containing chopped characters. delimcbuild_sv_t will not be
included.
Delimiter function. Used as comparator in cbuild_sv_chop_by_func
and cbuild_sv_chop_right_by_func
const cbuild_sv_t*
sv String view passed to
function.size_t idx Current character.void*
args Arguments passed by caller.bool If true is
returned this character will be considered a delimiter
CBUILDDEF cbuild_sv_t cbuild_sv_chop_by_func(cbuild_sv_t* sv,
cbuild_sv_delim_func delim, void* args);chop characters from string view starting from the left until delimcbuild_sv_delim_func
returns true.
cbuild_sv_t*
sv String view from which data will be
chopped. its size will be reduced.cbuild_sv_delim_func delim Delimiter function.void*
args Arguments to a function.cbuild_sv_t new string
view containing chopped characters. delimeter character will not be in
any string view.
CBUILDDEF cbuild_sv_t cbuild_sv_chop_right_by_func(cbuild_sv_t* sv,
cbuild_sv_delim_func delim, void* args);chop characters from string view starting from the right until delimcbuild_sv_delim_func
returns true.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.cbuild_sv_delim_func delim Delimiter function.void*
args Arguments to a function.cbuild_sv_t new string
view containing chopped characters. Delimiter character will not be in
any string view.
strcmp for string view. Fully compatible but extends
API.
-2 If size of first
string view is smaller.-1 If first different
character in first string view is smaller.0 If two string views
are equal.1 If first different
character in first string view is larger. 2 If size of first string view
is larger.strcmp for string view. Fully compatible but extends
API. Performs case folding for ASCII.
-2 If size of first
string view is smaller.-1 If first different
character in first string view is smaller.0 If two string views
are equal.1 If first different
character in first string view is larger.2 If size of first
string view is larger.Check if string view has specific prefix.
Check if string view has specific suffix.
Find specific character in string view.
ssize_t Index of
character or -1
if not found
Find specific substring (provided as string view) in another string view.
ssize_t Index of first
character of needlecbuild_sv_t or -1
if not found
Find specific character in string view. Searches from the end.
ssize_t Index of
character or -1
if not found
Check if string view contains some character.
Check substring (provided as string view) is contained in another string view.
Get length of first utf8 codepoint in string view.
Invalid codepoints assumed to have length of 1
int Length of codepoint
in bytes.
strchr implementation for string view.
cbuild_sv_t sv String view to work withchar c Character that will be searched.char* Pointer to
character or NULL if not found.
strchr implementation for string view. Operates on utf8
codepoints instead of ASCII characters.
cbuild_sv_t sv String view to work withuint32_t
c Codepoint that will be
searched.char* Pointer to
character or NULL if not found.
Chop first utf8 codepoint out of string view.
uint32_t Unicode
codepoint. UINT32_MAX means error.
Chop characters from string view starting from the left until delimuint32_t
is found. Operates on utf8 codepoints instead of ASCII characters.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.uint32_t
delim Delimiter character.cbuild_sv_t New string
view containing chopped characters. delimuint32_t
will not be included.
Delimiter function. Used as comparator in cbuild_sv_chop_by_func_utf8
const cbuild_sv_t*
sv String view, prechopped, so first
character is possible delimiter and should be checked.void*
args Arguments passed by caller.bool If true is
returned this character will be considered a delimiter
CBUILDDEF cbuild_sv_t cbuild_sv_chop_by_func_utf8(cbuild_sv_t* sv,
cbuild_sv_utf8delim_func delim, void* args);chop characters from string view starting from the right until delimcbuild_sv_utf8delim_func
returns true. Operates on utf8 codepoints instead of ASCII
characters.
cbuild_sv_t*
sv String view from which data will be
chopped. Its size will be reduced.cbuild_sv_utf8delim_func delim Delimiter function.void*
args Arguments to a function.cbuild_sv_t new string
view containing chopped characters. Delimiter character will not be in
any string view.
Get length of a string view in utf8 codepoints.
Invalid codepoints assumed to have length of 1
Check if string view is a valid utf8 data.
cbuild_sv_t sv String view to work with.size_t*
idx If validation failed this will
store index of first invalid codepoint. Can be NULL.bool false
if validation failed.
Convert string view to c-string. Allocate memory via
malloc.
Convert string view to c-string. Allocate memory via
malloc.
Convert string view to c-string. Allocate memory via cbuild_temp_malloc.
Convert string view to c-string. Allocate memory via cbuild_temp_malloc.