ucx
UAP Common Extensions
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
35
36#ifndef UCX_STRING_H
37#define UCX_STRING_H
38
39#include "common.h"
40#include "allocator.h"
41
42#include <string.h>
43
45#define CX_NULLSTR cx_mutstr(NULL)
46
48#define CX_SFMT(s) (int) (s).length, (s).ptr
49
51#define CX_PRIstr ".*s"
52
56CX_EXPORT extern const unsigned cx_strstr_sbo_size;
57
66 char *ptr;
68 size_t length;
69};
70
74typedef struct cx_mutstr_s cxmutstr;
75
84 const char *ptr;
86 size_t length;
87};
88
92typedef struct cx_string_s cxstring;
93
139
144
165 str.ptr = cstring;
166 str.length = cstring == NULL ? 0 : strlen(cstring);
167 return str;
168}
169
187CX_INLINE cxmutstr cx_mutstrn(char *cstring, size_t length) {
189 str.ptr = cstring;
190 str.length = length;
191 return str;
192}
193
212CX_INLINE cxstring cx_str(const char *cstring) {
214 str.ptr = cstring;
215 str.length = cstring == NULL ? 0 : strlen(cstring);
216 return str;
217}
218
219
237CX_INLINE cxstring cx_strn(const char *cstring, size_t length) {
239 str.ptr = cstring;
240 str.length = length;
241 return str;
242}
243
244#ifdef __cplusplus
247 return str;
248}
251 return str;
252}
255 return cx_mutstr(str);
256}
258CX_CPPDECL cxmutstr cx_strcast_m(unsigned char *str) {
259 return cx_mutstr(reinterpret_cast<char*>(str));
260}
262CX_CPPDECL cxstring cx_strcast_m(const char *str) {
263 return cx_str(str);
264}
266CX_CPPDECL cxstring cx_strcast_m(const unsigned char *str) {
267 return cx_str(reinterpret_cast<const char*>(str));
268}
271 return cx_strn(str.ptr, str.length);
272}
275 return str;
276}
277#define cx_strcast(s) cx_strcast_(cx_strcast_m(s))
278#else
290
301
311 return cx_mutstr((char*)str);
312}
313
323 return cx_mutstr(str);
324}
325
334CX_INLINE cxstring cx_strcast_ucc(const unsigned char *str) {
335 return cx_str((const char*)str);
336}
337
347 return cx_str(str);
348}
349
356#define cx_strcast_m(str) _Generic((str), \
357 cxstring: cx_strcast_cxs, \
358 cxmutstr: cx_strcast_cxms, \
359 const unsigned char*: cx_strcast_ucc, \
360 unsigned char *: cx_strcast_uc, \
361 const char*: cx_strcast_cc, \
362 char *: cx_strcast_c) (str)
363
372
381
383#define cx_strcast_(str) _Generic((str), \
384 cxmutstr: cx_strcast_1, \
385 cxstring: cx_strcast_2)(str)
386
393#define cx_strcast(str) cx_strcast_(cx_strcast_m(str))
394#endif
395
403 cxmutstr s;
404 s.ptr = (char*)str.ptr;
405 s.length = str.length;
406 return s;
407}
408
423
439
454int cx_strcpy_a_(const CxAllocator *alloc, cxmutstr *dest, cxstring src);
455
470#define cx_strcpy_a(alloc, dest, src) cx_strcpy_a_(alloc, dest, cx_strcast(src))
471
485#define cx_strcpy(dest, src) cx_strcpy_a(cxDefaultAllocator, dest, src)
486
500size_t cx_strlen(size_t count, ...);
501
524 cxmutstr str, size_t count, ...);
525
542#define cx_strcat(str, count, ...) \
543 cx_strcat_a(cxDefaultAllocator, str, count, __VA_ARGS__)
544
557cxstring cx_strsubsl_(cxstring string, size_t start, size_t length);
558
570cxstring cx_strsubs_(cxstring string, size_t start);
571
579cxmutstr cx_strsubs_m_(cxmutstr string, size_t start) {
580 return cx_mutstrcast(cx_strsubs_(cx_strcast(string), start));
581}
582
591cxmutstr cx_strsubsl_m_(cxmutstr string, size_t start, size_t length) {
592 return cx_mutstrcast(cx_strsubsl_(cx_strcast(string), start, length));
593}
594
595#ifdef __cplusplus
596CX_CPPDECL cxstring cx_strsubs_cpp_(cxstring string, size_t start) {
597 return cx_strsubs_(string, start);
598}
599CX_CPPDECL cxstring cx_strsubsl_cpp_(cxstring string, size_t start, size_t length) {
600 return cx_strsubsl_(string, start, length);
601}
602CX_CPPDECL cxmutstr cx_strsubs_cpp_(cxmutstr string, size_t start) {
603 return cx_strsubs_m_(string, start);
604}
605CX_CPPDECL cxmutstr cx_strsubsl_cpp_(cxmutstr string, size_t start, size_t length) {
606 return cx_strsubsl_m_(string, start, length);
607}
608#define cx_strsubs(string, start) cx_strsubs_cpp_(cx_strcast_m(string), start)
609#define cx_strsubsl(string, start, length) cx_strsubsl_cpp_(cx_strcast_m(string), start, length)
610#else
624#define cx_strsubs(string, start) _Generic(cx_strcast_m(string), \
625 cxstring: cx_strsubs_, \
626 cxmutstr: cx_strsubs_m_)(cx_strcast_m(string), start)
627
645#define cx_strsubsl(string, start, length) _Generic(cx_strcast_m(string), \
646 cxstring: cx_strsubsl_, \
647 cxmutstr: cx_strsubsl_m_)(cx_strcast_m(string), start, length)
648#endif
649
661char cx_strat_(cxstring str, off_t index) {
662 size_t i;
663 if (index >= 0) {
664 i = index;
665 } else {
666 i = (size_t) (str.length + index);
667 }
668 if (i >= str.length) {
669 return '\0';
670 }
671 return str.ptr[i];
672}
673
687#define cx_strat(str, index) cx_strat_(cx_strcast(str), index)
688
698cxstring cx_strchr_(cxstring string, int chr);
699
710
711#ifdef __cplusplus
712CX_CPPDECL cxstring cx_strchr_cpp_(cxstring string, int chr) {
713 return cx_strchr_(string, chr);
714}
715CX_CPPDECL cxmutstr cx_strchr_cpp_(cxmutstr string, int chr) {
716 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr));
717}
718#define cx_strchr(s, chr) cx_strchr_cpp_(cx_strcast_m(s), chr)
719CX_CPPDECL cxstring cx_strrchr_cpp_(cxstring string, int chr) {
720 return cx_strrchr_(string, chr);
721}
722CX_CPPDECL cxmutstr cx_strrchr_cpp_(cxmutstr string, int chr) {
723 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr));
724}
725#define cx_strrchr(s, chr) cx_strrchr_cpp_(cx_strcast_m(s), chr)
726#else
734 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr));
735}
736
743 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr));
744}
745
757#define cx_strchr(string, chr) _Generic(cx_strcast_m(string), \
758 cxstring: cx_strchr_, \
759 cxmutstr: cx_strchr_m_)(cx_strcast_m(string), chr)
760
772#define cx_strrchr(string, chr) _Generic(cx_strcast_m(string), \
773 cxstring: cx_strrchr_, \
774 cxmutstr: cx_strrchr_m_)(cx_strcast_m(string), chr)
775#endif
776
790
791#ifdef __cplusplus
792CX_CPPDECL cxstring cx_strstr_cpp_(cxstring haystack, cxstring needle) {
793 return cx_strstr_(haystack, needle);
794}
795CX_CPPDECL cxmutstr cx_strstr_cpp_(cxmutstr haystack, cxstring needle) {
796 return cx_mutstrcast(cx_strstr_(cx_strcast(haystack), needle));
797}
798#define cx_strstr(h,n) cx_strstr_cpp_(cx_strcast_m(h), cx_strcast(n))
799#else
807 return cx_mutstrcast(cx_strstr_(cx_strcast(haystack), needle));
808}
809
824#define cx_strstr(haystack, needle) _Generic(cx_strcast_m(haystack), \
825 cxstring: cx_strstr_,\
826 cxmutstr: cx_strstr_m_)(cx_strcast_m(haystack), cx_strcast(needle))
827#endif
828
843 size_t limit, cxstring *output);
844
859size_t cx_strsplit_a_(const CxAllocator *allocator,
860 cxstring string, cxstring delim,
861 size_t limit, cxstring **output);
862
863
878 size_t limit, cxmutstr *output);
879
894size_t cx_strsplit_ma_(const CxAllocator *allocator,
895 cxmutstr string, cxstring delim, size_t limit,
896 cxmutstr **output);
897
898#ifdef __cplusplus
899CX_CPPDECL size_t cx_strsplit_cpp_(cxstring string, cxstring delim,
900 size_t limit, cxstring *output) {
901 return cx_strsplit_(string, delim, limit, output);
902}
903CX_CPPDECL size_t cx_strsplit_cpp_(cxmutstr string, cxstring delim,
904 size_t limit, cxmutstr *output) {
905 return cx_strsplit_m_(string, delim, limit, output);
906}
907CX_CPPDECL size_t cx_strsplit_a_cpp_(const CxAllocator *allocator,
908 cxstring string, cxstring delim, size_t limit, cxstring **output) {
909 return cx_strsplit_a_(allocator, string, delim, limit, output);
910}
911CX_CPPDECL size_t cx_strsplit_a_cpp_(const CxAllocator *allocator,
912 cxmutstr string, cxstring delim, size_t limit, cxmutstr **output) {
913 return cx_strsplit_ma_(allocator, string, delim, limit, output);
914}
915#define cx_strsplit(string, delim, limit, output) \
916 cx_strsplit_cpp_(cx_strcast_m(string), cx_strcast(delim), limit, output)
917#define cx_strsplit_a(allocator, string, delim, limit, output) \
918 cx_strsplit_a_cpp_(allocator, cx_strcast_m(string), cx_strcast(delim), limit, output)
919#else
933#define cx_strsplit(string, delim, limit, output) \
934 _Generic(cx_strcast_m(string), \
935 cxstring: cx_strsplit_, \
936 cxmutstr: cx_strsplit_m_)\
937 (cx_strcast_m(string), cx_strcast(delim), limit, output)
938
958#define cx_strsplit_a(allocator, string, delim, limit, output) \
959 _Generic(cx_strcast_m(string), \
960 cxstring: cx_strsplit_a_, \
961 cxmutstr: cx_strsplit_ma_)\
962 (allocator, cx_strcast_m(string), cx_strcast(delim), limit, output)
963#endif
964
975
984#define cx_strcmp(s1, s2) cx_strcmp_(cx_strcast(s1), cx_strcast(s2))
985
996
1005#define cx_strcasecmp(s1, s2) cx_strcasecmp_(cx_strcast(s1), cx_strcast(s2))
1006
1021int cx_strcmp_p(const void *s1, const void *s2);
1022
1034int cx_strcasecmp_p(const void *s1, const void *s2);
1035
1049cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string);
1050
1064#define cx_strdup_a(allocator, string) cx_strdup_a_((allocator), cx_strcast(string))
1065
1079#define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
1080
1089
1090#ifdef __cplusplus
1091CX_CPPDECL cxstring cx_strtrim_cpp_(cxstring string) {
1092 return cx_strtrim_(string);
1093}
1094CX_CPPDECL cxmutstr cx_strtrim_cpp_(cxmutstr string) {
1095 return cx_mutstrcast(cx_strtrim_(cx_strcast(string)));
1096}
1097#define cx_strtrim(string) cx_strtrim_cpp_(cx_strcast_m(string))
1098#else
1107
1117#define cx_strtrim(string) _Generic(cx_strcast_m(string), \
1118 cxstring: cx_strtrim_, \
1119 cxmutstr: cx_strtrim_m_)(cx_strcast_m(string))
1120#endif
1121
1131bool cx_strprefix_(cxstring string, cxstring prefix);
1132
1141#define cx_strprefix(string, prefix) cx_strprefix_(cx_strcast(string), cx_strcast(prefix))
1142
1152bool cx_strsuffix_(cxstring string, cxstring suffix);
1153
1162#define cx_strsuffix(string, suffix) cx_strsuffix_(cx_strcast(string), cx_strcast(suffix))
1163
1174
1183#define cx_strcaseprefix(string, prefix) cx_strcaseprefix_(cx_strcast(string), cx_strcast(prefix))
1184
1195
1204#define cx_strcasesuffix(string, suffix) cx_strcasesuffix_(cx_strcast(string), cx_strcast(suffix))
1205
1224 cxstring str, cxstring search, cxstring replacement, size_t replmax);
1225
1244#define cx_strreplacen_a(allocator, str, search, replacement, replmax) \
1245 cx_strreplace_(allocator, cx_strcast(str), cx_strcast(search), cx_strcast(replacement), replmax)
1246
1264#define cx_strreplacen(str, search, replacement, replmax) \
1265 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax)
1266
1282#define cx_strreplace_a(allocator, str, search, replacement) \
1283 cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX)
1284
1299#define cx_strreplace(str, search, replacement) \
1300 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX)
1301
1312
1321#define cx_strtok(str, delim, limit) \
1322 cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit))
1323
1336
1337#ifdef __cplusplus
1339 return cx_strtok_next_(ctx, token);
1340}
1342 // Note: this is actually UB - fixed with start_lifetime_as() in C++23
1343 // but it works on all supported platforms
1344 return cx_strtok_next_(ctx, reinterpret_cast<cxstring*>(token));
1345}
1346#else // ! __cplusplus
1358#define cx_strtok_next(ctx, token) _Generic((token), \
1359 cxstring*: cx_strtok_next_, \
1360 cxmutstr*: cx_strtok_next_)(ctx, (cxstring*)token)
1361#endif
1362
1371void cx_strtok_delim(CxStrtokCtx *ctx, const cxstring *delim, size_t count);
1372
1373/* ------------------------------------------------------------------------- *
1374 * string to number conversion functions *
1375 * ------------------------------------------------------------------------- */
1376
1392int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep);
1393
1409int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep);
1410
1426int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep);
1427
1443int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep);
1444
1460int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep);
1461
1477int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep);
1478
1494int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep);
1495
1511int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep);
1512
1528int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep);
1529
1545int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep);
1546
1562int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep);
1563
1579int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep);
1580
1596int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep);
1597
1613int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep);
1614
1630int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep);
1631
1647int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep);
1648
1664int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep);
1665
1681int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep);
1682
1698int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep);
1699
1714#define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep)
1715
1730#define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep)
1731
1746#define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep)
1747
1762#define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep)
1763
1778#define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep)
1779
1794#define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep)
1795
1810#define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep)
1811
1826#define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep)
1827
1842#define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep)
1843
1858#define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep)
1859
1874#define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep)
1875
1890#define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep)
1891
1906#define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep)
1907
1922#define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep)
1923
1938#define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep)
1939
1954#define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep)
1955
1970#define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep)
1971
1988#define cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",")
1989
2006#define cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",")
2007
2024#define cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",")
2025
2042#define cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",")
2043
2060#define cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",")
2061
2078#define cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",")
2079
2096#define cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",")
2097
2114#define cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",")
2115
2132#define cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",")
2133
2150#define cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",")
2151
2168#define cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",")
2169
2186#define cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",")
2187
2204#define cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",")
2205
2222#define cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",")
2223
2240#define cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",")
2241
2258#define cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",")
2259
2276#define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",")
2277
2292#define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep)
2293
2307#define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep)
2308
2325#define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",")
2326
2342#define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",")
2343
2344#endif //UCX_STRING_H
Interface for custom allocators.
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
Common definitions and feature checks.
#define CX_INLINE
Declares a function to be inlined.
Definition common.h:311
#define CX_CSTR_ARG(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:211
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:289
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NODISCARD
Warn about discarded return value.
Definition common.h:256
#define CX_NONNULL_ARG(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
#define CX_ACCESS_R(...)
Specifies that the function will only read through the given pointer.
Definition common.h:230
#define CX_ACCESS_RW(...)
Specifies that the function will read and write through the given pointer.
Definition common.h:238
#define CX_CPPDECL
Declares a compatibility function for C++ builds.
Definition common.h:316
#define CX_ACCESS_W(...)
Specifies that the function will only write through the given pointer.
Definition common.h:246
Strings that know their length.
static cxstring cx_strcast_1(cxmutstr str)
Internal function, do not use.
Definition string.h:369
cxmutstr cx_strreplace_(const CxAllocator *allocator, cxstring str, cxstring search, cxstring replacement, size_t replmax)
Replaces a string with another string.
int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep)
Converts a string to a number.
struct cx_string_s cxstring
An immutable string.
Definition string.h:92
static cxstring cx_strcast_cxs(cxstring str)
Internal function, do not use.
Definition string.h:298
const unsigned cx_strstr_sbo_size
The maximum length of the "needle" in cx_strstr() that can use SBO.
int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep)
Converts a string to a number.
cxstring cx_strchr_(cxstring string, int chr)
Searches for a character in a string.
int cx_strcasecmp_p(const void *s1, const void *s2)
Compares two strings ignoring case.
size_t cx_strsplit_a_(const CxAllocator *allocator, cxstring string, cxstring delim, size_t limit, cxstring **output)
Splits a given string using a delimiter string.
static cxmutstr cx_mutstrcast(cxstring str)
Casts away constness and converts a cxstring to a cxmutstr.
Definition string.h:402
cxstring cx_strsubsl_(cxstring string, size_t start, size_t length)
Returns a substring.
int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strcmp_(cxstring s1, cxstring s2)
Compares two strings.
int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep)
Converts a string to a number.
static cxmutstr cx_strrchr_m_(cxmutstr string, int chr)
Internal conversion function - do not use.
Definition string.h:742
static cxmutstr cx_strcast_uc(unsigned char *str)
Internal function, do not use.
Definition string.h:310
int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep)
Converts a string to a number.
static cxstring cx_str(const char *cstring)
Wraps a string that must be zero-terminated.
Definition string.h:212
cxstring cx_strtrim_(cxstring string)
Trims a string.
int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep)
Converts a string to a number.
static cxmutstr cx_strcast_cxms(cxmutstr str)
Internal function, do not use.
Definition string.h:287
void cx_strfree(cxmutstr *str)
Passes the pointer in this string to the cxDefaultAllocator's free() function.
struct cx_mutstr_s cxmutstr
A mutable string.
Definition string.h:74
int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep)
Converts a string to a number.
size_t cx_strsplit_ma_(const CxAllocator *allocator, cxmutstr string, cxstring delim, size_t limit, cxmutstr **output)
Splits a given string using a delimiter string.
cxstring cx_strsubs_(cxstring string, size_t start)
Returns a substring.
static cxmutstr cx_strsubsl_m_(cxmutstr string, size_t start, size_t length)
Internal conversion function - do not use.
Definition string.h:591
struct cx_strtok_ctx_s CxStrtokCtx
A string tokenizing context.
Definition string.h:143
int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep)
Converts a string to a number.
static cxmutstr cx_mutstr(char *cstring)
Wraps a mutable string that must be zero-terminated.
Definition string.h:163
static cxmutstr cx_strchr_m_(cxmutstr string, int chr)
Internal conversion function - do not use.
Definition string.h:733
cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string)
Creates a duplicate of the specified string.
#define cx_strcast(str)
Converts any string to a cxstring.
Definition string.h:393
static cxmutstr cx_mutstrn(char *cstring, size_t length)
Wraps a string that does not need to be zero-terminated.
Definition string.h:187
int cx_strcmp_p(const void *s1, const void *s2)
Compares two strings.
static cxstring cx_strcast_ucc(const unsigned char *str)
Internal function, do not use.
Definition string.h:334
bool cx_strcaseprefix_(cxstring string, cxstring prefix)
Checks if a string has a specific prefix, ignoring the case.
int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep)
Converts a string to a double precision floating-point number.
int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep)
Converts a string to a number.
size_t cx_strsplit_(cxstring string, cxstring delim, size_t limit, cxstring *output)
Splits a given string using a delimiter string.
static char cx_strat_(cxstring str, off_t index)
Returns the character at the specified index offset.
Definition string.h:661
static cxmutstr cx_strcast_c(char *str)
Internal function, do not use.
Definition string.h:322
int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep)
Converts a string to a number.
int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep)
Converts a string to a single precision floating-point number.
cxmutstr cx_strcat_a(const CxAllocator *alloc, cxmutstr str, size_t count,...)
Concatenates strings.
CxStrtokCtx cx_strtok_(cxstring str, cxstring delim, size_t limit)
Creates a string tokenization context.
static cxstring cx_strn(const char *cstring, size_t length)
Wraps a string that does not need to be zero-terminated.
Definition string.h:237
int cx_strcpy_a_(const CxAllocator *alloc, cxmutstr *dest, cxstring src)
Copies a string.
int cx_strcasecmp_(cxstring s1, cxstring s2)
Compares two strings ignoring case.
size_t cx_strlen(size_t count,...)
Returns the accumulated length of all specified strings.
#define cx_strtok_next(ctx, token)
Returns the next token.
Definition string.h:1358
static cxstring cx_strcast_2(cxstring str)
Internal function, do not use.
Definition string.h:378
int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep)
Converts a string to a number.
size_t cx_strsplit_m_(cxmutstr string, cxstring delim, size_t limit, cxmutstr *output)
Splits a given string using a delimiter string.
static cxmutstr cx_strsubs_m_(cxmutstr string, size_t start)
Internal conversion function - do not use.
Definition string.h:579
int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep)
Converts a string to a number.
cxstring cx_strrchr_(cxstring string, int chr)
Searches for a character in a string.
static cxmutstr cx_strstr_m_(cxmutstr haystack, cxstring needle)
Internal conversion - do not use.
Definition string.h:806
int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep)
Converts a string to a number.
bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token)
Returns the next token.
bool cx_strprefix_(cxstring string, cxstring prefix)
Checks if a string has a specific prefix.
static cxstring cx_strcast_cc(const char *str)
Internal function, do not use.
Definition string.h:346
#define cx_strcast_(str)
internal conversion macro
Definition string.h:383
bool cx_strsuffix_(cxstring string, cxstring suffix)
Checks if a string has a specific suffix.
cxstring cx_strstr_(cxstring haystack, cxstring needle)
Searches for a specific substring.
static cxmutstr cx_strtrim_m_(cxmutstr string)
Internal conversion function.
Definition string.h:1104
void cx_strtok_delim(CxStrtokCtx *ctx, const cxstring *delim, size_t count)
Defines an array of more delimiters for the specified tokenization context.
#define cx_strcast_m(str)
Wraps any string into an UCX string.
Definition string.h:356
int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep)
Converts a string to a number.
bool cx_strcasesuffix_(cxstring string, cxstring suffix)
Checks, if a string has a specific suffix, ignoring the case.
int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep)
Converts a string to a number.
void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str)
Passes the pointer in this string to the allocator's free function.
The UCX string structure.
Definition string.h:61
char * ptr
A pointer to the string.
Definition string.h:66
size_t length
The length of the string.
Definition string.h:68
The UCX string structure for immutable (constant) strings.
Definition string.h:79
size_t length
The length of the string.
Definition string.h:86
const char * ptr
A pointer to the immutable string.
Definition string.h:84
Context for string tokenizing.
Definition string.h:97
size_t delim_pos
Position of the next delimiter in the source string.
Definition string.h:125
cxstring str
The string to tokenize.
Definition string.h:101
cxstring delim
The primary delimiter.
Definition string.h:105
size_t delim_more_count
Length of the array containing more delimiters.
Definition string.h:113
size_t pos
Position of the currently active token in the source string.
Definition string.h:117
size_t next_pos
The position of the next token in the source string.
Definition string.h:129
size_t found
The number of already found tokens.
Definition string.h:133
size_t limit
The maximum number of tokens that shall be returned.
Definition string.h:137
const cxstring * delim_more
Optional array of more delimiters.
Definition string.h:109