143#define CX_STR(literal) cxstring{literal, sizeof(literal) - 1}
154#define CX_STR(literal) ((cxstring){literal, sizeof(literal) - 1})
295#define cx_strcast(str) _Generic((str), \
296 cxmutstr: cx_strcast_m, \
297 cxstring: cx_strcast_c) \
405#define cx_strcat_a(alloc, count, ...) \
406cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
425#define cx_strcat(count, ...) \
426cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
449#define cx_strcat_m(str, count, ...) \
450cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__)
881#define cx_strdup_a(allocator, string) \
882 cx_strdup_a_((allocator), cx_strcast(string))
897#define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
1031#define cx_strreplacen(str, search, replacement, replmax) \
1032cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax)
1049#define cx_strreplace_a(allocator, str, search, replacement) \
1050cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX)
1066#define cx_strreplace(str, search, replacement) \
1067cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX)
1093#define cx_strtok(str, delim, limit) \
1094 cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit))
1495#define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep)
1511#define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep)
1527#define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep)
1543#define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep)
1559#define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep)
1575#define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep)
1591#define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep)
1607#define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep)
1623#define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep)
1639#define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep)
1655#define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep)
1671#define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep)
1687#define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep)
1703#define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep)
1719#define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep)
1735#define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep)
1751#define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep)
1769#define cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",")
1787#define cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",")
1805#define cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",")
1823#define cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",")
1841#define cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",")
1859#define cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",")
1877#define cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",")
1895#define cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",")
1913#define cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",")
1931#define cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",")
1949#define cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",")
1967#define cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",")
1985#define cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",")
2003#define cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",")
2021#define cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",")
2039#define cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",")
2057#define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",")
2073#define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep)
2088#define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep)
2106#define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",")
2123#define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",")
Interface for custom allocators.
Common definitions and feature checks.
#define cx_attr_export
Only used for building Windows DLLs.
Definition common.h:285
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_access_w(...)
Specifies that the function will only write through the given pointer.
Definition common.h:241
#define cx_attr_access_r(...)
Specifies that the function will only read through the given pointer.
Definition common.h:225
#define cx_attr_access_rw(...)
Specifies that the function will read and write through the given pointer.
Definition common.h:233
#define cx_attr_nonnull_arg(...)
The specified pointer arguments must be non-NULL.
Definition common.h:141
#define cx_attr_cstr_arg(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:206
int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep)
Converts a string to a number.
const unsigned cx_strstr_sbo_size
The maximum length of the "needle" in cx_strstr() that can use SBO.
cxmutstr cx_strreplacen_a(const CxAllocator *allocator, cxstring str, cxstring search, cxstring replacement, size_t replmax)
Replaces a string with another string.
int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strcasecmp_p(const void *s1, const void *s2)
Compares two strings ignoring case.
int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep)
Converts a string to a number.
static cxstring cx_strcast_m(cxmutstr str)
Internal function, do not use.
Definition string.h:269
int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep)
Converts a string to a number.
cxstring cx_strsubsl(cxstring string, size_t start, size_t length)
Returns a substring starting at the specified location.
int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep)
Converts a string to a number.
cxstring cx_str(const char *cstring)
Wraps a string that must be zero-terminated.
void cx_strfree(cxmutstr *str)
Passes the pointer in this string to free().
int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep)
Converts a string to a number.
cxmutstr cx_strsubsl_m(cxmutstr string, size_t start, size_t length)
Returns a substring starting at the specified location.
cxstring cx_strrchr(cxstring string, int chr)
Returns a substring starting at the location of the last occurrence of the specified character.
cxmutstr cx_strcat_ma(const CxAllocator *alloc, cxmutstr str, size_t count,...)
Concatenates strings.
int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep)
Converts a string to a number.
size_t cx_strsplit_ma(const CxAllocator *allocator, cxmutstr string, cxstring delim, size_t limit, cxmutstr **output)
Splits a given string using a delimiter string.
cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string)
Creates a duplicate of the specified string.
bool cx_strtok_next(CxStrtokCtx *ctx, cxstring *token)
Returns the next token.
#define cx_strcast(str)
Casts a mutable string to an immutable string.
Definition string.h:295
int cx_strcmp_p(const void *s1, const void *s2)
Compares two strings.
int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep)
Converts a string to a double precision floating point number.
int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep)
Converts a string to a number.
size_t cx_strsplit(cxstring string, cxstring delim, size_t limit, cxstring *output)
Splits a given string using a delimiter string.
int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strcasecmp(cxstring s1, cxstring s2)
Compares two strings ignoring case.
int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep)
Converts a string to a single precision floating point number.
cxmutstr cx_strchr_m(cxmutstr string, int chr)
Returns a substring starting at the location of the first occurrence of the specified character.
CxStrtokCtx cx_strtok_(cxstring str, cxstring delim, size_t limit)
Creates a string tokenization context.
cxmutstr cx_mutstr(char *cstring)
Wraps a mutable string that must be zero-terminated.
cxstring cx_strchr(cxstring string, int chr)
Returns a substring starting at the location of the first occurrence of the specified character.
cxstring cx_strn(const char *cstring, size_t length)
Wraps a string that does not need to be zero-terminated.
size_t cx_strlen(size_t count,...)
Returns the accumulated length of all specified strings.
cxmutstr cx_strtrim_m(cxmutstr string)
Omits leading and trailing spaces.
bool cx_strtok_next_m(CxStrtokCtx *ctx, cxmutstr *token)
Returns the next token of a mutable string.
int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep)
Converts a string to a number.
size_t cx_strsplit_a(const CxAllocator *allocator, cxstring string, cxstring delim, size_t limit, cxstring **output)
Splits a given string using a delimiter string.
bool cx_strprefix(cxstring string, cxstring prefix)
Checks, if a string has a specific prefix.
bool cx_strcaseprefix(cxstring string, cxstring prefix)
Checks, if a string has a specific prefix, ignoring the case.
cxstring cx_strtrim(cxstring string)
Omits leading and trailing spaces.
int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep)
Converts a string to a number.
cxstring cx_strstr(cxstring haystack, cxstring needle)
Returns a substring starting at the location of the first occurrence of the specified string.
cxstring cx_strsubs(cxstring string, size_t start)
Returns a substring starting at the specified location.
int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep)
Converts a string to a number.
cxmutstr cx_strsubs_m(cxmutstr string, size_t start)
Returns a substring starting at the specified location.
cxmutstr cx_strrchr_m(cxmutstr string, int chr)
Returns a substring starting at the location of the last occurrence of the specified character.
size_t cx_strsplit_m(cxmutstr string, cxstring delim, size_t limit, cxmutstr *output)
Splits a given string using a delimiter string.
int cx_strcmp(cxstring s1, cxstring s2)
Compares two strings.
bool cx_strsuffix(cxstring string, cxstring suffix)
Checks, if a string has a specific suffix.
void cx_strtok_delim(CxStrtokCtx *ctx, const cxstring *delim, size_t count)
Defines an array of more delimiters for the specified tokenization context.
cxmutstr cx_strstr_m(cxmutstr haystack, cxstring needle)
Returns a substring starting at the location of the first occurrence of the specified string.
bool cx_strcasesuffix(cxstring string, cxstring suffix)
Checks, if a string has a specific suffix, ignoring the case.
int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep)
Converts a string to a number.
cxmutstr cx_mutstrn(char *cstring, size_t length)
Wraps a string that does not need to be zero-terminated.
int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep)
Converts a string to a number.
static cxstring cx_strcast_c(cxstring str)
Internal function, do not use.
Definition string.h:279
void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str)
Passes the pointer in this string to the allocators free function.
Structure holding the data for an allocator.
Definition allocator.h:84
The UCX string structure.
Definition string.h:51
char * ptr
A pointer to the string.
Definition string.h:56
size_t length
The length of the string.
Definition string.h:58
The UCX string structure for immutable (constant) strings.
Definition string.h:69
size_t length
The length of the string.
Definition string.h:76
const char * ptr
A pointer to the immutable string.
Definition string.h:74
Context for string tokenizing.
Definition string.h:87
size_t delim_pos
Position of next delimiter in the source string.
Definition string.h:115
cxstring str
The string to tokenize.
Definition string.h:91
cxstring delim
The primary delimiter.
Definition string.h:95
size_t delim_more_count
Length of the array containing more delimiters.
Definition string.h:103
size_t pos
Position of the currently active token in the source string.
Definition string.h:107
size_t next_pos
The position of the next token in the source string.
Definition string.h:119
size_t found
The number of already found tokens.
Definition string.h:123
size_t limit
The maximum number of tokens that shall be returned.
Definition string.h:127
const cxstring * delim_more
Optional array of more delimiters.
Definition string.h:99