ucx
UAP Common Extensions
Loading...
Searching...
No Matches
string.h File Reference

Strings that know their length. More...

#include "common.h"
#include "allocator.h"
#include <string.h>

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_NULLSTR   cx_mutstr(NULL)
 Convenience macro for creating a null string.
 
#define CX_SFMT(s)
 Expands a UCX string as printf arguments.
 
#define CX_PRIstr   ".*s"
 Format specifier for a UCX string.
 
#define cx_strcast_m(str)
 Wraps any string into an UCX string.
 
#define cx_strcast_(str)
 internal conversion macro
 
#define cx_strcast(str)
 Converts any string to a cxstring.
 
#define cx_strcpy_a(alloc, dest, src)
 Copies a string.
 
#define cx_strcpy(dest, src)
 Copies a string.
 
#define cx_strcat(str, count, ...)
 Concatenates strings and returns a new string.
 
#define cx_strsubs(string, start)
 Returns a substring starting at the specified location.
 
#define cx_strsubsl(string, start, length)
 Returns a substring starting at the specified location.
 
#define cx_strat(str, index)
 Returns the character at the specified index offset.
 
#define cx_strchr(string, chr)
 Returns a substring starting at the location of the first occurrence of the specified character.
 
#define cx_strrchr(string, chr)
 Returns a substring starting at the location of the last occurrence of the specified character.
 
#define cx_strstr(haystack, needle)
 Returns a substring starting at the location of the first occurrence of the specified string.
 
#define cx_strsplit(string, delim, limit, output)
 Splits a given string using a delimiter string.
 
#define cx_strsplit_a(allocator, string, delim, limit, output)
 Splits a given string using a delimiter string.
 
#define cx_strcmp(s1, s2)
 Compares two strings.
 
#define cx_strcasecmp(s1, s2)
 Compares two strings ignoring case.
 
#define cx_strdup_a(allocator, string)
 Creates a duplicate of the specified string.
 
#define cx_strdup(string)
 Creates a duplicate of the specified string.
 
#define cx_strtrim(string)
 Omits leading and trailing spaces.
 
#define cx_strprefix(string, prefix)
 Checks if a string has a specific prefix.
 
#define cx_strsuffix(string, suffix)
 Checks if a string has a specific suffix.
 
#define cx_strcaseprefix(string, prefix)
 Checks if a string has a specific prefix, ignoring the case.
 
#define cx_strcasesuffix(string, suffix)
 Checks, if a string has a specific suffix, ignoring the case.
 
#define cx_strreplacen_a(allocator, str, search, replacement, replmax)
 Replaces a string with another string.
 
#define cx_strreplacen(str, search, replacement, replmax)
 Replaces a string with another string.
 
#define cx_strreplace_a(allocator, str, search, replacement)
 Replaces a string with another string.
 
#define cx_strreplace(str, search, replacement)
 Replaces a string with another string.
 
#define cx_strtok(str, delim, limit)
 Creates a string tokenization context.
 
#define cx_strtok_next(ctx, token)
 Returns the next token.
 
#define cx_strtos_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoi_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtol_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoll_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoi8_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoi16_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoi32_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoi64_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtous_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtou_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoul_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoull_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtou8_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtou16_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtou32_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtou64_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtoz_lc(str, output, base, groupsep)
 Converts a string to a number.
 
#define cx_strtos(str, output, base)
 Converts a string to a number.
 
#define cx_strtoi(str, output, base)
 Converts a string to a number.
 
#define cx_strtol(str, output, base)
 Converts a string to a number.
 
#define cx_strtoll(str, output, base)
 Converts a string to a number.
 
#define cx_strtoi8(str, output, base)
 Converts a string to a number.
 
#define cx_strtoi16(str, output, base)
 Converts a string to a number.
 
#define cx_strtoi32(str, output, base)
 Converts a string to a number.
 
#define cx_strtoi64(str, output, base)
 Converts a string to a number.
 
#define cx_strtoz(str, output, base)
 Converts a string to a number.
 
#define cx_strtous(str, output, base)
 Converts a string to a number.
 
#define cx_strtou(str, output, base)
 Converts a string to a number.
 
#define cx_strtoul(str, output, base)
 Converts a string to a number.
 
#define cx_strtoull(str, output, base)
 Converts a string to a number.
 
#define cx_strtou8(str, output, base)
 Converts a string to a number.
 
#define cx_strtou16(str, output, base)
 Converts a string to a number.
 
#define cx_strtou32(str, output, base)
 Converts a string to a number.
 
#define cx_strtou64(str, output, base)
 Converts a string to a number.
 
#define cx_strtof_lc(str, output, decsep, groupsep)
 Converts a string to a single precision floating-point number.
 
#define cx_strtod_lc(str, output, decsep, groupsep)
 Converts a string to a double precision floating-point number.
 
#define cx_strtof(str, output)
 Converts a string to a single precision floating-point number.
 
#define cx_strtod(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

static cxmutstr cx_mutstr (char *cstring)
 Wraps a mutable string that must be zero-terminated.
 
static cxmutstr cx_mutstrn (char *cstring, size_t length)
 Wraps a string that does not need to be zero-terminated.
 
static cxstring cx_str (const char *cstring)
 Wraps a string that must be zero-terminated.
 
static cxstring cx_strn (const char *cstring, size_t length)
 Wraps a string that does not need to be zero-terminated.
 
static cxmutstr cx_strcast_cxms (cxmutstr str)
 Internal function, do not use.
 
static cxstring cx_strcast_cxs (cxstring str)
 Internal function, do not use.
 
static cxmutstr cx_strcast_uc (unsigned char *str)
 Internal function, do not use.
 
static cxmutstr cx_strcast_c (char *str)
 Internal function, do not use.
 
static cxstring cx_strcast_ucc (const unsigned char *str)
 Internal function, do not use.
 
static cxstring cx_strcast_cc (const char *str)
 Internal function, do not use.
 
static cxstring cx_strcast_1 (cxmutstr str)
 Internal function, do not use.
 
static cxstring cx_strcast_2 (cxstring str)
 Internal function, do not use.
 
static cxmutstr cx_mutstrcast (cxstring str)
 Casts away constness and converts a cxstring to a cxmutstr.
 
void cx_strfree (cxmutstr *str)
 Passes the pointer in this string to the cxDefaultAllocator's free() function.
 
void cx_strfree_a (const CxAllocator *alloc, cxmutstr *str)
 Passes the pointer in this string to the allocator's free function.
 
int cx_strcpy_a_ (const CxAllocator *alloc, cxmutstr *dest, cxstring src)
 Copies a string.
 
size_t cx_strlen (size_t count,...)
 Returns the accumulated length of all specified strings.
 
cxmutstr cx_strcat_a (const CxAllocator *alloc, cxmutstr str, size_t count,...)
 Concatenates strings.
 
cxstring cx_strsubsl_ (cxstring string, size_t start, size_t length)
 Returns a substring.
 
cxstring cx_strsubs_ (cxstring string, size_t start)
 Returns a substring.
 
static cxmutstr cx_strsubs_m_ (cxmutstr string, size_t start)
 Internal conversion function - do not use.
 
static cxmutstr cx_strsubsl_m_ (cxmutstr string, size_t start, size_t length)
 Internal conversion function - do not use.
 
static char cx_strat_ (cxstring str, off_t index)
 Returns the character at the specified index offset.
 
cxstring cx_strchr_ (cxstring string, int chr)
 Searches for a character in a string.
 
cxstring cx_strrchr_ (cxstring string, int chr)
 Searches for a character in a string.
 
static cxmutstr cx_strchr_m_ (cxmutstr string, int chr)
 Internal conversion function - do not use.
 
static cxmutstr cx_strrchr_m_ (cxmutstr string, int chr)
 Internal conversion function - do not use.
 
cxstring cx_strstr_ (cxstring haystack, cxstring needle)
 Searches for a specific substring.
 
static cxmutstr cx_strstr_m_ (cxmutstr haystack, cxstring needle)
 Internal conversion - do not use.
 
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)
 Trims a string.
 
static cxmutstr cx_strtrim_m_ (cxmutstr string)
 Internal conversion function.
 
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_strreplace_ (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.
 
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.
 

Detailed Description

Strings that know their length.

Author
Mike Becker
Olaf Wintermann

Macro Definition Documentation

◆ CX_SFMT

#define CX_SFMT ( s)
Value:
(int) (s).length, (s).ptr

Expands a UCX string as printf arguments.

◆ cx_strat

#define cx_strat ( str,
index )
Value:
cx_strat_(cx_strcast(str), index)
#define cx_strcast(str)
Converts any string to a cxstring.
Definition string.h:393
static char cx_strat_(cxstring str, off_t index)
Returns the character at the specified index offset.
Definition string.h:661

Returns the character at the specified index offset.

When the index is negative, the character is counted from the end of the string where -1 denotes the last character in the string.

When the index is out of bounds, the function returns zero.

Parameters
strthe string
indexthe index offset
Returns
the character at the index
See also
cx_strat()

◆ cx_strcasecmp

#define cx_strcasecmp ( s1,
s2 )
Value:
int cx_strcasecmp_(cxstring s1, cxstring s2)
Compares two strings ignoring case.

Compares two strings ignoring case.

Parameters
s1the first string
s2the second string
Returns
negative if s1 is smaller than s2, positive if s1 is larger than s2, zero if both strings equal ignoring case

◆ cx_strcaseprefix

#define cx_strcaseprefix ( string,
prefix )
Value:
bool cx_strcaseprefix_(cxstring string, cxstring prefix)
Checks if a string has a specific prefix, ignoring the case.

Checks if a string has a specific prefix, ignoring the case.

Parameters
stringthe string to check
prefixthe prefix the string should have
Returns
true, if and only if the string has the specified prefix, false otherwise

◆ cx_strcasesuffix

#define cx_strcasesuffix ( string,
suffix )
Value:
bool cx_strcasesuffix_(cxstring string, cxstring suffix)
Checks, if a string has a specific suffix, ignoring the case.

Checks, if a string has a specific suffix, ignoring the case.

Parameters
stringthe string to check
suffixthe suffix the string should have
Returns
true, if and only if the string has the specified suffix, false otherwise

◆ cx_strcast

#define cx_strcast ( str)
Value:
#define cx_strcast_(str)
internal conversion macro
Definition string.h:383
#define cx_strcast_m(str)
Wraps any string into an UCX string.
Definition string.h:356

Converts any string to a cxstring.

Parameters
str(any supported string type) the string to cast
Returns
he string converted to a (cxstring)

◆ cx_strcast_

#define cx_strcast_ ( str)
Value:
_Generic((str), \
static cxstring cx_strcast_1(cxmutstr str)
Internal function, do not use.
Definition string.h:369
struct cx_string_s cxstring
An immutable string.
Definition string.h:92
struct cx_mutstr_s cxmutstr
A mutable string.
Definition string.h:74
static cxstring cx_strcast_2(cxstring str)
Internal function, do not use.
Definition string.h:378

internal conversion macro

◆ cx_strcast_m

#define cx_strcast_m ( str)
Value:
_Generic((str), \
const unsigned char*: cx_strcast_ucc, \
unsigned char *: cx_strcast_uc, \
const char*: cx_strcast_cc, \
char *: cx_strcast_c) (str)
static cxstring cx_strcast_cxs(cxstring str)
Internal function, do not use.
Definition string.h:298
static cxmutstr cx_strcast_uc(unsigned char *str)
Internal function, do not use.
Definition string.h:310
static cxmutstr cx_strcast_cxms(cxmutstr str)
Internal function, do not use.
Definition string.h:287
static cxstring cx_strcast_ucc(const unsigned char *str)
Internal function, do not use.
Definition string.h:334
static cxmutstr cx_strcast_c(char *str)
Internal function, do not use.
Definition string.h:322
static cxstring cx_strcast_cc(const char *str)
Internal function, do not use.
Definition string.h:346

Wraps any string into an UCX string.

Parameters
str(any supported string type) the string to cast
Returns
(cxstring) or (cxmutstr) the string wrapped as UCX string

◆ cx_strcat

#define cx_strcat ( str,
count,
... )
Value:
cx_strcat_a(cxDefaultAllocator, str, count, __VA_ARGS__)
const CxAllocator * cxDefaultAllocator
The default allocator that is used by UCX.
cxmutstr cx_strcat_a(const CxAllocator *alloc, cxmutstr str, size_t count,...)
Concatenates strings.

Concatenates strings and returns a new string.

The resulting string will be allocated by the cxDefaultAllocator. So developers must pass the return value to cx_strfree() eventually.

Note
It is guaranteed that there is only one allocation for the resulting string. It is also guaranteed that the returned string is zero-terminated. If allocation fails, the ptr in the returned string will be NULL.
Parameters
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 UCX strings
Returns
the concatenated string

◆ cx_strchr

#define cx_strchr ( string,
chr )
Value:
_Generic(cx_strcast_m(string), \
cxstring cx_strchr_(cxstring string, int chr)
Searches for a character in a string.
static cxmutstr cx_strchr_m_(cxmutstr string, int chr)
Internal conversion function - do not use.
Definition string.h:733

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.

Parameters
stringthe string where to locate the character
chr(int) the character to locate
Returns
(cxstring or cxmutstr) a substring starting at the first location of chr

◆ cx_strcmp

#define cx_strcmp ( s1,
s2 )
Value:
int cx_strcmp_(cxstring s1, cxstring s2)
Compares two strings.

Compares two strings.

Parameters
s1the first string
s2the second string
Returns
negative if s1 is smaller than s2, positive if s1 is larger than s2, zero if both strings equal

◆ cx_strcpy

#define cx_strcpy ( dest,
src )
Value:
#define cx_strcpy_a(alloc, dest, src)
Copies a string.
Definition string.h:470

Copies a string.

The memory in the dest structure is either allocated or re-allocated to fit the entire source string, including a zero-terminator.

The string in dest is guaranteed to be zero-terminated, regardless of whether src is.

Parameters
dest(cxmutstr*) a pointer to the structure where to copy the contents to
srcthe source string
Return values
zerosuccess
non-zeroif re-allocation failed

◆ cx_strcpy_a

#define cx_strcpy_a ( alloc,
dest,
src )
Value:
cx_strcpy_a_(alloc, dest, cx_strcast(src))
int cx_strcpy_a_(const CxAllocator *alloc, cxmutstr *dest, cxstring src)
Copies a string.

Copies a string.

The memory in the dest structure is either allocated or re-allocated to fit the entire source string, including a zero-terminator.

The string in dest is guaranteed to be zero-terminated, regardless of whether src is.

Parameters
alloc(CxAllocator*) the allocator
dest(cxmutstr*) a pointer to the structure where to copy the contents to
srcthe source string
Return values
zerosuccess
non-zeroif re-allocation failed

◆ cx_strdup

#define cx_strdup ( string)
Value:
#define cx_strdup_a(allocator, string)
Creates a duplicate of the specified string.
Definition string.h:1064

Creates a duplicate of the specified string.

The new string will contain a copy allocated by the cxDefaultAllocator. So developers must pass the return value to cx_strfree().

Note
The returned string is guaranteed to be zero-terminated.
Parameters
stringthe string to duplicate
Returns
(cxmutstr) a duplicate of the string
See also
cx_strdup_a()
cx_strfree()

◆ cx_strdup_a

#define cx_strdup_a ( allocator,
string )
Value:
cx_strdup_a_((allocator), cx_strcast(string))
cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string)
Creates a duplicate of the specified string.

Creates a duplicate of the specified string.

The new string will contain a copy allocated by allocator.

Note
The returned string is guaranteed to be zero-terminated.
Parameters
allocator(CxAllocator*) the allocator to use
stringthe string to duplicate
Returns
(cxmutstr) a duplicate of the string
See also
cx_strdup()
cx_strfree_a()

◆ cx_strprefix

#define cx_strprefix ( string,
prefix )
Value:
bool cx_strprefix_(cxstring string, cxstring prefix)
Checks if a string has a specific prefix.

Checks if a string has a specific prefix.

Parameters
stringthe string to check
prefixthe prefix the string should have
Returns
true, if and only if the string has the specified prefix, false otherwise

◆ cx_strrchr

#define cx_strrchr ( string,
chr )
Value:
_Generic(cx_strcast_m(string), \
static cxmutstr cx_strrchr_m_(cxmutstr string, int chr)
Internal conversion function - do not use.
Definition string.h:742
cxstring cx_strrchr_(cxstring string, int chr)
Searches for a character in a string.

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.

Parameters
stringthe string where to locate the character
chr(int) the character to locate
Returns
(cxstring or cxmutstr) a substring starting at the last location of chr

◆ cx_strreplace

#define cx_strreplace ( str,
search,
replacement )
Value:
cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX)
#define cx_strreplacen_a(allocator, str, search, replacement, replmax)
Replaces a string with another string.
Definition string.h:1244

Replaces a string with another string.

The returned string will be allocated by the cxDefaultAllocator and is guaranteed to be zero-terminated.

If allocation fails, or the input string is empty, the returned string will be empty.

Parameters
strthe string where replacements should be applied
searchthe string to search for
replacementthe replacement string
Returns
(cxmutstr) the resulting string after applying the replacements

◆ cx_strreplace_a

#define cx_strreplace_a ( allocator,
str,
search,
replacement )
Value:
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.

Parameters
allocator(CxAllocator*) the allocator to use
strthe string where replacements should be applied
searchthe string to search for
replacementthe replacement string
Returns
(cxmutstr) the resulting string after applying the replacements

◆ cx_strreplacen

#define cx_strreplacen ( str,
search,
replacement,
replmax )
Value:
cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax)

Replaces a string with another string.

The function replaces at most replmax occurrences.

The returned string will be allocated by the cxDefaultAllocator and is guaranteed to be zero-terminated.

If allocation fails, or the input string is empty, the returned string will be empty.

Parameters
strthe string where replacements should be applied
searchthe string to search for
replacementthe replacement string
replmax(size_t) maximum number of replacements
Returns
(cxmutstr) the resulting string after applying the replacements

◆ cx_strreplacen_a

#define cx_strreplacen_a ( allocator,
str,
search,
replacement,
replmax )
Value:
cx_strreplace_(allocator, cx_strcast(str), cx_strcast(search), cx_strcast(replacement), replmax)
cxmutstr cx_strreplace_(const CxAllocator *allocator, cxstring str, cxstring search, cxstring replacement, size_t replmax)
Replaces a string with another string.

Replaces a string with another string.

The function 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.

Parameters
allocator(CxAllocator*) the allocator to use
strthe string where replacements should be applied
searchthe string to search for
replacementthe replacement string
replmax(size_t) maximum number of replacements
Returns
(cxmutstr) the resulting string after applying the replacements

◆ cx_strsplit

#define cx_strsplit ( string,
delim,
limit,
output )
Value:
_Generic(cx_strcast_m(string), \
(cx_strcast_m(string), cx_strcast(delim), limit, output)
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_m_(cxmutstr string, cxstring delim, size_t limit, cxmutstr *output)
Splits a given string using a delimiter string.

Splits a given string using a delimiter string.

Note
The resulting array contains strings that point to the source string. Use cx_strdup() to get copies.
Parameters
stringthe string to split
delimthe delimiter
limit(size_t) the maximum number of split items
output(cxstring* or cxmutstr*) a preallocated array of at least limit length
Returns
the actual number of split items

◆ cx_strsplit_a

#define cx_strsplit_a ( allocator,
string,
delim,
limit,
output )
Value:
_Generic(cx_strcast_m(string), \
(allocator, cx_strcast_m(string), cx_strcast(delim), limit, output)
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_ma_(const CxAllocator *allocator, cxmutstr string, cxstring delim, size_t limit, cxmutstr **output)
Splits a given string using a delimiter string.

Splits a given string using a delimiter string.

The array pointed to by output will be allocated by allocator.

Note
The resulting array contains strings that point to the source string. Use cx_strdup() to get copies.
Attention
If allocation fails, the NULL pointer will be written to output and the number returned will be zero.
Parameters
allocator(CxAllocator*) the allocator to use for allocating the resulting array
stringthe string to split
delimthe delimiter
limit(size_t) the maximum number of split items
output(cxstring** or cxmutstr**) a pointer where the address of the allocated array shall be written to
Returns
the actual number of split items

◆ cx_strstr

#define cx_strstr ( haystack,
needle )
Value:
_Generic(cx_strcast_m(haystack), \
static cxmutstr cx_strstr_m_(cxmutstr haystack, cxstring needle)
Internal conversion - do not use.
Definition string.h:806
cxstring cx_strstr_(cxstring haystack, cxstring needle)
Searches for a specific substring.

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.

Parameters
haystackthe string to be scanned
needlestring containing the sequence of characters to match
Returns
(cxstring or cxmutstr) a substring starting at the first occurrence of needle, or an empty string, if the sequence is not contained

◆ cx_strsubs

#define cx_strsubs ( string,
start )
Value:
_Generic(cx_strcast_m(string), \
cxstring cx_strsubs_(cxstring string, size_t start)
Returns a substring.
static cxmutstr cx_strsubs_m_(cxmutstr string, size_t start)
Internal conversion function - do not use.
Definition string.h:579

Returns a substring starting at the specified location.

Attention
the new string references the same memory area as the input string and is not zero-terminated. Use cx_strdup() to get a copy.
Parameters
stringinput string
start(size_t) start location of the substring
Returns
(cxstring or cxmutstr) a substring of string starting at start
See also
cx_strsubsl()

◆ cx_strsubsl

#define cx_strsubsl ( string,
start,
length )
Value:
_Generic(cx_strcast_m(string), \
cxmutstr: cx_strsubsl_m_)(cx_strcast_m(string), start, length)
cxstring cx_strsubsl_(cxstring string, size_t start, size_t length)
Returns a substring.
static cxmutstr cx_strsubsl_m_(cxmutstr string, size_t start, size_t length)
Internal conversion function - do not use.
Definition string.h:591

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.

Attention
the new string references the same memory area as the input string and is usually not zero-terminated. Use cx_strdup() to get a copy.
Parameters
stringinput string
startstart location of the substring
lengththe maximum length of the returned string
Returns
a substring of string starting at start
See also
cx_strsubs()

◆ cx_strsuffix

#define cx_strsuffix ( string,
suffix )
Value:
bool cx_strsuffix_(cxstring string, cxstring suffix)
Checks if a string has a specific suffix.

Checks if a string has a specific suffix.

Parameters
stringthe string to check
suffixthe suffix the string should have
Returns
true, if and only if the string has the specified suffix, false otherwise

◆ cx_strtod

#define cx_strtod ( str,
output )
Value:
cx_strtod_lc_(cx_strcast(str), output, '.', ",")
int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep)
Converts a string to a double precision floating-point number.

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 a group separator and ignored during parsing. If you want to choose a different format, use cx_strtof_lc().

Parameters
strthe string to convert
outputa pointer to the double variable where the result shall be stored
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtod_lc

#define cx_strtod_lc ( str,
output,
decsep,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the double variable where the result shall be stored
decsepthe decimal separator
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtof

#define cx_strtof ( str,
output )
Value:
cx_strtof_lc_(cx_strcast(str), output, '.', ",")
int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep)
Converts a string to a single precision floating-point number.

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 a group separator and ignored during parsing. If you want to choose a different format, use cx_strtof_lc().

Parameters
strthe string to convert
outputa pointer to the float variable where the result shall be stored
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtof_lc

#define cx_strtof_lc ( str,
output,
decsep,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the float variable where the result shall be stored
decsepthe decimal separator
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi

#define cx_strtoi ( str,
output,
base )
Value:
cx_strtoi_lc_(cx_strcast(str), output, base, ",")
int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi16

#define cx_strtoi16 ( str,
output,
base )
Value:
cx_strtoi16_lc_(cx_strcast(str), output, base, ",")
int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi16_lc

#define cx_strtoi16_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi32

#define cx_strtoi32 ( str,
output,
base )
Value:
cx_strtoi32_lc_(cx_strcast(str), output, base, ",")
int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi32_lc

#define cx_strtoi32_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi64

#define cx_strtoi64 ( str,
output,
base )
Value:
cx_strtoi64_lc_(cx_strcast(str), output, base, ",")
int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi64_lc

#define cx_strtoi64_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi8

#define cx_strtoi8 ( str,
output,
base )
Value:
cx_strtoi8_lc_(cx_strcast(str), output, base, ",")
int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi8_lc

#define cx_strtoi8_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi_lc

#define cx_strtoi_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtok

#define cx_strtok ( str,
delim,
limit )
Value:
cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit))
CxStrtokCtx cx_strtok_(cxstring str, cxstring delim, size_t limit)
Creates a string tokenization context.

Creates a string tokenization context.

Parameters
strthe string to tokenize
delimthe delimiter string (must not be empty)
limit(size_t) the maximum number of tokens that shall be returned
Returns
(CxStrtokCtx) a new string tokenization context

◆ cx_strtok_next

#define cx_strtok_next ( ctx,
token )
Value:
_Generic((token), \
bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token)
Returns the next token.

Returns the next token.

The token will point to the source string.

Parameters
ctx(CxStrtokCtx*) the tokenization context
tokena pointer to either a cxstring or cxmutstr where the next token shall be stored
Returns
true if successful, false if the limit or the end of the string has been reached

◆ cx_strtol

#define cx_strtol ( str,
output,
base )
Value:
cx_strtol_lc_(cx_strcast(str), output, base, ",")
int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtol_lc

#define cx_strtol_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoll

#define cx_strtoll ( str,
output,
base )
Value:
cx_strtoll_lc_(cx_strcast(str), output, base, ",")
int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoll_lc

#define cx_strtoll_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtos

#define cx_strtos ( str,
output,
base )
Value:
cx_strtos_lc_(cx_strcast(str), output, base, ",")
int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtos_lc

#define cx_strtos_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou

#define cx_strtou ( str,
output,
base )
Value:
cx_strtou_lc_(cx_strcast(str), output, base, ",")
int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou16

#define cx_strtou16 ( str,
output,
base )
Value:
cx_strtou16_lc_(cx_strcast(str), output, base, ",")
int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou16_lc

#define cx_strtou16_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou32

#define cx_strtou32 ( str,
output,
base )
Value:
cx_strtou32_lc_(cx_strcast(str), output, base, ",")
int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou32_lc

#define cx_strtou32_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou64

#define cx_strtou64 ( str,
output,
base )
Value:
cx_strtou64_lc_(cx_strcast(str), output, base, ",")
int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou64_lc

#define cx_strtou64_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou8

#define cx_strtou8 ( str,
output,
base )
Value:
cx_strtou8_lc_(cx_strcast(str), output, base, ",")
int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou8_lc

#define cx_strtou8_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou_lc

#define cx_strtou_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoul

#define cx_strtoul ( str,
output,
base )
Value:
cx_strtoul_lc_(cx_strcast(str), output, base, ",")
int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoul_lc

#define cx_strtoul_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoull

#define cx_strtoull ( str,
output,
base )
Value:
cx_strtoull_lc_(cx_strcast(str), output, base, ",")
int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoull_lc

#define cx_strtoull_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtous

#define cx_strtous ( str,
output,
base )
Value:
cx_strtous_lc_(cx_strcast(str), output, base, ",")
int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtous_lc

#define cx_strtous_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoz

#define cx_strtoz ( str,
output,
base )
Value:
cx_strtoz_lc_(cx_strcast(str), output, base, ",")
int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep)
Converts a string to a number.

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 a 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()).

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoz_lc

#define cx_strtoz_lc ( str,
output,
base,
groupsep )
Value:
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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsep(const char*) each character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtrim

#define cx_strtrim ( string)
Value:
_Generic(cx_strcast_m(string), \
cxstring cx_strtrim_(cxstring string)
Trims a string.
static cxmutstr cx_strtrim_m_(cxmutstr string)
Internal conversion function.
Definition string.h:1104

Omits leading and trailing spaces.

Note
the returned string references the same memory, thus you must not free the returned memory.
Parameters
stringthe string that shall be trimmed
Returns
(cxstring or cxmutstr) the trimmed string

Function Documentation

◆ cx_mutstr()

static cxmutstr cx_mutstr ( char * cstring)
inlinestatic

Wraps a mutable string that must be zero-terminated.

The length is implicitly inferred by using a call to strlen().

When NULL is passed, the length will be set to zero.

Note
the wrapped string will share the specified pointer to the string. If you do want a copy, use cx_strdup() on the return value of this function.

If you need to wrap a constant string, use cx_str().

Parameters
cstringthe string to wrap (must be zero-terminated)
Returns
the wrapped string
See also
cx_mutstrn()

◆ cx_mutstrcast()

static cxmutstr cx_mutstrcast ( cxstring str)
inlinestatic

Casts away constness and converts a cxstring to a cxmutstr.

For internal use only!

Parameters
str
Returns

◆ cx_mutstrn()

static cxmutstr cx_mutstrn ( char * cstring,
size_t length )
inlinestatic

Wraps a string that does not need to be zero-terminated.

The argument may be NULL if the length is zero.

Note
the wrapped string will share the specified pointer to the string. If you do want a copy, use cx_strdup() on the return value of this function.

If you need to wrap a constant string, use cx_strn().

Parameters
cstringthe string to wrap (or NULL, only if the length is zero)
lengththe length of the string
Returns
the wrapped string
See also
cx_mutstr()

◆ cx_str()

static cxstring cx_str ( const char * cstring)
inlinestatic

Wraps a string that must be zero-terminated.

The length is implicitly inferred by using a call to strlen().

When NULL is passed, the length will be set to zero.

Note
the wrapped string will share the specified pointer to the string. If you do want a copy, use cx_strdup() on the return value of this function.

If you need to wrap a non-constant string, use cx_mutstr().

Parameters
cstringthe string to wrap (must be zero-terminated)
Returns
the wrapped string
See also
cx_strn()

◆ cx_strat_()

static char cx_strat_ ( cxstring str,
off_t index )
inlinestatic

Returns the character at the specified index offset.

Internal function - do not use.

Parameters
strthe string
indexthe index offset
Returns
the character at the index
See also
cx_strat()

◆ cx_strcasecmp_()

int cx_strcasecmp_ ( cxstring s1,
cxstring s2 )

Compares two strings ignoring case.

Parameters
s1the first string
s2the second string
Returns
negative if s1 is smaller than s2, positive if s1 is larger than s2, zero if both strings equal ignoring case

◆ cx_strcasecmp_p()

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.

Parameters
s1the first string
s2the second string
Returns
negative if s1 is smaller than s2, positive if s1 is larger than s2, zero if both strings equal ignoring case

◆ cx_strcaseprefix_()

bool cx_strcaseprefix_ ( cxstring string,
cxstring prefix )

Checks if a string has a specific prefix, ignoring the case.

Parameters
stringthe string to check
prefixthe prefix the string should have
Returns
true, if and only if the string has the specified prefix, false otherwise

◆ cx_strcasesuffix_()

bool cx_strcasesuffix_ ( cxstring string,
cxstring suffix )

Checks, if a string has a specific suffix, ignoring the case.

Parameters
stringthe string to check
suffixthe suffix the string should have
Returns
true, if and only if the string has the specified suffix, false otherwise

◆ cx_strcast_1()

static cxstring cx_strcast_1 ( cxmutstr str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns

◆ cx_strcast_2()

static cxstring cx_strcast_2 ( cxstring str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns

◆ cx_strcast_c()

static cxmutstr cx_strcast_c ( char * str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns
See also
cx_strcast_m()
cx_strcast()

◆ cx_strcast_cc()

static cxstring cx_strcast_cc ( const char * str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns
See also
cx_strcast_m()
cx_strcast()

◆ cx_strcast_cxms()

static cxmutstr cx_strcast_cxms ( cxmutstr str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns
See also
cx_strcast_m()
cx_strcast()

◆ cx_strcast_cxs()

static cxstring cx_strcast_cxs ( cxstring str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns
See also
cx_strcast_m()
cx_strcast()

◆ cx_strcast_uc()

static cxmutstr cx_strcast_uc ( unsigned char * str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns
See also
cx_strcast_m()
cx_strcast()

◆ cx_strcast_ucc()

static cxstring cx_strcast_ucc ( const unsigned char * str)
inlinestatic

Internal function, do not use.

Parameters
str
Returns
See also
cx_strcast_m()
cx_strcast()

◆ cx_strcat_a()

cxmutstr cx_strcat_a ( 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.

Note
It is guaranteed that there is only one allocation for the resulting string. It is also guaranteed that the returned string is zero-terminated. If allocation fails, the ptr in the returned string will be NULL.
Parameters
allocthe allocator to use
strthe string the other strings shall be concatenated to
countthe number of the other following strings to concatenate
...all other UCX strings
Returns
the concatenated string

◆ cx_strchr_()

cxstring cx_strchr_ ( cxstring string,
int chr )

Searches for a character in a string.

Internal function - do not use.

Parameters
string
chr
Returns
See also
cx_strchr()

◆ cx_strchr_m_()

static cxmutstr cx_strchr_m_ ( cxmutstr string,
int chr )
inlinestatic

Internal conversion function - do not use.

Parameters
string
chr
Returns

◆ cx_strcmp_()

int cx_strcmp_ ( cxstring s1,
cxstring s2 )

Compares two strings.

Parameters
s1the first string
s2the second string
Returns
negative if s1 is smaller than s2, positive if s1 is larger than s2, zero if both strings equal

◆ cx_strcmp_p()

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.

Attention
This function can only compare UCX strings. It is unsafe to pass normal C-strings to this function.
Parameters
s1the first string
s2the second string
Returns
negative if s1 is smaller than s2, positive if s1 is larger than s2, zero if both strings equal

◆ cx_strcpy_a_()

int cx_strcpy_a_ ( const CxAllocator * alloc,
cxmutstr * dest,
cxstring src )

Copies a string.

Internal function - do not use.

Parameters
allocthe allocator
desta pointer to the structure where to copy the contents to
srcthe source string
Return values
zerosuccess
non-zeroif re-allocation failed
See also
cx_strcpy_a()

◆ cx_strdup_a_()

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.

Note
The returned string is guaranteed to be zero-terminated.
Parameters
allocatorthe allocator to use
stringthe string to duplicate
Returns
a duplicate of the string
See also
cx_strdup()

◆ cx_strfree()

void cx_strfree ( cxmutstr * str)

Passes the pointer in this string to the cxDefaultAllocator's 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.

Note
There is no implementation for cxstring, because it is unlikely that you ever have a const char* you are really supposed to free. If you encounter such a situation, you should double-check your code.
Parameters
strthe string to free

◆ cx_strfree_a()

void cx_strfree_a ( const CxAllocator * alloc,
cxmutstr * str )

Passes the pointer in this string to the allocator's 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.

Note
There is no implementation for cxstring, because it is unlikely that you ever have a const char* you are really supposed to free. If you encounter such a situation, you should double-check your code.
Parameters
allocthe allocator
strthe string to free

◆ cx_strlen()

size_t cx_strlen ( size_t count,
... )

Returns the accumulated length of all specified strings.

If this sum overflows, errno is set to EOVERFLOW.

Attention
if the count argument is larger than the number of the specified strings, the behavior is undefined.
Parameters
countthe total number of specified strings
...all strings
Returns
the accumulated length of all strings

◆ cx_strn()

static cxstring cx_strn ( const char * cstring,
size_t length )
inlinestatic

Wraps a string that does not need to be zero-terminated.

The argument may be NULL if the length is zero.

Note
the wrapped string will share the specified pointer to the string. If you do want a copy, use cx_strdup() on the return value of this function.

If you need to wrap a non-constant string, use cx_mutstrn().

Parameters
cstringthe string to wrap (or NULL, only if the length is zero)
lengththe length of the string
Returns
the wrapped string
See also
cx_str()

◆ cx_strprefix_()

bool cx_strprefix_ ( cxstring string,
cxstring prefix )

Checks if a string has a specific prefix.

Parameters
stringthe string to check
prefixthe prefix the string should have
Returns
true, if and only if the string has the specified prefix, false otherwise

◆ cx_strrchr_()

cxstring cx_strrchr_ ( cxstring string,
int chr )

Searches for a character in a string.

Internal function - do not use.

Parameters
string
chr
Returns
See also
cx_strrchr()

◆ cx_strrchr_m_()

static cxmutstr cx_strrchr_m_ ( cxmutstr string,
int chr )
inlinestatic

Internal conversion function - do not use.

Parameters
string
chr
Returns

◆ cx_strreplace_()

cxmutstr cx_strreplace_ ( const CxAllocator * allocator,
cxstring str,
cxstring search,
cxstring replacement,
size_t replmax )

Replaces a string with another string.

Internal function - do not use.

Parameters
allocator
str
search
replacement
replmax
Returns
See also
cx_strreplace_a()
cx_strreplace()
cx_strreplacen_a()
cx_strreplacen()

◆ cx_strsplit_()

size_t cx_strsplit_ ( cxstring string,
cxstring delim,
size_t limit,
cxstring * output )

Splits a given string using a delimiter string.

Internal function - do not use.

Parameters
stringthe string to split
delimthe delimiter
limitthe maximum number of split items
outputthe output array
Returns
the actual number of split items
See also
cx_strsplit()

◆ cx_strsplit_a_()

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.

Internal function - do not use.

Parameters
allocatorthe allocator to use for allocating the resulting array
stringthe string to split
delimthe delimiter
limitthe maximum number of split items
outputthe output array
Returns
the actual number of split items
See also
cx_strsplit_a()

◆ cx_strsplit_m_()

size_t cx_strsplit_m_ ( cxmutstr string,
cxstring delim,
size_t limit,
cxmutstr * output )

Splits a given string using a delimiter string.

Internal function - do not use.

Parameters
stringthe string to split
delimthe delimiter
limitthe maximum number of split items
outputthe output array
Returns
the actual number of split items
See also
cx_strsplit_m()

◆ cx_strsplit_ma_()

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.

Internal function - do not use.

Parameters
allocatorthe allocator to use for allocating the resulting array
stringthe string to split
delimthe delimiter
limitthe maximum number of split items
outputthe output array
Returns
the actual number of split items
See also
cx_strsplit_ma()

◆ cx_strstr_()

cxstring cx_strstr_ ( cxstring haystack,
cxstring needle )

Searches for a specific substring.

Internal function - do not use.

Parameters
haystackthe string to be scanned
needlestring containing the sequence of characters to match
Returns
a substring starting at the first occurrence of needle, or an empty string, if the sequence is not contained
See also
cx_strstr()

◆ cx_strstr_m_()

static cxmutstr cx_strstr_m_ ( cxmutstr haystack,
cxstring needle )
inlinestatic

Internal conversion - do not use.

Parameters
haystack
needle
Returns

◆ cx_strsubs_()

cxstring cx_strsubs_ ( cxstring string,
size_t start )

Returns a substring.

Internal function - do not use.

Parameters
stringinput string
startstart location of the substring
Returns
a substring of string starting at start
See also
cx_strsubs()

◆ cx_strsubs_m_()

static cxmutstr cx_strsubs_m_ ( cxmutstr string,
size_t start )
inlinestatic

Internal conversion function - do not use.

Parameters
string
start
Returns

◆ cx_strsubsl_()

cxstring cx_strsubsl_ ( cxstring string,
size_t start,
size_t length )

Returns a substring.

Internal function - do not use.

Parameters
stringinput string
startstart location of the substring
lengththe maximum length of the returned string
Returns
a substring of string starting at start
See also
cx_strsubsl()

◆ cx_strsubsl_m_()

static cxmutstr cx_strsubsl_m_ ( cxmutstr string,
size_t start,
size_t length )
inlinestatic

Internal conversion function - do not use.

Parameters
string
start
length
Returns

◆ cx_strsuffix_()

bool cx_strsuffix_ ( cxstring string,
cxstring suffix )

Checks if a string has a specific suffix.

Parameters
stringthe string to check
suffixthe suffix the string should have
Returns
true, if and only if the string has the specified suffix, false otherwise

◆ cx_strtod_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the float variable where the result shall be stored
decsepthe decimal separator
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtof_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the float variable where the result shall be stored
decsepthe decimal separator
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi16_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi32_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi64_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi8_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoi_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtok_()

CxStrtokCtx cx_strtok_ ( cxstring str,
cxstring delim,
size_t limit )

Creates a string tokenization context.

Parameters
strthe string to tokenize
delimthe delimiter (must not be empty)
limitthe maximum number of tokens that shall be returned
Returns
a new string tokenization context

◆ cx_strtok_delim()

void cx_strtok_delim ( CxStrtokCtx * ctx,
const cxstring * delim,
size_t count )

Defines an array of more delimiters for the specified tokenization context.

Parameters
ctxthe tokenization context
delimarray of more delimiters
countnumber of elements in the array

◆ cx_strtok_next_()

bool cx_strtok_next_ ( CxStrtokCtx * ctx,
cxstring * token )

Returns the next token.

The token will point to the source string.

Parameters
ctxthe tokenization context
tokena pointer to memory where the next token shall be stored
Returns
true if successful, false if the limit or the end of the string has been reached

◆ cx_strtol_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoll_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtos_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou16_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou32_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou64_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou8_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtou_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoul_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoull_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtous_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtoz_lc_()

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.

Parameters
strthe string to convert
outputa pointer to the integer variable where the result shall be stored
base2, 8, 10, or 16
groupsepeach character in this string is treated as a group separator and ignored during conversion
Return values
zerosuccess
non-zeroconversion was not possible

◆ cx_strtrim_()

cxstring cx_strtrim_ ( cxstring string)

Trims a string.

Internal function - do not use.

Parameters
string
Returns

◆ cx_strtrim_m_()

static cxmutstr cx_strtrim_m_ ( cxmutstr string)
inlinestatic

Internal conversion function.

Parameters
string
Returns