![]() |
ucx
UAP Common Extensions
|
Strings that know their length. More...
Go to the source code of this file.
Data Structures | |
struct | cx_mutstr_s |
The UCX string structure. More... | |
struct | cx_string_s |
The UCX string structure for immutable (constant) strings. More... | |
struct | cx_strtok_ctx_s |
Context for string tokenizing. More... | |
Macros | |
#define | CX_STR(literal) ((cxstring){literal, sizeof(literal) - 1}) |
A literal initializer for an UCX string structure. | |
#define | cx_strcast(str) |
Casts a mutable string to an immutable string. | |
#define | cx_strcat_a(alloc, count, ...) cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
Concatenates strings and returns a new string. | |
#define | cx_strcat(count, ...) cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
Concatenates strings and returns a new string. | |
#define | cx_strcat_m(str, count, ...) cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) |
Concatenates strings. | |
#define | cx_strdup_a(allocator, string) cx_strdup_a_((allocator), cx_strcast(string)) |
Creates a duplicate of the specified string. | |
#define | cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
Creates a duplicate of the specified string. | |
#define | cx_strreplacen(str, search, replacement, replmax) cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax) |
Replaces a string with another string. | |
#define | cx_strreplace_a(allocator, str, search, replacement) cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX) |
Replaces a string with another string. | |
#define | cx_strreplace(str, search, replacement) cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX) |
Replaces a string with another string. | |
#define | cx_strtok(str, delim, limit) cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit)) |
Creates a string tokenization context. | |
#define | cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number. | |
#define | cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number. | |
#define | cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep) |
Converts a string to a single precision floating point number. | |
#define | cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep) |
Converts a string to a double precision floating point number. | |
#define | cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",") |
Converts a string to a single precision floating point number. | |
#define | cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",") |
Converts a string to a double precision floating point number. | |
Typedefs | |
typedef struct cx_mutstr_s | cxmutstr |
A mutable string. | |
typedef struct cx_string_s | cxstring |
An immutable string. | |
typedef struct cx_strtok_ctx_s | CxStrtokCtx |
A string tokenizing context. | |
Functions | |
cxmutstr | cx_mutstr (char *cstring) |
Wraps a mutable string that must be zero-terminated. | |
cxmutstr | cx_mutstrn (char *cstring, size_t length) |
Wraps a string that does not need to be zero-terminated. | |
cxstring | cx_str (const char *cstring) |
Wraps a string that must be zero-terminated. | |
cxstring | cx_strn (const char *cstring, size_t length) |
Wraps a string that does not need to be zero-terminated. | |
static cxstring | cx_strcast_m (cxmutstr str) |
Internal function, do not use. | |
static cxstring | cx_strcast_c (cxstring str) |
Internal function, do not use. | |
void | cx_strfree (cxmutstr *str) |
Passes the pointer in this string to free() . | |
void | cx_strfree_a (const CxAllocator *alloc, cxmutstr *str) |
Passes the pointer in this string to the allocators free function. | |
size_t | cx_strlen (size_t count,...) |
Returns the accumulated length of all specified strings. | |
cxmutstr | cx_strcat_ma (const CxAllocator *alloc, cxmutstr str, size_t count,...) |
Concatenates strings. | |
cxstring | cx_strsubs (cxstring string, size_t start) |
Returns a substring starting at the specified location. | |
cxstring | cx_strsubsl (cxstring string, size_t start, size_t length) |
Returns a substring starting at the specified location. | |
cxmutstr | cx_strsubs_m (cxmutstr string, size_t start) |
Returns a substring starting at the specified location. | |
cxmutstr | cx_strsubsl_m (cxmutstr string, size_t start, size_t length) |
Returns a substring starting at the specified location. | |
cxstring | cx_strchr (cxstring string, int chr) |
Returns a substring starting at the location of the first occurrence of the specified character. | |
cxmutstr | cx_strchr_m (cxmutstr string, int chr) |
Returns a substring starting at the location of the first occurrence of the specified character. | |
cxstring | cx_strrchr (cxstring string, int chr) |
Returns a substring starting at the location of the last occurrence of the specified character. | |
cxmutstr | cx_strrchr_m (cxmutstr string, int chr) |
Returns a substring starting at the location of the last occurrence of the specified character. | |
cxstring | cx_strstr (cxstring haystack, cxstring needle) |
Returns a substring starting at the location of the first occurrence of the specified string. | |
cxmutstr | cx_strstr_m (cxmutstr haystack, cxstring needle) |
Returns a substring starting at the location of the first occurrence of the specified string. | |
size_t | cx_strsplit (cxstring string, cxstring delim, size_t limit, cxstring *output) |
Splits a given string using a delimiter string. | |
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. | |
size_t | cx_strsplit_m (cxmutstr string, cxstring delim, size_t limit, cxmutstr *output) |
Splits a given string using a delimiter string. | |
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. | |
int | cx_strcmp (cxstring s1, cxstring s2) |
Compares two strings. | |
int | cx_strcasecmp (cxstring s1, cxstring s2) |
Compares two strings ignoring case. | |
int | cx_strcmp_p (const void *s1, const void *s2) |
Compares two strings. | |
int | cx_strcasecmp_p (const void *s1, const void *s2) |
Compares two strings ignoring case. | |
cxmutstr | cx_strdup_a_ (const CxAllocator *allocator, cxstring string) |
Creates a duplicate of the specified string. | |
cxstring | cx_strtrim (cxstring string) |
Omits leading and trailing spaces. | |
cxmutstr | cx_strtrim_m (cxmutstr string) |
Omits leading and trailing spaces. | |
bool | cx_strprefix (cxstring string, cxstring prefix) |
Checks, if a string has a specific prefix. | |
bool | cx_strsuffix (cxstring string, cxstring suffix) |
Checks, if a string has a specific suffix. | |
bool | cx_strcaseprefix (cxstring string, cxstring prefix) |
Checks, if a string has a specific prefix, ignoring the case. | |
bool | cx_strcasesuffix (cxstring string, cxstring suffix) |
Checks, if a string has a specific suffix, ignoring the case. | |
cxmutstr | cx_strreplacen_a (const CxAllocator *allocator, cxstring str, cxstring search, cxstring replacement, size_t replmax) |
Replaces a string with another string. | |
CxStrtokCtx | cx_strtok_ (cxstring str, cxstring delim, size_t limit) |
Creates a string tokenization context. | |
bool | cx_strtok_next (CxStrtokCtx *ctx, cxstring *token) |
Returns the next token. | |
bool | cx_strtok_next_m (CxStrtokCtx *ctx, cxmutstr *token) |
Returns the next token of a mutable string. | |
void | cx_strtok_delim (CxStrtokCtx *ctx, const cxstring *delim, size_t count) |
Defines an array of more delimiters for the specified tokenization context. | |
int | cx_strtos_lc_ (cxstring str, short *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoi_lc_ (cxstring str, int *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtol_lc_ (cxstring str, long *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoll_lc_ (cxstring str, long long *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. | |
int | cx_strtoi16_lc_ (cxstring str, int16_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoi32_lc_ (cxstring str, int32_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoi64_lc_ (cxstring str, int64_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtous_lc_ (cxstring str, unsigned short *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtou_lc_ (cxstring str, unsigned int *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoul_lc_ (cxstring str, unsigned long *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoull_lc_ (cxstring str, unsigned long long *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtou8_lc_ (cxstring str, uint8_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtou16_lc_ (cxstring str, uint16_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtou32_lc_ (cxstring str, uint32_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtou64_lc_ (cxstring str, uint64_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtoz_lc_ (cxstring str, size_t *output, int base, const char *groupsep) |
Converts a string to a number. | |
int | cx_strtof_lc_ (cxstring str, float *output, char decsep, const char *groupsep) |
Converts a string to a single precision floating point number. | |
int | cx_strtod_lc_ (cxstring str, double *output, char decsep, const char *groupsep) |
Converts a string to a double precision floating point number. | |
Variables | |
const unsigned | cx_strstr_sbo_size |
The maximum length of the "needle" in cx_strstr() that can use SBO. | |
Strings that know their length.
#define CX_STR | ( | literal | ) | ((cxstring){literal, sizeof(literal) - 1}) |
A literal initializer for an UCX string structure.
The argument MUST be a string (const char*) literal.
literal | the string literal |
#define cx_strcast | ( | str | ) |
Casts a mutable string to an immutable string.
Does nothing for already immutable strings.
str | (cxstring or cxmutstr ) the string to cast |
cxstring
) an immutable copy of the string pointer #define cx_strcat | ( | count, | |
... ) cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
Concatenates strings and returns a new string.
The resulting string will be allocated by standard malloc()
. So developers must pass the return value to cx_strfree() eventually.
If memory allocation fails, the pointer in the returned string will be NULL
and errno
might be set.
count | (size_t ) the number of the other following strings to concatenate |
... | all other UCX strings |
cxmutstr
) the concatenated string #define cx_strcat_a | ( | alloc, | |
count, | |||
... ) cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
Concatenates strings and returns a new string.
The resulting string will be allocated by the specified allocator. So developers must pass the return value to cx_strfree_a() eventually.
If memory allocation fails, the pointer in the returned string will be NULL
. Depending on the allocator, errno
might be set.
alloc | (CxAllocator* ) the allocator to use |
count | (size_t ) the number of the other following strings to concatenate |
... | all other UCX strings |
cxmutstr
) the concatenated string #define cx_strcat_m | ( | str, | |
count, | |||
... ) cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) |
Concatenates strings.
The resulting string will be allocated by standard malloc()
. So developers must pass the return value to cx_strfree() eventually.
If str
already contains a string, the memory will be reallocated and the other strings are appended. Otherwise, new memory is allocated.
If memory allocation fails, the pointer in the returned string will be NULL
and errno
might be set.
str | (cxmutstr ) the string the other strings shall be concatenated to |
count | (size_t ) the number of the other following strings to concatenate |
... | all other strings |
cxmutstr
) the concatenated string #define cx_strdup | ( | string | ) | cx_strdup_a(cxDefaultAllocator, string) |
Creates a duplicate of the specified string.
The new string will contain a copy allocated by standard malloc()
. So developers must pass the return value to cx_strfree().
string | the string to duplicate |
cxmutstr
) a duplicate of the string #define cx_strdup_a | ( | allocator, | |
string ) cx_strdup_a_((allocator), cx_strcast(string)) |
Creates a duplicate of the specified string.
The new string will contain a copy allocated by allocator
.
allocator | (CxAllocator* ) the allocator to use |
string | the string to duplicate |
cxmutstr
) a duplicate of the string #define cx_strreplace | ( | str, | |
search, | |||
replacement ) cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX) |
Replaces a string with another string.
The returned string will be allocated by malloc()
and is guaranteed to be zero-terminated.
If allocation fails, or the input string is empty, the returned string will be empty.
str | (cxstring ) the string where replacements should be applied |
search | (cxstring ) the string to search for |
replacement | (cxstring ) the replacement string |
cxmutstr
) the resulting string after applying the replacements #define cx_strreplace_a | ( | allocator, | |
str, | |||
search, | |||
replacement ) cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX) |
Replaces a string with another string.
The returned string will be allocated by allocator
and is guaranteed to be zero-terminated.
If allocation fails, or the input string is empty, the returned string will be empty.
allocator | (CxAllocator* ) the allocator to use |
str | (cxstring ) the string where replacements should be applied |
search | (cxstring ) the string to search for |
replacement | (cxstring ) the replacement string |
cxmutstr
) the resulting string after applying the replacements #define cx_strreplacen | ( | str, | |
search, | |||
replacement, | |||
replmax ) cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax) |
Replaces a string with another string.
Replaces at most replmax
occurrences.
The returned string will be allocated by malloc()
and is guaranteed to be zero-terminated.
If allocation fails, or the input string is empty, the returned string will be empty.
str | (cxstring ) the string where replacements should be applied |
search | (cxstring ) the string to search for |
replacement | (cxstring ) the replacement string |
replmax | (size_t ) maximum number of replacements |
cxmutstr
) the resulting string after applying the replacements #define cx_strtod | ( | str, | |
output ) cx_strtod_lc_(cx_strcast(str), output, '.', ",") |
Converts a string to a double precision floating point number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character.
The decimal separator is assumed to be a dot character. The comma character is treated as group separator and ignored during parsing. If you want to choose a different format, use cx_strtof_lc().
str | the string to convert |
output | a pointer to the double variable where the result shall be stored |
zero | success |
non-zero | conversion was not possible |
#define cx_strtod_lc | ( | str, | |
output, | |||
decsep, | |||
groupsep ) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep) |
Converts a string to a double precision floating point number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character.
str | the string to convert |
output | a pointer to the double variable where the result shall be stored |
decsep | the decimal separator |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtof | ( | str, | |
output ) cx_strtof_lc_(cx_strcast(str), output, '.', ",") |
Converts a string to a single precision floating point number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character. It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
The decimal separator is assumed to be a dot character. The comma character is treated as group separator and ignored during parsing. If you want to choose a different format, use cx_strtof_lc().
str | the string to convert |
output | a pointer to the float variable where the result shall be stored |
zero | success |
non-zero | conversion was not possible |
#define cx_strtof_lc | ( | str, | |
output, | |||
decsep, | |||
groupsep ) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep) |
Converts a string to a single precision floating point number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character. It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
str | the string to convert |
output | a pointer to the float variable where the result shall be stored |
decsep | the decimal separator |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi | ( | str, | |
output, | |||
base ) cx_strtoi_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi16 | ( | str, | |
output, | |||
base ) cx_strtoi16_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi16_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi32 | ( | str, | |
output, | |||
base ) cx_strtoi32_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi32_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi64 | ( | str, | |
output, | |||
base ) cx_strtoi64_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi64_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi8 | ( | str, | |
output, | |||
base ) cx_strtoi8_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi8_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoi_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtok | ( | str, | |
delim, | |||
limit ) cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit)) |
Creates a string tokenization context.
str | the string to tokenize |
delim | the delimiter string (must not be empty) |
limit | (size_t ) the maximum number of tokens that shall be returned |
CxStrtokCtx
) a new string tokenization context #define cx_strtol | ( | str, | |
output, | |||
base ) cx_strtol_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtol_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtol_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoll | ( | str, | |
output, | |||
base ) cx_strtoll_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoll_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtos | ( | str, | |
output, | |||
base ) cx_strtos_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtos_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtos_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou | ( | str, | |
output, | |||
base ) cx_strtou_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou16 | ( | str, | |
output, | |||
base ) cx_strtou16_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou16_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou32 | ( | str, | |
output, | |||
base ) cx_strtou32_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou32_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou64 | ( | str, | |
output, | |||
base ) cx_strtou64_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou64_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou8 | ( | str, | |
output, | |||
base ) cx_strtou8_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou8_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtou_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtou_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoul | ( | str, | |
output, | |||
base ) cx_strtoul_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoul_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoull | ( | str, | |
output, | |||
base ) cx_strtoull_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoull_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtous | ( | str, | |
output, | |||
base ) cx_strtous_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtous_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtous_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoz | ( | str, | |
output, | |||
base ) cx_strtoz_lc_(cx_strcast(str), output, base, ",") |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
The comma character is treated as group separator and ignored during parsing. If you want to choose the set of group separators, use the _lc
variant of this function (e.g. cx_strtoz_lc()).
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
zero | success |
non-zero | conversion was not possible |
#define cx_strtoz_lc | ( | str, | |
output, | |||
base, | |||
groupsep ) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | (const char* ) each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
cxmutstr cx_mutstr | ( | char * | cstring | ) |
Wraps a mutable string that must be zero-terminated.
The length is implicitly inferred by using a call to strlen()
.
If you need to wrap a constant string, use cx_str().
cstring | the string to wrap, must be zero-terminated |
cxmutstr cx_mutstrn | ( | char * | cstring, |
size_t | length ) |
Wraps a string that does not need to be zero-terminated.
The argument may be NULL
if the length is zero.
If you need to wrap a constant string, use cx_strn().
cstring | the string to wrap (or NULL , only if the length is zero) |
length | the length of the string |
cxstring cx_str | ( | const char * | cstring | ) |
Wraps a string that must be zero-terminated.
The length is implicitly inferred by using a call to strlen()
.
If you need to wrap a non-constant string, use cx_mutstr().
cstring | the string to wrap, must be zero-terminated |
Compares two strings ignoring case.
s1 | the first string |
s2 | the second string |
s1
is smaller than s2
, positive if s1
is larger than s2
, zero if both strings equal ignoring case int cx_strcasecmp_p | ( | const void * | s1, |
const void * | s2 ) |
Compares two strings ignoring case.
This function has a compatible signature for the use as a cx_compare_func.
s1 | the first string |
s2 | the second string |
s1
is smaller than s2
, positive if s1
is larger than s2
, zero if both strings equal ignoring case Checks, if a string has a specific prefix, ignoring the case.
string | the string to check |
prefix | the prefix the string should have |
true
, if and only if the string has the specified prefix, false
otherwise Checks, if a string has a specific suffix, ignoring the case.
string | the string to check |
suffix | the suffix the string should have |
true
, if and only if the string has the specified suffix, false
otherwise cxmutstr cx_strcat_ma | ( | const CxAllocator * | alloc, |
cxmutstr | str, | ||
size_t | count, | ||
... ) |
Concatenates strings.
The resulting string will be allocated by the specified allocator. So developers must pass the return value to cx_strfree_a() eventually.
If str
already contains a string, the memory will be reallocated and the other strings are appended. Otherwise, new memory is allocated.
If memory allocation fails, the pointer in the returned string will be NULL
. Depending on the allocator, errno
might be set.
alloc | the allocator to use |
str | the string the other strings shall be concatenated to |
count | the number of the other following strings to concatenate |
... | all other UCX strings |
Returns a substring starting at the location of the first occurrence of the specified character.
If the string does not contain the character, an empty string is returned.
string | the string where to locate the character |
chr | the character to locate |
chr
Returns a substring starting at the location of the first occurrence of the specified character.
If the string does not contain the character, an empty string is returned.
string | the string where to locate the character |
chr | the character to locate |
chr
Compares two strings.
s1 | the first string |
s2 | the second string |
s1
is smaller than s2
, positive if s1
is larger than s2
, zero if both strings equal int cx_strcmp_p | ( | const void * | s1, |
const void * | s2 ) |
Compares two strings.
This function has a compatible signature for the use as a cx_compare_func.
s1 | the first string |
s2 | the second string |
s1
is smaller than s2
, positive if s1
is larger than s2
, zero if both strings equal cxmutstr cx_strdup_a_ | ( | const CxAllocator * | allocator, |
cxstring | string ) |
Creates a duplicate of the specified string.
The new string will contain a copy allocated by allocator
.
allocator | the allocator to use |
string | the string to duplicate |
void cx_strfree | ( | cxmutstr * | str | ) |
Passes the pointer in this string to free()
.
The pointer in the struct is set to NULL
and the length is set to zero which means that this function protects you against double-free.
const char*
you are really supposed to free. If you encounter such situation, you should double-check your code.str | the string to free |
void cx_strfree_a | ( | const CxAllocator * | alloc, |
cxmutstr * | str ) |
Passes the pointer in this string to the allocators free function.
The pointer in the struct is set to NULL
and the length is set to zero which means that this function protects you against double-free.
const char*
you are really supposed to free. If you encounter such situation, you should double-check your code.alloc | the allocator |
str | the string to free |
size_t cx_strlen | ( | size_t | count, |
... ) |
Returns the accumulated length of all specified strings.
If this sum overflows, errno is set to EOVERFLOW.
count | the total number of specified strings |
... | all strings |
cxstring cx_strn | ( | const char * | cstring, |
size_t | length ) |
Wraps a string that does not need to be zero-terminated.
The argument may be NULL
if the length is zero.
If you need to wrap a non-constant string, use cx_mutstrn().
cstring | the string to wrap (or NULL , only if the length is zero) |
length | the length of the string |
Checks, if a string has a specific prefix.
string | the string to check |
prefix | the prefix the string should have |
true
, if and only if the string has the specified prefix, false
otherwise Returns a substring starting at the location of the last occurrence of the specified character.
If the string does not contain the character, an empty string is returned.
string | the string where to locate the character |
chr | the character to locate |
chr
Returns a substring starting at the location of the last occurrence of the specified character.
If the string does not contain the character, an empty string is returned.
string | the string where to locate the character |
chr | the character to locate |
chr
cxmutstr cx_strreplacen_a | ( | const CxAllocator * | allocator, |
cxstring | str, | ||
cxstring | search, | ||
cxstring | replacement, | ||
size_t | replmax ) |
Replaces a string with another string.
Replaces at most replmax
occurrences.
The returned string will be allocated by allocator
and is guaranteed to be zero-terminated.
If allocation fails, or the input string is empty, the returned string will be empty.
allocator | the allocator to use |
str | the string where replacements should be applied |
search | the string to search for |
replacement | the replacement string |
replmax | maximum number of replacements |
Splits a given string using a delimiter string.
string
. Use cx_strdup() to get copies.string | the string to split |
delim | the delimiter |
limit | the maximum number of split items |
output | a preallocated array of at least limit length |
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.
The array pointed to by output
will be allocated by allocator
.
string
. Use cx_strdup() to get copies.NULL
pointer will be written to output
and the number returned will be zero.allocator | the allocator to use for allocating the resulting array |
string | the string to split |
delim | the delimiter |
limit | the maximum number of split items |
output | a pointer where the address of the allocated array shall be written to |
Splits a given string using a delimiter string.
string
. Use cx_strdup() to get copies.string | the string to split |
delim | the delimiter |
limit | the maximum number of split items |
output | a preallocated array of at least limit length |
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.
The array pointed to by output
will be allocated by allocator
.
string
. Use cx_strdup() to get copies.NULL
pointer will be written to output
and the number returned will be zero.allocator | the allocator to use for allocating the resulting array |
string | the string to split |
delim | the delimiter |
limit | the maximum number of split items |
output | a pointer where the address of the allocated array shall be written to |
Returns a substring starting at the location of the first occurrence of the specified string.
If haystack
does not contain needle
, an empty string is returned.
If needle
is an empty string, the complete haystack
is returned.
haystack | the string to be scanned |
needle | string containing the sequence of characters to match |
needle
, or an empty string, if the sequence is not contained Returns a substring starting at the location of the first occurrence of the specified string.
If haystack
does not contain needle
, an empty string is returned.
If needle
is an empty string, the complete haystack
is returned.
haystack | the string to be scanned |
needle | string containing the sequence of characters to match |
needle
, or an empty string, if the sequence is not contained Returns a substring starting at the specified location.
string | input string |
start | start location of the substring |
string
starting at start
Returns a substring starting at the specified location.
string | input string |
start | start location of the substring |
string
starting at start
Returns a substring starting at the specified location.
The returned string will be limited to length
bytes or the number of bytes available in string
, whichever is smaller.
string | input string |
start | start location of the substring |
length | the maximum length of the returned string |
string
starting at start
Returns a substring starting at the specified location.
The returned string will be limited to length
bytes or the number of bytes available in string
, whichever is smaller.
string | input string |
start | start location of the substring |
length | the maximum length of the returned string |
string
starting at start
Checks, if a string has a specific suffix.
string | the string to check |
suffix | the suffix the string should have |
true
, if and only if the string has the specified suffix, false
otherwise int cx_strtod_lc_ | ( | cxstring | str, |
double * | output, | ||
char | decsep, | ||
const char * | groupsep ) |
Converts a string to a double precision floating point number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character. It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
str | the string to convert |
output | a pointer to the float variable where the result shall be stored |
decsep | the decimal separator |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtof_lc_ | ( | cxstring | str, |
float * | output, | ||
char | decsep, | ||
const char * | groupsep ) |
Converts a string to a single precision floating point number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character. It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
str | the string to convert |
output | a pointer to the float variable where the result shall be stored |
decsep | the decimal separator |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoi16_lc_ | ( | cxstring | str, |
int16_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoi32_lc_ | ( | cxstring | str, |
int32_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoi64_lc_ | ( | cxstring | str, |
int64_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoi8_lc_ | ( | cxstring | str, |
int8_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoi_lc_ | ( | cxstring | str, |
int * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
CxStrtokCtx cx_strtok_ | ( | cxstring | str, |
cxstring | delim, | ||
size_t | limit ) |
Creates a string tokenization context.
str | the string to tokenize |
delim | the delimiter (must not be empty) |
limit | the maximum number of tokens that shall be returned |
void cx_strtok_delim | ( | CxStrtokCtx * | ctx, |
const cxstring * | delim, | ||
size_t | count ) |
Defines an array of more delimiters for the specified tokenization context.
ctx | the tokenization context |
delim | array of more delimiters |
count | number of elements in the array |
bool cx_strtok_next | ( | CxStrtokCtx * | ctx, |
cxstring * | token ) |
Returns the next token.
The token will point to the source string.
ctx | the tokenization context |
token | a pointer to memory where the next token shall be stored |
bool cx_strtok_next_m | ( | CxStrtokCtx * | ctx, |
cxmutstr * | token ) |
Returns the next token of a mutable string.
The token will point to the source string.
ctx | the tokenization context |
token | a pointer to memory where the next token shall be stored |
int cx_strtol_lc_ | ( | cxstring | str, |
long * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoll_lc_ | ( | cxstring | str, |
long long * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtos_lc_ | ( | cxstring | str, |
short * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtou16_lc_ | ( | cxstring | str, |
uint16_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtou32_lc_ | ( | cxstring | str, |
uint32_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtou64_lc_ | ( | cxstring | str, |
uint64_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtou8_lc_ | ( | cxstring | str, |
uint8_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtou_lc_ | ( | cxstring | str, |
unsigned int * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoul_lc_ | ( | cxstring | str, |
unsigned long * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoull_lc_ | ( | cxstring | str, |
unsigned long long * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtous_lc_ | ( | cxstring | str, |
unsigned short * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
int cx_strtoz_lc_ | ( | cxstring | str, |
size_t * | output, | ||
int | base, | ||
const char * | groupsep ) |
Converts a string to a number.
The function returns non-zero when conversion is not possible. In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. It sets errno to ERANGE when the target datatype is too small.
str | the string to convert |
output | a pointer to the integer variable where the result shall be stored |
base | 2, 8, 10, or 16 |
groupsep | each character in this string is treated as group separator and ignored during conversion |
zero | success |
non-zero | conversion was not possible |
Omits leading and trailing spaces.
string | the string that shall be trimmed |