58 #ifndef UCX_NO_SSTR_SHORTCUTS 63 #define ST(s) { s, sizeof(s)-1 } 66 #define S(s) sstrn(s, sizeof(s)-1) 69 #define SC(s) scstrn(s, sizeof(s)-1) 75 #ifndef UCX_NO_SSTR_FORMAT_MACROS 77 #define SFMT(s) (int) (s).length, (s).ptr 153 #define SCSTR(s) s2scstr(s) 182 #if __STDC_VERSION__ >= 201112L 188 #define SCSTR(str) _Generic(str, sstr_t: ucx_ss2sc, scstr_t: ucx_sc2sc)(str) 190 #elif defined(__GNUC__) || defined(__clang__) 197 #define SCSTR(str) __builtin_choose_expr( \ 198 __builtin_types_compatible_p(typeof(str), sstr_t), \ 209 #define SCSTR(str) ({typeof(str) ucx_tmp_var_str = str; \ 210 scstr_t ucx_tmp_var_c; \ 211 ucx_tmp_var_c.ptr = ucx_tmp_var_str.ptr;\ 212 ucx_tmp_var_c.length = ucx_tmp_var_str.length;\ 233 #define SCSTR(str) ucx_ss2c_s(str) 329 #define sstrnlen(count, ...) scstrnlen(count, __VA_ARGS__) 361 #define sstrcat(count, s1, ...) scstrcat(count, SCSTR(s1), __VA_ARGS__) 399 #define sstrcat_a(alloc, count, s1, ...) \ 400 scstrcat_a(alloc, count, SCSTR(s1), __VA_ARGS__) 560 #define sstrstr(string, match) scstrsstr(string, SCSTR(match)) 594 #define sstrscstr(string, match) scstrscstr(string, SCSTR(match)) 692 #define sstrsplit(string, delim, count) \ 693 scstrsplit(SCSTR(string), SCSTR(delim), count) 736 #define sstrsplit_a(allocator, string, delim, count) \ 737 scstrsplit_a(allocator, SCSTR(string), SCSTR(delim), count) 765 #define sstrcmp(s1, s2) scstrcmp(SCSTR(s1), SCSTR(s2)) 795 #define sstrcasecmp(s1, s2) scstrcasecmp(SCSTR(s1), SCSTR(s2)) 827 #define sstrdup(string) scstrdup(SCSTR(string)) 863 #define sstrdup_a(allocator, string) scstrdup_a(allocator, SCSTR(string)) 920 #define sstrprefix(string, prefix) scstrprefix(SCSTR(string), SCSTR(prefix)) 938 #define sstrsuffix(string, suffix) scstrsuffix(SCSTR(string), SCSTR(suffix)) 956 #define sstrcaseprefix(string, prefix) \ 957 scstrcaseprefix(SCSTR(string), SCSTR(prefix)) 975 #define sstrcasesuffix(string, suffix) \ 976 scstrcasesuffix(SCSTR(string), SCSTR(suffix)) 999 #define sstrlower(string) scstrlower(SCSTR(string)) 1025 #define sstrlower_a(allocator, string) scstrlower_a(allocator, SCSTR(string)) 1048 #define sstrupper(string) scstrupper(SCSTR(string)) 1073 #define sstrupper_a(allocator, string) scstrupper_a(allocator, string) sstr_t sstr(char *cstring)
Creates a new sstr_t based on a C string.
Definition: string.c:43
sstr_t scstrdup(scstr_t string)
Creates a duplicate of the specified string.
Definition: string.c:520
The UCX string structure.
Definition: string.h:90
sstr_t scstrlower(scstr_t string)
Returns a lower case version of a string.
Definition: string.c:633
sstr_t sstrsubsl(sstr_t string, size_t start, size_t length)
Returns a substring with the given length starting at the specified location.
Definition: string.c:201
scstr_t scstrtrim(scstr_t string)
Omits leading and trailing spaces.
Definition: string.c:563
sstr_t * scstrsplit_a(UcxAllocator *allocator, scstr_t string, scstr_t delim, ssize_t *count)
Performing scstrsplit() using a UcxAllocator.
Definition: string.c:400
Main UCX Header providing most common definitions.
scstr_t scstrrchr(scstr_t string, int chr)
Returns an immutable substring starting at the location of the last occurrence of the specified chara...
Definition: string.c:270
scstr_t ucx_sc2sc(scstr_t str)
One of two type adjustment functions that return an scstr_t.
Definition: string.c:666
int scstrprefix(scstr_t string, scstr_t prefix)
Checks, if a string has a specific prefix.
Definition: string.c:570
sstr_t sstrrchr(sstr_t string, int chr)
Returns a substring starting at the location of the last occurrence of the specified character...
Definition: string.c:254
sstr_t sstrtrim(sstr_t string)
Omits leading and trailing spaces.
Definition: string.c:556
const char * ptr
A constant pointer to the immutable string (not necessarily NULL-terminated)
Definition: string.h:104
The UCX string structure for immutable (constant) strings.
Definition: string.h:101
size_t scstrnlen(size_t count,...)
Returns the accumulated length of all specified strings.
Definition: string.c:72
sstr_t sstrsubs(sstr_t string, size_t start)
Returns a substring starting at the specified location.
Definition: string.c:197
int scstrcasecmp(scstr_t s1, scstr_t s2)
Compares two UCX strings ignoring the case.
Definition: string.c:506
scstr_t ucx_ss2sc(sstr_t str)
One of two type adjustment functions that return an scstr_t.
Definition: string.c:669
int scstrcmp(scstr_t s1, scstr_t s2)
Compares two UCX strings with standard memcmp().
Definition: string.c:496
char * ptr
A pointer to the string (not necessarily NULL-terminated)
Definition: string.h:93
UCX allocator data structure containing memory management functions.
Definition: allocator.h:88
sstr_t * scstrsplit(scstr_t string, scstr_t delim, ssize_t *count)
Splits a string into parts by using a delimiter string.
Definition: string.c:396
sstr_t scstrlower_a(UcxAllocator *allocator, scstr_t string)
Returns a lower case version of a string.
Definition: string.c:641
size_t length
The length of the string.
Definition: string.h:95
sstr_t sstrchr(sstr_t string, int chr)
Returns a substring starting at the location of the first occurrence of the specified character...
Definition: string.c:246
sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t string)
Creates a duplicate of the specified string using a UcxAllocator.
Definition: string.c:524
scstr_t scstrn(const char *cstring, size_t length)
Creates a new scstr_t of the specified length based on a constant C string.
Definition: string.c:64
scstr_t ucx_ss2c_s()
Converts a UCX string to an immutable UCX string (scstr_t).
int scstrsuffix(scstr_t string, scstr_t suffix)
Checks, if a string has a specific suffix.
Definition: string.c:585
scstr_t scstr(const char *cstring)
Creates a new scstr_t based on a constant C string.
Definition: string.c:57
Allocator for custom memory management.
scstr_t scstrscstr(scstr_t string, scstr_t match)
Returns an immutable substring starting at the location of the first occurrence of the specified immu...
Definition: string.c:375
sstr_t scstrcat_a(UcxAllocator *alloc, size_t count, scstr_t s1,...)
Concatenates two or more strings using a UcxAllocator.
Definition: string.c:167
sstr_t scstrcat(size_t count, scstr_t s1,...)
Concatenates two or more strings.
Definition: string.c:159
sstr_t scstrupper_a(UcxAllocator *allocator, scstr_t string)
Returns a upper case version of a string.
Definition: string.c:657
sstr_t scstrupper(scstr_t string)
Returns a upper case version of a string.
Definition: string.c:649
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...
Definition: string.c:214
sstr_t sstrn(char *cstring, size_t length)
Creates a new sstr_t of the specified length based on a C string.
Definition: string.c:50
size_t length
The length of the string.
Definition: string.h:106
int scstrcasesuffix(scstr_t string, scstr_t suffix)
Checks, if a string has a specific suffix, ignoring the case.
Definition: string.c:617
scstr_t scstrchr(scstr_t string, int chr)
Returns an immutable substring starting at the location of the first occurrence of the specified char...
Definition: string.c:262
scstr_t scstrsubs(scstr_t string, size_t start)
Returns a substring of an immutable string starting at the specified location.
Definition: string.c:210
sstr_t scstrsstr(sstr_t string, scstr_t match)
Returns a substring starting at the location of the first occurrence of the specified string...
Definition: string.c:357
int scstrcaseprefix(scstr_t string, scstr_t prefix)
Checks, if a string has a specific prefix, ignoring the case.
Definition: string.c:601