universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: ucx: /home/mike/workspace/c/ucx/src/ucx/string.h File Reference universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
ucx universe@390:
universe@390:
UAP Common Extensions
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390:
universe@390: universe@390:
universe@390: universe@390: universe@390:
universe@390:
universe@390:
universe@390: Data Structures | universe@390: Macros | universe@390: Functions
universe@390:
universe@390:
string.h File Reference
universe@390:
universe@390:
universe@390: universe@390:

Bounded string implementation. universe@390: More...

universe@390:
#include "ucx.h"
universe@390: #include "allocator.h"
universe@390: #include <stddef.h>
universe@390:
universe@390:

Go to the source code of this file.

universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Data Structures

struct  sstr_t
 The UCX string structure. More...
 
struct  scstr_t
 The UCX string structure for immutable (constant) strings. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Macros

universe@390: #define ST(s)   { s, sizeof(s)-1 }
 Shortcut for a sstr_t struct or scstr_t struct literal.
 
#define S(s)   sstrn(s, sizeof(s)-1)
 Shortcut for the conversion of a C string to a sstr_t. More...
 
#define SC(s)   scstrn(s, sizeof(s)-1)
 Shortcut for the conversion of a C string to a scstr_t. More...
 
#define SFMT(s)   (int) (s).length, (s).ptr
 Expands a sstr_t or scstr_t to printf arguments. More...
 
#define PRIsstr   ".*s"
 Format specifier for a sstr_t or scstr_t. More...
 
#define SCSTR(str)   ucx_ss2c_s(str)
 Converts a UCX string to an immutable UCX string (scstr_t). More...
 
#define sstrnlen(count, ...)   scstrnlen(count, __VA_ARGS__)
 Returns the accumulated length of all specified strings. More...
 
#define sstrcat(count, s1, ...)   scstrcat(count, SCSTR(s1), __VA_ARGS__)
 Concatenates two or more strings. More...
 
#define sstrcat_a(alloc, count, s1, ...)   scstrcat_a(alloc, count, SCSTR(s1), __VA_ARGS__)
 Concatenates two or more strings using a UcxAllocator. More...
 
#define sstrstr(string, match)   scstrsstr(string, SCSTR(match))
 Returns a substring starting at the location of the first occurrence of the specified string. More...
 
#define sstrscstr(string, match)   scstrscstr(string, SCSTR(match))
 Returns an immutable substring starting at the location of the first occurrence of the specified immutable string. More...
 
#define sstrsplit(string, delim, count)   scstrsplit(SCSTR(string), SCSTR(delim), count)
 Splits a string into parts by using a delimiter string. More...
 
#define sstrsplit_a(allocator, string, delim, count)   scstrsplit_a(allocator, SCSTR(string), SCSTR(delim), count)
 Performing sstrsplit() using a UcxAllocator. More...
 
#define sstrcmp(s1, s2)   scstrcmp(SCSTR(s1), SCSTR(s2))
 Compares two UCX strings with standard memcmp(). More...
 
#define sstrcasecmp(s1, s2)   scstrcasecmp(SCSTR(s1), SCSTR(s2))
 Compares two UCX strings ignoring the case. More...
 
#define sstrdup(string)   scstrdup(SCSTR(string))
 Creates a duplicate of the specified string. More...
 
#define sstrdup_a(allocator, string)   scstrdup_a(allocator, SCSTR(string))
 Creates a duplicate of the specified string using a UcxAllocator. More...
 
#define sstrprefix(string, prefix)   scstrprefix(SCSTR(string), SCSTR(prefix))
 Checks, if a string has a specific prefix. More...
 
#define sstrsuffix(string, suffix)   scstrsuffix(SCSTR(string), SCSTR(suffix))
 Checks, if a string has a specific suffix. More...
 
#define sstrcaseprefix(string, prefix)   scstrcaseprefix(SCSTR(string), SCSTR(prefix))
 Checks, if a string has a specific prefix, ignoring the case. More...
 
#define sstrcasesuffix(string, suffix)   scstrcasesuffix(SCSTR(string), SCSTR(suffix))
 Checks, if a string has a specific suffix, ignoring the case. More...
 
#define sstrlower(string)   scstrlower(SCSTR(string))
 Returns a lower case version of a string. More...
 
#define sstrlower_a(allocator, string)   scstrlower_a(allocator, SCSTR(string))
 Returns a lower case version of a string. More...
 
#define sstrupper(string)   scstrupper(SCSTR(string))
 Returns a upper case version of a string. More...
 
#define sstrupper_a(allocator, string)   scstrupper_a(allocator, string)
 Returns a upper case version of a string. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Functions

scstr_t ucx_sc2sc (scstr_t str)
 One of two type adjustment functions that return an scstr_t. More...
 
scstr_t ucx_ss2sc (sstr_t str)
 One of two type adjustment functions that return an scstr_t. More...
 
scstr_t ucx_ss2c_s ()
 Converts a UCX string to an immutable UCX string (scstr_t). More...
 
sstr_t sstr (char *cstring)
 Creates a new sstr_t based on a C string. More...
 
sstr_t sstrn (char *cstring, size_t length)
 Creates a new sstr_t of the specified length based on a C string. More...
 
scstr_t scstr (const char *cstring)
 Creates a new scstr_t based on a constant C string. More...
 
scstr_t scstrn (const char *cstring, size_t length)
 Creates a new scstr_t of the specified length based on a constant C string. More...
 
size_t scstrnlen (size_t count,...)
 Returns the accumulated length of all specified strings. More...
 
sstr_t scstrcat (size_t count, scstr_t s1,...)
 Concatenates two or more strings. More...
 
sstr_t scstrcat_a (UcxAllocator *alloc, size_t count, scstr_t s1,...)
 Concatenates two or more strings using a UcxAllocator. More...
 
sstr_t sstrsubs (sstr_t string, size_t start)
 Returns a substring starting at the specified location. More...
 
sstr_t sstrsubsl (sstr_t string, size_t start, size_t length)
 Returns a substring with the given length starting at the specified location. More...
 
scstr_t scstrsubs (scstr_t string, size_t start)
 Returns a substring of an immutable string starting at the specified location. More...
 
scstr_t scstrsubsl (scstr_t string, size_t start, size_t length)
 Returns a substring of an immutable string with a maximum length starting at the specified location. More...
 
sstr_t sstrchr (sstr_t string, int chr)
 Returns a substring starting at the location of the first occurrence of the specified character. More...
 
sstr_t sstrrchr (sstr_t string, int chr)
 Returns a substring starting at the location of the last occurrence of the specified character. More...
 
scstr_t scstrchr (scstr_t string, int chr)
 Returns an immutable substring starting at the location of the first occurrence of the specified character. More...
 
scstr_t scstrrchr (scstr_t string, int chr)
 Returns an immutable substring starting at the location of the last occurrence of the specified character. More...
 
sstr_t scstrsstr (sstr_t string, scstr_t match)
 Returns a substring starting at the location of the first occurrence of the specified string. More...
 
scstr_t scstrscstr (scstr_t string, scstr_t match)
 Returns an immutable substring starting at the location of the first occurrence of the specified immutable string. More...
 
sstr_tscstrsplit (scstr_t string, scstr_t delim, ssize_t *count)
 Splits a string into parts by using a delimiter string. More...
 
sstr_tscstrsplit_a (UcxAllocator *allocator, scstr_t string, scstr_t delim, ssize_t *count)
 Performing scstrsplit() using a UcxAllocator. More...
 
int scstrcmp (scstr_t s1, scstr_t s2)
 Compares two UCX strings with standard memcmp(). More...
 
int scstrcasecmp (scstr_t s1, scstr_t s2)
 Compares two UCX strings ignoring the case. More...
 
sstr_t scstrdup (scstr_t string)
 Creates a duplicate of the specified string. More...
 
sstr_t scstrdup_a (UcxAllocator *allocator, scstr_t string)
 Creates a duplicate of the specified string using a UcxAllocator. More...
 
sstr_t sstrtrim (sstr_t string)
 Omits leading and trailing spaces. More...
 
scstr_t scstrtrim (scstr_t string)
 Omits leading and trailing spaces. More...
 
int scstrprefix (scstr_t string, scstr_t prefix)
 Checks, if a string has a specific prefix. More...
 
int scstrsuffix (scstr_t string, scstr_t suffix)
 Checks, if a string has a specific suffix. More...
 
int scstrcaseprefix (scstr_t string, scstr_t prefix)
 Checks, if a string has a specific prefix, ignoring the case. More...
 
int scstrcasesuffix (scstr_t string, scstr_t suffix)
 Checks, if a string has a specific suffix, ignoring the case. More...
 
sstr_t scstrlower (scstr_t string)
 Returns a lower case version of a string. More...
 
sstr_t scstrlower_a (UcxAllocator *allocator, scstr_t string)
 Returns a lower case version of a string. More...
 
sstr_t scstrupper (scstr_t string)
 Returns a upper case version of a string. More...
 
sstr_t scstrupper_a (UcxAllocator *allocator, scstr_t string)
 Returns a upper case version of a string. More...
 
universe@390:

Detailed Description

universe@390:

Bounded string implementation.

universe@390:

The UCX strings (sstr_t) provide an alternative to C strings. The main difference to C strings is, that sstr_t does not need to be NULL-terminated. Instead the length is stored within the structure.

universe@390:

When using sstr_t, developers must be full aware of what type of string (NULL-terminated) or not) they are using, when accessing the char* ptr directly.

universe@390:

The UCX string module provides some common string functions, known from standard libc, working with sstr_t.

universe@390:
Author
Mike Becker
universe@390:
universe@390: Olaf Wintermann
universe@390:

Macro Definition Documentation

universe@390: universe@390:

◆ PRIsstr

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define PRIsstr   ".*s"
universe@390:
universe@390: universe@390:

Format specifier for a sstr_t or scstr_t.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ S

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define S( s)   sstrn(s, sizeof(s)-1)
universe@390:
universe@390: universe@390:

Shortcut for the conversion of a C string to a sstr_t.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ SC

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define SC( s)   scstrn(s, sizeof(s)-1)
universe@390:
universe@390: universe@390:

Shortcut for the conversion of a C string to a scstr_t.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ SCSTR

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define SCSTR( str)   ucx_ss2c_s(str)
universe@390:
universe@390: universe@390:

Converts a UCX string to an immutable UCX string (scstr_t).

universe@390:
Parameters
universe@390: universe@390: universe@390:
strsome UCX string
universe@390:
universe@390:
universe@390:
Returns
the an immutable version of the provided string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ SFMT

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define SFMT( s)   (int) (s).length, (s).ptr
universe@390:
universe@390: universe@390:

Expands a sstr_t or scstr_t to printf arguments.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrcasecmp

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrcasecmp( s1,
 s2 
)   scstrcasecmp(SCSTR(s1), SCSTR(s2))
universe@390:
universe@390: universe@390:

Compares two UCX strings ignoring the case.

universe@390:

At first it compares the sstr_t.length attribute of the two strings. If and only if the lengths match, both strings are compared char by char ignoring the case.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
s1the first string
s2the second string
universe@390:
universe@390:
universe@390:
Returns
-1, if the length of s1 is less than the length of s2 or 1, if the length of s1 is greater than the length of s2 or the result of the platform specific string comparison function ignoring the case.
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrcaseprefix

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrcaseprefix( string,
 prefix 
)   scstrcaseprefix(SCSTR(string), SCSTR(prefix))
universe@390:
universe@390: universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
prefixthe prefix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified prefix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrcasesuffix

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrcasesuffix( string,
 suffix 
)   scstrcasesuffix(SCSTR(string), SCSTR(suffix))
universe@390:
universe@390: universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
suffixthe suffix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified suffix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrcat

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrcat( count,
 s1,
 ... 
)   scstrcat(count, SCSTR(s1), __VA_ARGS__)
universe@390:
universe@390: universe@390:

Concatenates two or more strings.

universe@390:

The resulting string will be allocated by standard malloc(). So developers MUST pass the sstr_t.ptr to free().

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
countthe total number of strings to concatenate
s1first string
...all remaining strings
universe@390:
universe@390:
universe@390:
Returns
the concatenated string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrcat_a

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrcat_a( alloc,
 count,
 s1,
 ... 
)   scstrcat_a(alloc, count, SCSTR(s1), __VA_ARGS__)
universe@390:
universe@390: universe@390:

Concatenates two or more strings using a UcxAllocator.

universe@390:

The resulting string must be freed by the allocators free() implementation.

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocthe allocator to use
countthe total number of strings to concatenate
s1first string
...all remaining strings
universe@390:
universe@390:
universe@390:
Returns
the concatenated string
universe@390:
See also
sstrcat()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrcmp

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrcmp( s1,
 s2 
)   scstrcmp(SCSTR(s1), SCSTR(s2))
universe@390:
universe@390: universe@390:

Compares two UCX strings with standard memcmp().

universe@390:

At first it compares the sstr_t.length attribute of the two strings. The memcmp() function is called, if and only if the lengths match.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
s1the first string
s2the second string
universe@390:
universe@390:
universe@390:
Returns
-1, if the length of s1 is less than the length of s2 or 1, if the length of s1 is greater than the length of s2 or the result of memcmp() otherwise (i.e. 0 if the strings match)
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrdup

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrdup( string)   scstrdup(SCSTR(string))
universe@390:
universe@390: universe@390:

Creates a duplicate of the specified string.

universe@390:

The new sstr_t will contain a copy allocated by standard malloc(). So developers MUST pass the sstr_t.ptr to free().

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated, regardless of the argument.

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe string to duplicate
universe@390:
universe@390:
universe@390:
Returns
a duplicate of the string
universe@390:
See also
sstrdup_a()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrdup_a

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrdup_a( allocator,
 string 
)   scstrdup_a(allocator, SCSTR(string))
universe@390:
universe@390: universe@390:

Creates a duplicate of the specified string using a UcxAllocator.

universe@390:

The new sstr_t will contain a copy allocated by the allocators UcxAllocator.malloc() function. So it is implementation depended, whether the returned sstr_t.ptr pointer must be passed to the allocators UcxAllocator.free() function manually.

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated, regardless of the argument.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatora valid instance of a UcxAllocator
stringthe string to duplicate
universe@390:
universe@390:
universe@390:
Returns
a duplicate of the string
universe@390:
See also
scstrdup()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrlower

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrlower( string)   scstrlower(SCSTR(string))
universe@390:
universe@390: universe@390:

Returns a lower case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see sstrdup()).

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting lower case string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrlower_a

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrlower_a( allocator,
 string 
)   scstrlower_a(allocator, SCSTR(string))
universe@390:
universe@390: universe@390:

Returns a lower case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see sstrdup_a()).

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator used for duplicating the string
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting lower case string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrnlen

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrnlen( count,
 ... 
)   scstrnlen(count, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Returns the accumulated length of all specified strings.

universe@390:

Attention: if the count argument is larger than the count of the specified strings, the behavior is undefined.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
countthe total number of specified strings
...all strings
universe@390:
universe@390:
universe@390:
Returns
the cumulated length of all strings
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrprefix

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrprefix( string,
 prefix 
)   scstrprefix(SCSTR(string), SCSTR(prefix))
universe@390:
universe@390: universe@390:

Checks, if a string has a specific prefix.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
prefixthe prefix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified prefix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrscstr

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrscstr( string,
 match 
)   scstrscstr(string, SCSTR(match))
universe@390:
universe@390: universe@390:

Returns an immutable substring starting at the location of the first occurrence of the specified immutable string.

universe@390:

If the string does not contain the other string, an empty string is returned.

universe@390:

If match is an empty string, the complete string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to be scanned
matchstring containing the sequence of characters to match
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the first occurrence of match, or an empty string, if the sequence is not present in string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrsplit

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrsplit( string,
 delim,
 count 
)   scstrsplit(SCSTR(string), SCSTR(delim), count)
universe@390:
universe@390: universe@390:

Splits a string into parts by using a delimiter string.

universe@390:

This function will return NULL, if one of the following happens:

    universe@390:
  • universe@390: the string length is zero
  • universe@390:
  • universe@390: the delimeter length is zero
  • universe@390:
  • universe@390: the string equals the delimeter
  • universe@390:
  • universe@390: memory allocation fails
  • universe@390:
universe@390:

The integer referenced by count is used as input and determines the maximum size of the resulting array, i.e. the maximum count of splits to perform + 1.

universe@390:

The integer referenced by count is also used as output and is set to

    universe@390:
  • universe@390: -2, on memory allocation errors
  • universe@390:
  • universe@390: -1, if either the string or the delimiter is an empty string
  • universe@390:
  • universe@390: 0, if the string equals the delimiter
  • universe@390:
  • universe@390: 1, if the string does not contain the delimiter
  • universe@390:
  • universe@390: the count of array items, otherwise
  • universe@390:
universe@390:

If the string starts with the delimiter, the first item of the resulting array will be an empty string.

universe@390:

If the string ends with the delimiter and the maximum list size is not exceeded, the last array item will be an empty string. In case the list size would be exceeded, the last array item will be the remaining string after the last split, including the terminating delimiter.

universe@390:

Attention: The array pointer AND all sstr_t.ptr of the array items must be manually passed to free(). Use sstrsplit_a() with an allocator to managed memory, to avoid this.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
stringthe string to split
delimthe delimiter string
countIN: the maximum size of the resulting array (0 = no limit), OUT: the actual size of the array
universe@390:
universe@390:
universe@390:
Returns
a sstr_t array containing the split strings or NULL on error
universe@390:
See also
sstrsplit_a()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrsplit_a

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrsplit_a( allocator,
 string,
 delim,
 count 
)   scstrsplit_a(allocator, SCSTR(string), SCSTR(delim), count)
universe@390:
universe@390: universe@390:

Performing sstrsplit() using a UcxAllocator.

universe@390:

Read the description of sstrsplit() for details.

universe@390:

The memory for the sstr_t.ptr pointers of the array items and the memory for the sstr_t array itself are allocated by using the UcxAllocator.malloc() function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe UcxAllocator used for allocating memory
stringthe string to split
delimthe delimiter string
countIN: the maximum size of the resulting array (0 = no limit), OUT: the actual size of the array
universe@390:
universe@390:
universe@390:
Returns
a sstr_t array containing the split strings or NULL on error
universe@390:
See also
sstrsplit()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrstr

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrstr( string,
 match 
)   scstrsstr(string, SCSTR(match))
universe@390:
universe@390: universe@390:

Returns a substring starting at the location of the first occurrence of the specified string.

universe@390:

If the string does not contain the other string, an empty string is returned.

universe@390:

If match is an empty string, the complete string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to be scanned
matchstring containing the sequence of characters to match
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the first occurrence of match, or an empty string, if the sequence is not present in string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrsuffix

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrsuffix( string,
 suffix 
)   scstrsuffix(SCSTR(string), SCSTR(suffix))
universe@390:
universe@390: universe@390:

Checks, if a string has a specific suffix.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
suffixthe suffix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified suffix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrupper

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrupper( string)   scstrupper(SCSTR(string))
universe@390:
universe@390: universe@390:

Returns a upper case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see sstrdup()).

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting upper case string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrupper_a

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define sstrupper_a( allocator,
 string 
)   scstrupper_a(allocator, string)
universe@390:
universe@390: universe@390:

Returns a upper case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see sstrdup_a()).

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator used for duplicating the string
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting upper case string
universe@390: universe@390:
universe@390:
universe@390:

Function Documentation

universe@390: universe@390:

◆ scstr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstr (const char * cstring)
universe@390:
universe@390: universe@390:

Creates a new scstr_t based on a constant C string.

universe@390:

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

universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390:
cstringthe C string to wrap
universe@390:
universe@390:
universe@390:
Returns
a new scstr_t containing the C string
universe@390:
See also
scstrn()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrcasecmp()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int scstrcasecmp (scstr_t s1,
scstr_t s2 
)
universe@390:
universe@390: universe@390:

Compares two UCX strings ignoring the case.

universe@390:

At first it compares the scstr_t.length attribute of the two strings. If and only if the lengths match, both strings are compared char by char ignoring the case.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
s1the first string
s2the second string
universe@390:
universe@390:
universe@390:
Returns
-1, if the length of s1 is less than the length of s2 or 1, if the length of s1 is greater than the length of s2 or the result of the platform specific string comparison function ignoring the case.
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrcaseprefix()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int scstrcaseprefix (scstr_t string,
scstr_t prefix 
)
universe@390:
universe@390: universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
prefixthe prefix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified prefix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrcasesuffix()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int scstrcasesuffix (scstr_t string,
scstr_t suffix 
)
universe@390:
universe@390: universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
suffixthe suffix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified suffix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrcat()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrcat (size_t count,
scstr_t s1,
 ... 
)
universe@390:
universe@390: universe@390:

Concatenates two or more strings.

universe@390:

The resulting string will be allocated by standard malloc(). So developers MUST pass the sstr_t.ptr to free().

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
countthe total number of strings to concatenate
s1first string
...all remaining strings
universe@390:
universe@390:
universe@390:
Returns
the concatenated string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrcat_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrcat_a (UcxAllocatoralloc,
size_t count,
scstr_t s1,
 ... 
)
universe@390:
universe@390: universe@390:

Concatenates two or more strings using a UcxAllocator.

universe@390:

The resulting string must be freed by the allocators free() implementation.

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocthe allocator to use
countthe total number of strings to concatenate
s1first string
...all remaining strings
universe@390:
universe@390:
universe@390:
Returns
the concatenated string
universe@390:
See also
scstrcat()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrchr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrchr (scstr_t string,
int chr 
)
universe@390:
universe@390: universe@390:

Returns an immutable substring starting at the location of the first occurrence of the specified character.

universe@390:

If the string does not contain the character, an empty string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string where to locate the character
chrthe character to locate
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the first location of chr
universe@390:
See also
scstrsubs()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrcmp()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int scstrcmp (scstr_t s1,
scstr_t s2 
)
universe@390:
universe@390: universe@390:

Compares two UCX strings with standard memcmp().

universe@390:

At first it compares the scstr_t.length attribute of the two strings. The memcmp() function is called, if and only if the lengths match.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
s1the first string
s2the second string
universe@390:
universe@390:
universe@390:
Returns
-1, if the length of s1 is less than the length of s2 or 1, if the length of s1 is greater than the length of s2 or the result of memcmp() otherwise (i.e. 0 if the strings match)
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrdup()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrdup (scstr_t string)
universe@390:
universe@390: universe@390:

Creates a duplicate of the specified string.

universe@390:

The new sstr_t will contain a copy allocated by standard malloc(). So developers MUST pass the sstr_t.ptr to free().

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated and mutable, regardless of the argument.

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe string to duplicate
universe@390:
universe@390:
universe@390:
Returns
a duplicate of the string
universe@390:
See also
scstrdup_a()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrdup_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrdup_a (UcxAllocatorallocator,
scstr_t string 
)
universe@390:
universe@390: universe@390:

Creates a duplicate of the specified string using a UcxAllocator.

universe@390:

The new sstr_t will contain a copy allocated by the allocators UcxAllocator.malloc() function. So it is implementation depended, whether the returned sstr_t.ptr pointer must be passed to the allocators UcxAllocator.free() function manually.

universe@390:

The sstr_t.ptr of the return value will always be NULL- terminated and mutable, regardless of the argument.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatora valid instance of a UcxAllocator
stringthe string to duplicate
universe@390:
universe@390:
universe@390:
Returns
a duplicate of the string
universe@390:
See also
scstrdup()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrlower()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrlower (scstr_t string)
universe@390:
universe@390: universe@390:

Returns a lower case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see scstrdup()).

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting lower case string
universe@390:
See also
scstrdup()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrlower_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrlower_a (UcxAllocatorallocator,
scstr_t string 
)
universe@390:
universe@390: universe@390:

Returns a lower case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see scstrdup_a()).

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator used for duplicating the string
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting lower case string
universe@390:
See also
scstrdup_a()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrn()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrn (const char * cstring,
size_t length 
)
universe@390:
universe@390: universe@390:

Creates a new scstr_t of the specified length based on a constant C string.

universe@390:

Note: the scstr_t will share the specified pointer to the C string. If you do want a copy, use scstrdup() on the return value of this function. *

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
cstringthe C string to wrap
lengththe length of the string
universe@390:
universe@390:
universe@390:
Returns
a new scstr_t containing the C string
universe@390:
See also
scstr()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrnlen()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
size_t scstrnlen (size_t count,
 ... 
)
universe@390:
universe@390: universe@390:

Returns the accumulated length of all specified strings.

universe@390:

Attention: if the count argument is larger than the count of the specified strings, the behavior is undefined.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
countthe total number of specified strings
...all strings
universe@390:
universe@390:
universe@390:
Returns
the accumulated length of all strings
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrprefix()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int scstrprefix (scstr_t string,
scstr_t prefix 
)
universe@390:
universe@390: universe@390:

Checks, if a string has a specific prefix.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
prefixthe prefix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified prefix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrrchr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrrchr (scstr_t string,
int chr 
)
universe@390:
universe@390: universe@390:

Returns an immutable substring starting at the location of the last occurrence of the specified character.

universe@390:

If the string does not contain the character, an empty string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string where to locate the character
chrthe character to locate
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the last location of chr
universe@390:
See also
scstrsubs()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrscstr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrscstr (scstr_t string,
scstr_t match 
)
universe@390:
universe@390: universe@390:

Returns an immutable substring starting at the location of the first occurrence of the specified immutable string.

universe@390:

If the string does not contain the other string, an empty string is returned.

universe@390:

If match is an empty string, the complete string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to be scanned
matchstring containing the sequence of characters to match
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the first occurrence of match, or an empty string, if the sequence is not present in string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrsplit()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t* scstrsplit (scstr_t string,
scstr_t delim,
ssize_t * count 
)
universe@390:
universe@390: universe@390:

Splits a string into parts by using a delimiter string.

universe@390:

This function will return NULL, if one of the following happens:

    universe@390:
  • universe@390: the string length is zero
  • universe@390:
  • universe@390: the delimeter length is zero
  • universe@390:
  • universe@390: the string equals the delimeter
  • universe@390:
  • universe@390: memory allocation fails
  • universe@390:
universe@390:

The integer referenced by count is used as input and determines the maximum size of the resulting array, i.e. the maximum count of splits to perform + 1.

universe@390:

The integer referenced by count is also used as output and is set to

    universe@390:
  • universe@390: -2, on memory allocation errors
  • universe@390:
  • universe@390: -1, if either the string or the delimiter is an empty string
  • universe@390:
  • universe@390: 0, if the string equals the delimiter
  • universe@390:
  • universe@390: 1, if the string does not contain the delimiter
  • universe@390:
  • universe@390: the count of array items, otherwise
  • universe@390:
universe@390:

If the string starts with the delimiter, the first item of the resulting array will be an empty string.

universe@390:

If the string ends with the delimiter and the maximum list size is not exceeded, the last array item will be an empty string. In case the list size would be exceeded, the last array item will be the remaining string after the last split, including the terminating delimiter.

universe@390:

Attention: The array pointer AND all sstr_t.ptr of the array items must be manually passed to free(). Use scstrsplit_a() with an allocator to managed memory, to avoid this.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
stringthe string to split
delimthe delimiter string
countIN: the maximum size of the resulting array (0 = no limit), OUT: the actual size of the array
universe@390:
universe@390:
universe@390:
Returns
a sstr_t array containing the split strings or NULL on error
universe@390:
See also
scstrsplit_a()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrsplit_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t* scstrsplit_a (UcxAllocatorallocator,
scstr_t string,
scstr_t delim,
ssize_t * count 
)
universe@390:
universe@390: universe@390:

Performing scstrsplit() using a UcxAllocator.

universe@390:

Read the description of scstrsplit() for details.

universe@390:

The memory for the sstr_t.ptr pointers of the array items and the memory for the sstr_t array itself are allocated by using the UcxAllocator.malloc() function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe UcxAllocator used for allocating memory
stringthe string to split
delimthe delimiter string
countIN: the maximum size of the resulting array (0 = no limit), OUT: the actual size of the array
universe@390:
universe@390:
universe@390:
Returns
a sstr_t array containing the split strings or NULL on error
universe@390:
See also
scstrsplit()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrsstr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrsstr (sstr_t string,
scstr_t match 
)
universe@390:
universe@390: universe@390:

Returns a substring starting at the location of the first occurrence of the specified string.

universe@390:

If the string does not contain the other string, an empty string is returned.

universe@390:

If match is an empty string, the complete string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to be scanned
matchstring containing the sequence of characters to match
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the first occurrence of match, or an empty string, if the sequence is not present in string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrsubs()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrsubs (scstr_t string,
size_t start 
)
universe@390:
universe@390: universe@390:

Returns a substring of an immutable string starting at the specified location.

universe@390:

Attention: the new string references the same memory area as the input string and is NOT required to be NULL-terminated. Use scstrdup() to get a copy.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringinput string
startstart location of the substring
universe@390:
universe@390:
universe@390:
Returns
a substring of string starting at start
universe@390:
See also
scstrsubsl()
universe@390:
universe@390: scstrchr()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrsubsl()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrsubsl (scstr_t string,
size_t start,
size_t length 
)
universe@390:
universe@390: universe@390:

Returns a substring of an immutable string with a maximum length starting at the specified location.

universe@390:

Attention: the new string references the same memory area as the input string and is NOT required to be NULL-terminated. Use scstrdup() to get a copy.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
stringinput string
startstart location of the substring
lengththe maximum length of the substring
universe@390:
universe@390:
universe@390:
Returns
a substring of string starting at start with a maximum length of length
universe@390:
See also
scstrsubs()
universe@390:
universe@390: scstrchr()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrsuffix()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int scstrsuffix (scstr_t string,
scstr_t suffix 
)
universe@390:
universe@390: universe@390:

Checks, if a string has a specific suffix.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string to check
suffixthe suffix the string should have
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the string has the specified suffix, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrtrim()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t scstrtrim (scstr_t string)
universe@390:
universe@390: universe@390:

Omits leading and trailing spaces.

universe@390:

This function returns a new scstr_t containing a trimmed version of the specified string.

universe@390:

Note: the new scstr_t references the same memory, thus you MUST NOT pass the scstr_t.ptr of the return value to free(). It is also highly recommended to avoid assignments like mystr = scstrtrim(mystr); as you lose the reference to the source string. Assignments of this type are only permitted, if the scstr_t.ptr of the source string does not need to be freed or if another reference to the source string exists.

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe string that shall be trimmed
universe@390:
universe@390:
universe@390:
Returns
a new scstr_t containing the trimmed string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrupper()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrupper (scstr_t string)
universe@390:
universe@390: universe@390:

Returns a upper case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see scstrdup()).

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting upper case string
universe@390:
See also
scstrdup()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ scstrupper_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t scstrupper_a (UcxAllocatorallocator,
scstr_t string 
)
universe@390:
universe@390: universe@390:

Returns a upper case version of a string.

universe@390:

This function creates a duplicate of the input string, first (see scstrdup_a()).

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator used for duplicating the string
stringthe input string
universe@390:
universe@390:
universe@390:
Returns
the resulting upper case string
universe@390:
See also
scstrdup_a()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstr (char * cstring)
universe@390:
universe@390: universe@390:

Creates a new sstr_t based on a C string.

universe@390:

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

universe@390:

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

universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390:
cstringthe C string to wrap
universe@390:
universe@390:
universe@390:
Returns
a new sstr_t containing the C string
universe@390:
See also
sstrn()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrchr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstrchr (sstr_t string,
int chr 
)
universe@390:
universe@390: universe@390:

Returns a substring starting at the location of the first occurrence of the specified character.

universe@390:

If the string does not contain the character, an empty string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string where to locate the character
chrthe character to locate
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the first location of chr
universe@390:
See also
sstrsubs()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrn()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstrn (char * cstring,
size_t length 
)
universe@390:
universe@390: universe@390:

Creates a new sstr_t of the specified length based on a C string.

universe@390:

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

universe@390:

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

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
cstringthe C string to wrap
lengththe length of the string
universe@390:
universe@390:
universe@390:
Returns
a new sstr_t containing the C string
universe@390:
See also
sstr()
universe@390:
universe@390: S()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrrchr()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstrrchr (sstr_t string,
int chr 
)
universe@390:
universe@390: universe@390:

Returns a substring starting at the location of the last occurrence of the specified character.

universe@390:

If the string does not contain the character, an empty string is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringthe string where to locate the character
chrthe character to locate
universe@390:
universe@390:
universe@390:
Returns
a substring starting at the last location of chr
universe@390:
See also
sstrsubs()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrsubs()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstrsubs (sstr_t string,
size_t start 
)
universe@390:
universe@390: universe@390:

Returns a substring starting at the specified location.

universe@390:

Attention: the new string references the same memory area as the input string and is NOT required to be NULL-terminated. Use sstrdup() to get a copy.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
stringinput string
startstart location of the substring
universe@390:
universe@390:
universe@390:
Returns
a substring of string starting at start
universe@390:
See also
sstrsubsl()
universe@390:
universe@390: sstrchr()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrsubsl()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstrsubsl (sstr_t string,
size_t start,
size_t length 
)
universe@390:
universe@390: universe@390:

Returns a substring with the given length starting at the specified location.

universe@390:

Attention: the new string references the same memory area as the input string and is NOT required to be NULL-terminated. Use sstrdup() to get a copy.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
stringinput string
startstart location of the substring
lengththe maximum length of the substring
universe@390:
universe@390:
universe@390:
Returns
a substring of string starting at start with a maximum length of length
universe@390:
See also
sstrsubs()
universe@390:
universe@390: sstrchr()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ sstrtrim()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
sstr_t sstrtrim (sstr_t string)
universe@390:
universe@390: universe@390:

Omits leading and trailing spaces.

universe@390:

This function returns a new sstr_t containing a trimmed version of the specified string.

universe@390:

Note: the new sstr_t references the same memory, thus you MUST NOT pass the sstr_t.ptr of the return value to free(). It is also highly recommended to avoid assignments like mystr = sstrtrim(mystr); as you lose the reference to the source string. Assignments of this type are only permitted, if the sstr_t.ptr of the source string does not need to be freed or if another reference to the source string exists.

universe@390:
Parameters
universe@390: universe@390: universe@390:
stringthe string that shall be trimmed
universe@390:
universe@390:
universe@390:
Returns
a new sstr_t containing the trimmed string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_sc2sc()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t ucx_sc2sc (scstr_t str)
universe@390:
universe@390: universe@390:

One of two type adjustment functions that return an scstr_t.

universe@390:

Used internally to convert a UCX string to an immutable UCX string. This variant is used, when the string is already immutable and no operation needs to be performed.

universe@390:

Do not use this function manually.

universe@390:
Parameters
universe@390: universe@390: universe@390:
strsome scstr_t
universe@390:
universe@390:
universe@390:
Returns
the argument itself
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_ss2c_s()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t ucx_ss2c_s ()
universe@390:
universe@390: universe@390:

Converts a UCX string to an immutable UCX string (scstr_t).

universe@390:

This internal function (ab)uses the C standard an expects one single argument which is then implicitly converted to scstr_t without a warning.

universe@390:

Do not use this function manually.

universe@390:
Returns
the an immutable version of the provided string
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_ss2sc()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
scstr_t ucx_ss2sc (sstr_t str)
universe@390:
universe@390: universe@390:

One of two type adjustment functions that return an scstr_t.

universe@390:

Used internally to convert a UCX string to an immutable UCX string.

universe@390:

Do not use this function manually.

universe@390:
Parameters
universe@390: universe@390: universe@390:
strsome sstr_t
universe@390:
universe@390:
universe@390:
Returns
an immutable (scstr_t) version of the provided string.
universe@390: universe@390:
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: