ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
string.h File Reference

Strings that know their length. More...

#include "common.h"
#include "allocator.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_STR(literal)   (cxstring){literal, sizeof(literal) - 1}
 A literal initializer for an UCX string structure.
 
#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(string)   cx_strdup_a(cxDefaultAllocator, string)
 Creates a duplicate of the specified string.
 
#define cx_strdup_ma(allocator, string)   cx_strdup_a(allocator, cx_strcast(string))
 Creates a duplicate of the specified string.
 
#define cx_strdup_m(string)   cx_strdup_a(cxDefaultAllocator, cx_strcast(string))
 Creates a duplicate of the specified string.
 
#define cx_strreplacen(str, pattern, replacement, replmax)   cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax)
 Replaces a pattern in a string with another string.
 
#define cx_strreplace_a(allocator, str, pattern, replacement)   cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX)
 Replaces a pattern in a string with another string.
 
#define cx_strreplace(str, pattern, replacement)   cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX)
 Replaces a pattern in a string with another string.
 

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 (char const *cstring)
 Wraps a string that must be zero-terminated.
 
cxstring cx_strn (char const *cstring, size_t length)
 Wraps a string that does not need to be zero-terminated.
 
cxstring cx_strcast (cxmutstr str)
 Casts a mutable string to an immutable string.
 
void cx_strfree (cxmutstr *str)
 Passes the pointer in this string to free().
 
void cx_strfree_a (CxAllocator const *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 (CxAllocator const *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 (CxAllocator const *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 (CxAllocator const *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 (void const *s1, void const *s2)
 Compares two strings.
 
int cx_strcasecmp_p (void const *s1, void const *s2)
 Compares two strings ignoring case.
 
cxmutstr cx_strdup_a (CxAllocator const *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.
 
void cx_strlower (cxmutstr string)
 Converts the string to lower case.
 
void cx_strupper (cxmutstr string)
 Converts the string to upper case.
 
cxmutstr cx_strreplacen_a (CxAllocator const *allocator, cxstring str, cxstring pattern, cxstring replacement, size_t replmax)
 Replaces a pattern in a string with another string.
 
CxStrtokCtx cx_strtok (cxstring str, cxstring delim, size_t limit)
 Creates a string tokenization context.
 
CxStrtokCtx cx_strtok_m (cxmutstr str, cxstring delim, size_t limit)
 Creates a string tokenization context for a mutable string.
 
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, cxstring const *delim, size_t count)
 Defines an array of more delimiters for the specified tokenization context.
 

Detailed Description

Strings that know their length.

Author
Mike Becker
Olaf Wintermann
Version
3.0

Macro Definition Documentation

◆ CX_STR

#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.

Parameters
literalthe string literal

◆ cx_strcat

#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.

Note
It is guaranteed that there is only one allocation. It is also guaranteed that the returned string is zero-terminated.
Parameters
countthe number of the other following strings to concatenate
...all other strings
Returns
the concatenated string

◆ cx_strcat_a

#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.

Note
It is guaranteed that there is only one allocation. It is also guaranteed that the returned string is zero-terminated.
Parameters
allocthe allocator to use
countthe number of the other following strings to concatenate
...all other strings
Returns
the concatenated string

◆ cx_strcat_m

#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.

Note
It is guaranteed that there is only one allocation. It is also guaranteed that the returned string is zero-terminated.
Parameters
strthe string the other strings shall be concatenated to
countthe number of the other following strings to concatenate
...all other strings
Returns
the concatenated string

◆ cx_strdup

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

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

◆ cx_strdup_m

#define cx_strdup_m (   string)    cx_strdup_a(cxDefaultAllocator, cx_strcast(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().

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

◆ cx_strdup_ma

#define cx_strdup_ma (   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.

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_m()

◆ cx_strreplace

#define cx_strreplace (   str,
  pattern,
  replacement 
)    cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX)

Replaces a pattern in a string with another string.

The pattern is taken literally and is no regular expression. 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.

Parameters
strthe string where replacements should be applied
patternthe pattern to search for
replacementthe replacement string
Returns
the resulting string after applying the replacements

◆ cx_strreplace_a

#define cx_strreplace_a (   allocator,
  str,
  pattern,
  replacement 
)    cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX)

Replaces a pattern in a string with another string.

The pattern is taken literally and is no regular expression.

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
allocatorthe allocator to use
strthe string where replacements should be applied
patternthe pattern to search for
replacementthe replacement string
Returns
the resulting string after applying the replacements

◆ cx_strreplacen

#define cx_strreplacen (   str,
  pattern,
  replacement,
  replmax 
)    cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax)

Replaces a pattern in a string with another string.

The pattern is taken literally and is no regular expression. 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.

Parameters
strthe string where replacements should be applied
patternthe pattern to search for
replacementthe replacement string
replmaxmaximum number of replacements
Returns
the resulting string after applying the replacements

Function Documentation

◆ cx_mutstr()

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

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_mutstrn()

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.

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

cxstring cx_str ( char const *  cstring)

Wraps a string that must be zero-terminated.

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

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_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 ( void const *  s1,
void const *  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()

cxstring cx_strcast ( cxmutstr  str)

Casts a mutable string to an immutable string.

Note
This is not seriously a cast. Instead you get a copy of the struct with the desired pointer type. Both structs still point to the same location, though!
Parameters
strthe mutable string to cast
Returns
an immutable copy of the string pointer

◆ cx_strcat_ma()

cxmutstr cx_strcat_ma ( CxAllocator const *  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. It is also guaranteed that the returned string is zero-terminated.
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 strings
Returns
the concatenated string

◆ cx_strchr()

cxstring cx_strchr ( cxstring  string,
int  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.

Parameters
stringthe string where to locate the character
chrthe character to locate
Returns
a substring starting at the first location of chr
See also
cx_strchr_m()

◆ cx_strchr_m()

cxmutstr cx_strchr_m ( cxmutstr  string,
int  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.

Parameters
stringthe string where to locate the character
chrthe character to locate
Returns
a substring starting at the first location of chr
See also
cx_strchr()

◆ 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 ( void const *  s1,
void const *  s2 
)

Compares two strings.

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

◆ cx_strdup_a()

cxmutstr cx_strdup_a ( CxAllocator const *  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 free().

The pointer in the struct is set to NULL and the length is set to zero.

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

◆ cx_strfree_a()

void cx_strfree_a ( CxAllocator const *  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.

Note
There is no implementation for cxstring, because it is unlikely that you ever have a char const* you are really supposed to free. If you encounter such 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.

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_strlower()

void cx_strlower ( cxmutstr  string)

Converts the string to lower case.

The change is made in-place. If you want a copy, use cx_strdup(), first.

Parameters
stringthe string to modify
See also
cx_strdup()

◆ cx_strn()

cxstring cx_strn ( char const *  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.

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 
)

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
chrthe character to locate
Returns
a substring starting at the last location of chr
See also
cx_strrchr_m()

◆ cx_strrchr_m()

cxmutstr cx_strrchr_m ( cxmutstr  string,
int  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.

Parameters
stringthe string where to locate the character
chrthe character to locate
Returns
a substring starting at the last location of chr
See also
cx_strrchr()

◆ cx_strreplacen_a()

cxmutstr cx_strreplacen_a ( CxAllocator const *  allocator,
cxstring  str,
cxstring  pattern,
cxstring  replacement,
size_t  replmax 
)

Replaces a pattern in a string with another string.

The pattern is taken literally and is no regular expression. 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
allocatorthe allocator to use
strthe string where replacements should be applied
patternthe pattern to search for
replacementthe replacement string
replmaxmaximum number of replacements
Returns
the resulting string after applying the replacements

◆ cx_strsplit()

size_t cx_strsplit ( cxstring  string,
cxstring  delim,
size_t  limit,
cxstring output 
)

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
limitthe maximum number of split items
outputa pre-allocated array of at least limit length
Returns
the actual number of split items

◆ cx_strsplit_a()

size_t cx_strsplit_a ( CxAllocator const *  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.

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
allocatorthe allocator to use for allocating the resulting array
stringthe string to split
delimthe delimiter
limitthe maximum number of split items
outputa pointer where the address of the allocated array shall be written to
Returns
the actual number of split items

◆ 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.

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
limitthe maximum number of split items
outputa pre-allocated array of at least limit length
Returns
the actual number of split items

◆ cx_strsplit_ma()

size_t cx_strsplit_ma ( CxAllocator const *  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.

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
allocatorthe allocator to use for allocating the resulting array
stringthe string to split
delimthe delimiter
limitthe maximum number of split items
outputa pointer where the address of the allocated array shall be written to
Returns
the actual number of split items

◆ cx_strstr()

cxstring cx_strstr ( cxstring  haystack,
cxstring  needle 
)

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
a substring starting at the first occurrence of needle, or an empty string, if the sequence is not contained
See also
cx_strstr_m()

◆ cx_strstr_m()

cxmutstr cx_strstr_m ( cxmutstr  haystack,
cxstring  needle 
)

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
a substring starting at the first occurrence of needle, or an empty string, if the sequence is not contained
See also
cx_strstr()

◆ cx_strsubs()

cxstring cx_strsubs ( cxstring  string,
size_t  start 
)

Returns a substring starting at the specified location.

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
Returns
a substring of string starting at start
See also
cx_strsubsl()
cx_strsubs_m()
cx_strsubsl_m()

◆ cx_strsubs_m()

cxmutstr cx_strsubs_m ( cxmutstr  string,
size_t  start 
)

Returns a substring starting at the specified location.

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
Returns
a substring of string starting at start
See also
cx_strsubsl_m()
cx_strsubs()
cx_strsubsl()

◆ cx_strsubsl()

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

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_strsubs_m()
cx_strsubsl_m()

◆ cx_strsubsl_m()

cxmutstr cx_strsubsl_m ( cxmutstr  string,
size_t  start,
size_t  length 
)

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_m()
cx_strsubs()
cx_strsubsl()

◆ 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_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,
cxstring const *  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_m()

CxStrtokCtx cx_strtok_m ( cxmutstr  str,
cxstring  delim,
size_t  limit 
)

Creates a string tokenization context for a mutable string.

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_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_strtok_next_m()

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. If the context was not initialized over a mutable string, modifying the data of the returned token is undefined behavior.

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_strtrim()

cxstring cx_strtrim ( cxstring  string)

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
the trimmed string

◆ cx_strtrim_m()

cxmutstr cx_strtrim_m ( cxmutstr  string)

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
the trimmed string

◆ cx_strupper()

void cx_strupper ( cxmutstr  string)

Converts the string to upper case.

The change is made in-place. If you want a copy, use cx_strdup(), first.

Parameters
stringthe string to modify
See also
cx_strdup()