Mon, 26 May 2025 21:06:17 +0200
update ucx
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 579 | 29 | * @file string.h |
| 30 | * @brief Strings that know their length. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifndef UCX_STRING_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_STRING_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "allocator.h" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
| 582 | 42 | /** Expands a UCX string as printf arguments. */ |
| 43 | #define CX_SFMT(s) (int) (s).length, (s).ptr | |
| 44 | ||
| 45 | /** Format specifier for a UCX string */ | |
| 46 | #define CX_PRIstr ".*s" | |
| 47 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | /** |
| 579 | 49 | * The maximum length of the "needle" in cx_strstr() that can use SBO. |
| 50 | */ | |
| 51 | cx_attr_export | |
| 52 | extern const unsigned cx_strstr_sbo_size; | |
| 53 | ||
| 54 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | * The UCX string structure. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | struct cx_mutstr_s { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | * A pointer to the string. |
| 579 | 60 | * @note The string is not necessarily @c NULL terminated. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | char *ptr; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | /** The length of the string */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | size_t length; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | * A mutable string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | typedef struct cx_mutstr_s cxmutstr; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | * The UCX string structure for immutable (constant) strings. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | struct cx_string_s { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | * A pointer to the immutable string. |
| 579 | 78 | * @note The string is not necessarily @c NULL terminated. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | */ |
| 579 | 80 | const char *ptr; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | /** The length of the string */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | size_t length; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | * An immutable string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | typedef struct cx_string_s cxstring; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | /** |
| 490 | 91 | * Context for string tokenizing. |
| 92 | */ | |
| 93 | struct cx_strtok_ctx_s { | |
| 94 | /** | |
| 95 | * The string to tokenize. | |
| 96 | */ | |
| 97 | cxstring str; | |
| 98 | /** | |
| 99 | * The primary delimiter. | |
| 100 | */ | |
| 101 | cxstring delim; | |
| 102 | /** | |
| 103 | * Optional array of more delimiters. | |
| 104 | */ | |
| 579 | 105 | const cxstring *delim_more; |
| 490 | 106 | /** |
| 107 | * Length of the array containing more delimiters. | |
| 108 | */ | |
| 109 | size_t delim_more_count; | |
| 110 | /** | |
| 111 | * Position of the currently active token in the source string. | |
| 112 | */ | |
| 113 | size_t pos; | |
| 114 | /** | |
| 115 | * Position of next delimiter in the source string. | |
| 116 | * | |
| 117 | * If the tokenizer has not yet returned a token, the content of this field | |
| 118 | * is undefined. If the tokenizer reached the end of the string, this field | |
| 119 | * contains the length of the source string. | |
| 120 | */ | |
| 121 | size_t delim_pos; | |
| 122 | /** | |
| 123 | * The position of the next token in the source string. | |
| 124 | */ | |
| 125 | size_t next_pos; | |
| 126 | /** | |
| 127 | * The number of already found tokens. | |
| 128 | */ | |
| 129 | size_t found; | |
| 130 | /** | |
| 131 | * The maximum number of tokens that shall be returned. | |
| 132 | */ | |
| 133 | size_t limit; | |
| 134 | }; | |
| 135 | ||
| 136 | /** | |
| 137 | * A string tokenizing context. | |
| 138 | */ | |
| 139 | typedef struct cx_strtok_ctx_s CxStrtokCtx; | |
| 140 | ||
| 141 | #ifdef __cplusplus | |
| 142 | extern "C" { | |
| 143 | ||
| 144 | /** | |
| 145 | * A literal initializer for an UCX string structure. | |
| 146 | * | |
| 147 | * @param literal the string literal | |
| 148 | */ | |
| 149 | #define CX_STR(literal) cxstring{literal, sizeof(literal) - 1} | |
| 150 | ||
| 151 | #else // __cplusplus | |
| 152 | ||
| 153 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | * A literal initializer for an UCX string structure. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | * |
| 579 | 156 | * The argument MUST be a string (const char*) @em literal. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | * @param literal the string literal |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | */ |
| 579 | 160 | #define CX_STR(literal) ((cxstring){literal, sizeof(literal) - 1}) |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | * Wraps a mutable string that must be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | * |
| 579 | 168 | * The length is implicitly inferred by using a call to @c strlen(). |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | * |
| 579 | 170 | * @note the wrapped string will share the specified pointer to the string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | * If you do want a copy, use cx_strdup() on the return value of this function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | * If you need to wrap a constant string, use cx_str(). |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | * @param cstring the string to wrap, must be zero-terminated |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | * @see cx_mutstrn() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | */ |
| 579 | 180 | cx_attr_nonnull |
| 181 | cx_attr_nodiscard | |
| 182 | cx_attr_cstr_arg(1) | |
| 183 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | cxmutstr cx_mutstr(char *cstring); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | * Wraps a string that does not need to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | * |
| 579 | 189 | * The argument may be @c NULL if the length is zero. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | * |
| 579 | 191 | * @note the wrapped string will share the specified pointer to the string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | * If you do want a copy, use cx_strdup() on the return value of this function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | * If you need to wrap a constant string, use cx_strn(). |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | * |
| 579 | 196 | * @param cstring the string to wrap (or @c NULL, only if the length is zero) |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | * @param length the length of the string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | * @see cx_mutstr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | */ |
| 579 | 202 | cx_attr_nodiscard |
| 203 | cx_attr_access_rw(1, 2) | |
| 204 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | cxmutstr cx_mutstrn( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | char *cstring, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | * Wraps a string that must be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | * |
| 579 | 213 | * The length is implicitly inferred by using a call to @c strlen(). |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | * |
| 579 | 215 | * @note the wrapped string will share the specified pointer to the string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | * If you do want a copy, use cx_strdup() on the return value of this function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | * If you need to wrap a non-constant string, use cx_mutstr(). |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | * @param cstring the string to wrap, must be zero-terminated |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | * @see cx_strn() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | */ |
| 579 | 225 | cx_attr_nonnull |
| 226 | cx_attr_nodiscard | |
| 227 | cx_attr_cstr_arg(1) | |
| 228 | cx_attr_export | |
| 229 | cxstring cx_str(const char *cstring); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | * Wraps a string that does not need to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | * |
| 579 | 235 | * The argument may be @c NULL if the length is zero. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | * |
| 579 | 237 | * @note the wrapped string will share the specified pointer to the string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | * If you do want a copy, use cx_strdup() on the return value of this function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | * If you need to wrap a non-constant string, use cx_mutstrn(). |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | * |
| 579 | 242 | * @param cstring the string to wrap (or @c NULL, only if the length is zero) |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | * @param length the length of the string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | * @see cx_str() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | */ |
| 579 | 248 | cx_attr_nodiscard |
| 249 | cx_attr_access_r(1, 2) | |
| 250 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | cxstring cx_strn( |
| 579 | 252 | const char *cstring, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | |
| 579 | 256 | #ifdef __cplusplus |
| 257 | } // extern "C" | |
| 258 | cx_attr_nodiscard | |
| 259 | static inline cxstring cx_strcast(cxmutstr str) { | |
| 260 | return cx_strn(str.ptr, str.length); | |
| 261 | } | |
| 262 | cx_attr_nodiscard | |
| 263 | static inline cxstring cx_strcast(cxstring str) { | |
| 264 | return str; | |
| 265 | } | |
| 266 | extern "C" { | |
| 267 | #else | |
| 268 | /** | |
| 269 | * Internal function, do not use. | |
| 270 | * @param str | |
| 271 | * @return | |
| 272 | * @see cx_strcast() | |
| 273 | */ | |
| 274 | cx_attr_nodiscard | |
| 275 | static inline cxstring cx_strcast_m(cxmutstr str) { | |
| 276 | return (cxstring) {str.ptr, str.length}; | |
| 277 | } | |
| 278 | /** | |
| 279 | * Internal function, do not use. | |
| 280 | * @param str | |
| 281 | * @return | |
| 282 | * @see cx_strcast() | |
| 283 | */ | |
| 284 | cx_attr_nodiscard | |
| 285 | static inline cxstring cx_strcast_c(cxstring str) { | |
| 286 | return str; | |
| 287 | } | |
| 288 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | * Casts a mutable string to an immutable string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | * |
| 579 | 292 | * Does nothing for already immutable strings. |
| 293 | * | |
| 294 | * @note This is not seriously a cast. Instead, you get a copy | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | * of the struct with the desired pointer type. Both structs still |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | * point to the same location, though! |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | * |
| 579 | 298 | * @param str (@c cxstring or @c cxmutstr) the string to cast |
| 299 | * @return (@c cxstring) an immutable copy of the string pointer | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | */ |
| 579 | 301 | #define cx_strcast(str) _Generic((str), \ |
| 302 | cxmutstr: cx_strcast_m, \ | |
| 303 | cxstring: cx_strcast_c) \ | |
| 304 | (str) | |
| 305 | #endif | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | /** |
| 582 | 308 | * Passes the pointer in this string to the cxDefaultAllocator's @c free() function. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | * |
| 579 | 310 | * The pointer in the struct is set to @c NULL and the length is set to zero |
| 311 | * which means that this function protects you against double-free. | |
| 312 | * | |
| 313 | * @note There is no implementation for cxstring, because it is unlikely that | |
| 314 | * you ever have a <code>const char*</code> you are really supposed to free. | |
| 315 | * If you encounter such situation, you should double-check your code. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | * @param str the string to free |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | */ |
| 579 | 319 | cx_attr_export |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | void cx_strfree(cxmutstr *str); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | * Passes the pointer in this string to the allocators free function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | * |
| 579 | 325 | * The pointer in the struct is set to @c NULL and the length is set to zero |
| 326 | * which means that this function protects you against double-free. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | * |
| 579 | 328 | * @note There is no implementation for cxstring, because it is unlikely that |
| 329 | * you ever have a <code>const char*</code> you are really supposed to free. | |
| 330 | * If you encounter such situation, you should double-check your code. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | * @param alloc the allocator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | * @param str the string to free |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | */ |
| 579 | 335 | cx_attr_nonnull_arg(1) |
| 336 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | void cx_strfree_a( |
| 579 | 338 | const CxAllocator *alloc, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | cxmutstr *str |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | /** |
| 582 | 343 | * Copies a string. |
| 344 | * | |
| 345 | * The memory in the @p dest structure is either allocated or re-allocated to fit the entire | |
| 346 | * source string, including a zero-terminator. | |
| 347 | * | |
| 348 | * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. | |
| 349 | * | |
| 350 | * @param alloc the allocator | |
| 351 | * @param dest a pointer to the structure where to copy the contents to | |
| 352 | * @param src the source string | |
| 353 | * | |
| 354 | * @retval zero success | |
| 355 | * @retval non-zero if re-allocation failed | |
| 356 | */ | |
| 357 | cx_attr_nonnull_arg(1) | |
| 358 | cx_attr_export | |
| 359 | int cx_strcpy_a( | |
| 360 | const CxAllocator *alloc, | |
| 361 | cxmutstr *dest, | |
| 362 | cxstring src | |
| 363 | ); | |
| 364 | ||
| 365 | ||
| 366 | /** | |
| 367 | * Copies a string. | |
| 368 | * | |
| 369 | * The memory in the @p dest structure is either allocated or re-allocated to fit the entire | |
| 370 | * source string, including a zero-terminator. | |
| 371 | * | |
| 372 | * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. | |
| 373 | * | |
| 374 | * @param dest (@c cxmutstr*) a pointer to the structure where to copy the contents to | |
| 375 | * @param src (@c cxstring) the source string | |
| 376 | * | |
| 377 | * @retval zero success | |
| 378 | * @retval non-zero if re-allocation failed | |
| 379 | */ | |
| 380 | #define cx_strcpy(dest, src) cx_strcpy_a(cxDefaultAllocator, dest, src) | |
| 381 | ||
| 382 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | * Returns the accumulated length of all specified strings. |
| 579 | 384 | * |
| 385 | * If this sum overflows, errno is set to EOVERFLOW. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | * |
| 579 | 387 | * @attention if the count argument is larger than the number of the |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | * specified strings, the behavior is undefined. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | * @param count the total number of specified strings |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | * @param ... all strings |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | * @return the accumulated length of all strings |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | */ |
| 579 | 394 | cx_attr_nodiscard |
| 395 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | size_t cx_strlen( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | size_t count, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | ... |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | /** |
| 490 | 402 | * Concatenates strings. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | * The resulting string will be allocated by the specified allocator. |
| 579 | 405 | * So developers @em must pass the return value to cx_strfree_a() eventually. |
| 490 | 406 | * |
| 579 | 407 | * If @p str already contains a string, the memory will be reallocated and |
| 490 | 408 | * the other strings are appended. Otherwise, new memory is allocated. |
| 409 | * | |
| 579 | 410 | * If memory allocation fails, the pointer in the returned string will |
| 411 | * be @c NULL. Depending on the allocator, @c errno might be set. | |
| 412 | * | |
| 413 | * @note It is guaranteed that there is only one allocation for the | |
| 414 | * resulting string. | |
| 490 | 415 | * It is also guaranteed that the returned string is zero-terminated. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | * @param alloc the allocator to use |
| 490 | 418 | * @param str the string the other strings shall be concatenated to |
| 419 | * @param count the number of the other following strings to concatenate | |
| 579 | 420 | * @param ... all other UCX strings |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | * @return the concatenated string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | */ |
| 579 | 423 | cx_attr_nodiscard |
| 424 | cx_attr_nonnull | |
| 425 | cx_attr_export | |
| 490 | 426 | cxmutstr cx_strcat_ma( |
| 579 | 427 | const CxAllocator *alloc, |
| 490 | 428 | cxmutstr str, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | size_t count, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | ... |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | /** |
| 490 | 434 | * Concatenates strings and returns a new string. |
| 435 | * | |
| 436 | * The resulting string will be allocated by the specified allocator. | |
| 579 | 437 | * So developers @em must pass the return value to cx_strfree_a() eventually. |
| 490 | 438 | * |
| 579 | 439 | * If memory allocation fails, the pointer in the returned string will |
| 440 | * be @c NULL. Depending on the allocator, @c errno might be set. | |
| 441 | * | |
| 442 | * @note It is guaranteed that there is only one allocation for the | |
| 443 | * resulting string. | |
| 490 | 444 | * It is also guaranteed that the returned string is zero-terminated. |
| 445 | * | |
| 579 | 446 | * @param alloc (@c CxAllocator*) the allocator to use |
| 447 | * @param count (@c size_t) the number of the other following strings to concatenate | |
| 448 | * @param ... all other UCX strings | |
| 449 | * @return (@c cxmutstr) the concatenated string | |
| 490 | 450 | */ |
| 451 | #define cx_strcat_a(alloc, count, ...) \ | |
| 452 | cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) | |
| 453 | ||
| 454 | /** | |
| 455 | * Concatenates strings and returns a new string. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | * |
| 582 | 457 | * The resulting string will be allocated by the cxDefaultAllocator. |
| 579 | 458 | * So developers @em must pass the return value to cx_strfree() eventually. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | * |
| 579 | 460 | * If memory allocation fails, the pointer in the returned string will |
| 461 | * be @c NULL and @c errno might be set. | |
| 462 | * | |
| 463 | * @note It is guaranteed that there is only one allocation for the | |
| 464 | * resulting string. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | * It is also guaranteed that the returned string is zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | * |
| 579 | 467 | * @param count (@c size_t) the number of the other following strings to concatenate |
| 468 | * @param ... all other UCX strings | |
| 469 | * @return (@c cxmutstr) the concatenated string | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | #define cx_strcat(count, ...) \ |
| 490 | 472 | cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
| 473 | ||
| 474 | /** | |
| 475 | * Concatenates strings. | |
| 476 | * | |
| 582 | 477 | * The resulting string will be allocated by the cxDefaultAllocator. |
| 579 | 478 | * So developers @em must pass the return value to cx_strfree() eventually. |
| 490 | 479 | * |
| 579 | 480 | * If @p str already contains a string, the memory will be reallocated and |
| 490 | 481 | * the other strings are appended. Otherwise, new memory is allocated. |
| 482 | * | |
| 579 | 483 | * If memory allocation fails, the pointer in the returned string will |
| 484 | * be @c NULL and @c errno might be set. | |
| 485 | * | |
| 486 | * @note It is guaranteed that there is only one allocation for the | |
| 487 | * resulting string. | |
| 490 | 488 | * It is also guaranteed that the returned string is zero-terminated. |
| 489 | * | |
| 579 | 490 | * @param str (@c cxmutstr) the string the other strings shall be concatenated to |
| 491 | * @param count (@c size_t) the number of the other following strings to concatenate | |
| 492 | * @param ... all other strings | |
| 493 | * @return (@c cxmutstr) the concatenated string | |
| 490 | 494 | */ |
| 495 | #define cx_strcat_m(str, count, ...) \ | |
| 496 | cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | * |
| 579 | 501 | * @attention the new string references the same memory area as the |
| 502 | * input string and is usually @em not zero-terminated. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | * Use cx_strdup() to get a copy. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | * @param start start location of the substring |
| 579 | 507 | * @return a substring of @p string starting at @p start |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | * @see cx_strsubsl() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | * @see cx_strsubs_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | * @see cx_strsubsl_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | */ |
| 579 | 513 | cx_attr_nodiscard |
| 514 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | cxstring cx_strsubs( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | size_t start |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | * |
| 579 | 523 | * The returned string will be limited to @p length bytes or the number |
| 524 | * of bytes available in @p string, whichever is smaller. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | * |
| 579 | 526 | * @attention the new string references the same memory area as the |
| 527 | * input string and is usually @em not zero-terminated. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | * Use cx_strdup() to get a copy. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531 | * @param start start location of the substring |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
532 | * @param length the maximum length of the returned string |
| 579 | 533 | * @return a substring of @p string starting at @p start |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
535 | * @see cx_strsubs() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536 | * @see cx_strsubs_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537 | * @see cx_strsubsl_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538 | */ |
| 579 | 539 | cx_attr_nodiscard |
| 540 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
541 | cxstring cx_strsubsl( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
542 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
543 | size_t start, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
544 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
545 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
546 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
547 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
548 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
549 | * |
| 579 | 550 | * @attention the new string references the same memory area as the |
| 551 | * input string and is usually @em not zero-terminated. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
552 | * Use cx_strdup() to get a copy. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
554 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555 | * @param start start location of the substring |
| 579 | 556 | * @return a substring of @p string starting at @p start |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558 | * @see cx_strsubsl_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | * @see cx_strsubs() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560 | * @see cx_strsubsl() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561 | */ |
| 579 | 562 | cx_attr_nodiscard |
| 563 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | cxmutstr cx_strsubs_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | size_t start |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
568 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
569 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571 | * |
| 579 | 572 | * The returned string will be limited to @p length bytes or the number |
| 573 | * of bytes available in @p string, whichever is smaller. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574 | * |
| 579 | 575 | * @attention the new string references the same memory area as the |
| 576 | * input string and is usually @em not zero-terminated. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | * Use cx_strdup() to get a copy. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | * @param start start location of the substring |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | * @param length the maximum length of the returned string |
| 579 | 582 | * @return a substring of @p string starting at @p start |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | * @see cx_strsubs_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | * @see cx_strsubs() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | * @see cx_strsubsl() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | */ |
| 579 | 588 | cx_attr_nodiscard |
| 589 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590 | cxmutstr cx_strsubsl_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
592 | size_t start, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597 | * Returns a substring starting at the location of the first occurrence of the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600 | * If the string does not contain the character, an empty string is returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
601 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602 | * @param string the string where to locate the character |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | * @param chr the character to locate |
| 579 | 604 | * @return a substring starting at the first location of @p chr |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606 | * @see cx_strchr_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607 | */ |
| 579 | 608 | cx_attr_nodiscard |
| 609 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | cxstring cx_strchr( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
611 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
613 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
614 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
616 | * Returns a substring starting at the location of the first occurrence of the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
618 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619 | * If the string does not contain the character, an empty string is returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | * @param string the string where to locate the character |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | * @param chr the character to locate |
| 579 | 623 | * @return a substring starting at the first location of @p chr |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625 | * @see cx_strchr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626 | */ |
| 579 | 627 | cx_attr_nodiscard |
| 628 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | cxmutstr cx_strchr_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
630 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
633 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
634 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635 | * Returns a substring starting at the location of the last occurrence of the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638 | * If the string does not contain the character, an empty string is returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | * @param string the string where to locate the character |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641 | * @param chr the character to locate |
| 579 | 642 | * @return a substring starting at the last location of @p chr |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644 | * @see cx_strrchr_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
645 | */ |
| 579 | 646 | cx_attr_nodiscard |
| 647 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
648 | cxstring cx_strrchr( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
649 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
650 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
651 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
652 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
653 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
654 | * Returns a substring starting at the location of the last occurrence of the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
657 | * If the string does not contain the character, an empty string is returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
658 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
659 | * @param string the string where to locate the character |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
660 | * @param chr the character to locate |
| 579 | 661 | * @return a substring starting at the last location of @p chr |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | * @see cx_strrchr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664 | */ |
| 579 | 665 | cx_attr_nodiscard |
| 666 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667 | cxmutstr cx_strrchr_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
670 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
671 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
672 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673 | * Returns a substring starting at the location of the first occurrence of the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674 | * specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | * |
| 579 | 676 | * If @p haystack does not contain @p needle, an empty string is returned. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | * |
| 579 | 678 | * If @p needle is an empty string, the complete @p haystack is |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | * returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | * @param haystack the string to be scanned |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | * @param needle string containing the sequence of characters to match |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | * @return a substring starting at the first occurrence of |
| 579 | 684 | * @p needle, or an empty string, if the sequence is not |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | * contained |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | * @see cx_strstr_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | */ |
| 579 | 688 | cx_attr_nodiscard |
| 689 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | cxstring cx_strstr( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | cxstring haystack, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | cxstring needle |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | * Returns a substring starting at the location of the first occurrence of the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | * specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | * |
| 579 | 699 | * If @p haystack does not contain @p needle, an empty string is returned. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | * |
| 579 | 701 | * If @p needle is an empty string, the complete @p haystack is |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702 | * returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704 | * @param haystack the string to be scanned |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705 | * @param needle string containing the sequence of characters to match |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
706 | * @return a substring starting at the first occurrence of |
| 579 | 707 | * @p needle, or an empty string, if the sequence is not |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708 | * contained |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709 | * @see cx_strstr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710 | */ |
| 579 | 711 | cx_attr_nodiscard |
| 712 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
713 | cxmutstr cx_strstr_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714 | cxmutstr haystack, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
715 | cxstring needle |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | * |
| 579 | 721 | * @note The resulting array contains strings that point to the source |
| 722 | * @p string. Use cx_strdup() to get copies. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | * @param limit the maximum number of split items |
| 579 | 727 | * @param output a preallocated array of at least @p limit length |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
729 | */ |
| 579 | 730 | cx_attr_nodiscard |
| 731 | cx_attr_nonnull | |
| 732 | cx_attr_access_w(4, 3) | |
| 733 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | size_t cx_strsplit( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | cxstring *output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | * |
| 579 | 744 | * The array pointed to by @p output will be allocated by @p allocator. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745 | * |
| 579 | 746 | * @note The resulting array contains strings that point to the source |
| 747 | * @p string. Use cx_strdup() to get copies. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748 | * |
| 579 | 749 | * @attention If allocation fails, the @c NULL pointer will be written to |
| 750 | * @p output and the number returned will be zero. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
751 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | * @param allocator the allocator to use for allocating the resulting array |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | * @param limit the maximum number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | * @param output a pointer where the address of the allocated array shall be |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | * written to |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | */ |
| 579 | 760 | cx_attr_nodiscard |
| 761 | cx_attr_nonnull | |
| 762 | cx_attr_access_w(5) | |
| 763 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | size_t cx_strsplit_a( |
| 579 | 765 | const CxAllocator *allocator, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | cxstring **output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | * |
| 579 | 776 | * @note The resulting array contains strings that point to the source |
| 777 | * @p string. Use cx_strdup() to get copies. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | * @param limit the maximum number of split items |
| 579 | 782 | * @param output a preallocated array of at least @p limit length |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
783 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
784 | */ |
| 579 | 785 | cx_attr_nodiscard |
| 786 | cx_attr_nonnull | |
| 787 | cx_attr_access_w(4, 3) | |
| 788 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | size_t cx_strsplit_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793 | cxmutstr *output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
794 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
795 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | * |
| 579 | 799 | * The array pointed to by @p output will be allocated by @p allocator. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | * |
| 579 | 801 | * @note The resulting array contains strings that point to the source |
| 802 | * @p string. Use cx_strdup() to get copies. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
803 | * |
| 579 | 804 | * @attention If allocation fails, the @c NULL pointer will be written to |
| 805 | * @p output and the number returned will be zero. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
806 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807 | * @param allocator the allocator to use for allocating the resulting array |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
808 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
809 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
810 | * @param limit the maximum number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811 | * @param output a pointer where the address of the allocated array shall be |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | * written to |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | */ |
| 579 | 815 | cx_attr_nodiscard |
| 816 | cx_attr_nonnull | |
| 817 | cx_attr_access_w(5) | |
| 818 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | size_t cx_strsplit_ma( |
| 579 | 820 | const CxAllocator *allocator, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
821 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
823 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
824 | cxmutstr **output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
826 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | * Compares two strings. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830 | * @param s1 the first string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | * @param s2 the second string |
| 579 | 832 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 833 | * than @p s2, zero if both strings equal | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
834 | */ |
| 579 | 835 | cx_attr_nodiscard |
| 836 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
837 | int cx_strcmp( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838 | cxstring s1, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | cxstring s2 |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843 | * Compares two strings ignoring case. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | * @param s1 the first string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | * @param s2 the second string |
| 579 | 847 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 848 | * than @p s2, zero if both strings equal ignoring case | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | */ |
| 579 | 850 | cx_attr_nodiscard |
| 851 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | int cx_strcasecmp( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
853 | cxstring s1, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
854 | cxstring s2 |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
855 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
856 | |
| 490 | 857 | /** |
| 858 | * Compares two strings. | |
| 859 | * | |
| 860 | * This function has a compatible signature for the use as a cx_compare_func. | |
| 861 | * | |
| 862 | * @param s1 the first string | |
| 863 | * @param s2 the second string | |
| 579 | 864 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 865 | * than @p s2, zero if both strings equal | |
| 490 | 866 | */ |
| 579 | 867 | cx_attr_nodiscard |
| 868 | cx_attr_nonnull | |
| 869 | cx_attr_export | |
| 490 | 870 | int cx_strcmp_p( |
| 579 | 871 | const void *s1, |
| 872 | const void *s2 | |
| 490 | 873 | ); |
| 874 | ||
| 875 | /** | |
| 876 | * Compares two strings ignoring case. | |
| 877 | * | |
| 878 | * This function has a compatible signature for the use as a cx_compare_func. | |
| 879 | * | |
| 880 | * @param s1 the first string | |
| 881 | * @param s2 the second string | |
| 579 | 882 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 883 | * than @p s2, zero if both strings equal ignoring case | |
| 490 | 884 | */ |
| 579 | 885 | cx_attr_nodiscard |
| 886 | cx_attr_nonnull | |
| 887 | cx_attr_export | |
| 490 | 888 | int cx_strcasecmp_p( |
| 579 | 889 | const void *s1, |
| 890 | const void *s2 | |
| 490 | 891 | ); |
| 892 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
894 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
895 | * Creates a duplicate of the specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896 | * |
| 579 | 897 | * The new string will contain a copy allocated by @p allocator. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
898 | * |
| 579 | 899 | * @note The returned string is guaranteed to be zero-terminated. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
900 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
901 | * @param allocator the allocator to use |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
902 | * @param string the string to duplicate |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
903 | * @return a duplicate of the string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
904 | * @see cx_strdup() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
905 | */ |
| 579 | 906 | cx_attr_nodiscard |
| 907 | cx_attr_nonnull | |
| 908 | cx_attr_export | |
| 909 | cxmutstr cx_strdup_a_( | |
| 910 | const CxAllocator *allocator, | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | cxstring string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | * Creates a duplicate of the specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916 | * |
| 579 | 917 | * The new string will contain a copy allocated by @p allocator. |
| 918 | * | |
| 919 | * @note The returned string is guaranteed to be zero-terminated. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920 | * |
| 579 | 921 | * @param allocator (@c CxAllocator*) the allocator to use |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922 | * @param string the string to duplicate |
| 579 | 923 | * @return (@c cxmutstr) a duplicate of the string |
| 924 | * @see cx_strdup() | |
| 925 | * @see cx_strfree_a() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926 | */ |
| 579 | 927 | #define cx_strdup_a(allocator, string) \ |
| 928 | cx_strdup_a_((allocator), cx_strcast(string)) | |
| 490 | 929 | |
| 930 | /** | |
| 931 | * Creates a duplicate of the specified string. | |
| 932 | * | |
| 582 | 933 | * The new string will contain a copy allocated by the cxDefaultAllocator. |
| 934 | * So developers @em must pass the return value to cx_strfree(). | |
| 490 | 935 | * |
| 579 | 936 | * @note The returned string is guaranteed to be zero-terminated. |
| 490 | 937 | * |
| 938 | * @param string the string to duplicate | |
| 579 | 939 | * @return (@c cxmutstr) a duplicate of the string |
| 940 | * @see cx_strdup_a() | |
| 941 | * @see cx_strfree() | |
| 490 | 942 | */ |
| 579 | 943 | #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
| 490 | 944 | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
946 | * Omits leading and trailing spaces. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
947 | * |
| 579 | 948 | * @note the returned string references the same memory, thus you |
| 949 | * must @em not free the returned memory. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
951 | * @param string the string that shall be trimmed |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
952 | * @return the trimmed string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
953 | */ |
| 579 | 954 | cx_attr_nodiscard |
| 955 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | cxstring cx_strtrim(cxstring string); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
958 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | * Omits leading and trailing spaces. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960 | * |
| 579 | 961 | * @note the returned string references the same memory, thus you |
| 962 | * must @em not free the returned memory. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
963 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | * @param string the string that shall be trimmed |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | * @return the trimmed string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
966 | */ |
| 579 | 967 | cx_attr_nodiscard |
| 968 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969 | cxmutstr cx_strtrim_m(cxmutstr string); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
971 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
972 | * Checks, if a string has a specific prefix. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
973 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
974 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
975 | * @param prefix the prefix the string should have |
| 579 | 976 | * @return @c true, if and only if the string has the specified prefix, |
| 977 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
978 | */ |
| 579 | 979 | cx_attr_nodiscard |
| 980 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
981 | bool cx_strprefix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
982 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
983 | cxstring prefix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
984 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
985 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
986 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
987 | * Checks, if a string has a specific suffix. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
988 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
989 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
990 | * @param suffix the suffix the string should have |
| 579 | 991 | * @return @c true, if and only if the string has the specified suffix, |
| 992 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
993 | */ |
| 579 | 994 | cx_attr_nodiscard |
| 995 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
996 | bool cx_strsuffix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
997 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
998 | cxstring suffix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
999 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1000 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1001 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1002 | * Checks, if a string has a specific prefix, ignoring the case. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1003 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1004 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1005 | * @param prefix the prefix the string should have |
| 579 | 1006 | * @return @c true, if and only if the string has the specified prefix, |
| 1007 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1008 | */ |
| 579 | 1009 | cx_attr_nodiscard |
| 1010 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1011 | bool cx_strcaseprefix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1012 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1013 | cxstring prefix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1014 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1015 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1016 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1017 | * Checks, if a string has a specific suffix, ignoring the case. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1018 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1019 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1020 | * @param suffix the suffix the string should have |
| 579 | 1021 | * @return @c true, if and only if the string has the specified suffix, |
| 1022 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1023 | */ |
| 579 | 1024 | cx_attr_nodiscard |
| 1025 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026 | bool cx_strcasesuffix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1027 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1028 | cxstring suffix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1030 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1031 | /** |
| 579 | 1032 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1033 | * |
| 579 | 1034 | * Replaces at most @p replmax occurrences. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | * |
| 579 | 1036 | * The returned string will be allocated by @p allocator and is guaranteed |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037 | * to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1038 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1039 | * If allocation fails, or the input string is empty, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1040 | * the returned string will be empty. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1041 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1042 | * @param allocator the allocator to use |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1043 | * @param str the string where replacements should be applied |
| 579 | 1044 | * @param search the string to search for |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1045 | * @param replacement the replacement string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1046 | * @param replmax maximum number of replacements |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1047 | * @return the resulting string after applying the replacements |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1048 | */ |
| 579 | 1049 | cx_attr_nodiscard |
| 1050 | cx_attr_nonnull | |
| 1051 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1052 | cxmutstr cx_strreplacen_a( |
| 579 | 1053 | const CxAllocator *allocator, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1054 | cxstring str, |
| 579 | 1055 | cxstring search, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1056 | cxstring replacement, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1057 | size_t replmax |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1058 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1059 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1060 | /** |
| 579 | 1061 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1062 | * |
| 579 | 1063 | * Replaces at most @p replmax occurrences. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1064 | * |
| 582 | 1065 | * The returned string will be allocated by the cxDefaultAllocator and is guaranteed |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1066 | * to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1067 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1068 | * If allocation fails, or the input string is empty, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1069 | * the returned string will be empty. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1070 | * |
| 579 | 1071 | * @param str (@c cxstring) the string where replacements should be applied |
| 1072 | * @param search (@c cxstring) the string to search for | |
| 1073 | * @param replacement (@c cxstring) the replacement string | |
| 1074 | * @param replmax (@c size_t) maximum number of replacements | |
| 1075 | * @return (@c cxmutstr) the resulting string after applying the replacements | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1076 | */ |
| 579 | 1077 | #define cx_strreplacen(str, search, replacement, replmax) \ |
| 1078 | cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax) | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1079 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1080 | /** |
| 579 | 1081 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1082 | * |
| 579 | 1083 | * The returned string will be allocated by @p allocator and is guaranteed |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1084 | * to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1085 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1086 | * If allocation fails, or the input string is empty, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1087 | * the returned string will be empty. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1088 | * |
| 579 | 1089 | * @param allocator (@c CxAllocator*) the allocator to use |
| 1090 | * @param str (@c cxstring) the string where replacements should be applied | |
| 1091 | * @param search (@c cxstring) the string to search for | |
| 1092 | * @param replacement (@c cxstring) the replacement string | |
| 1093 | * @return (@c cxmutstr) the resulting string after applying the replacements | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1094 | */ |
| 579 | 1095 | #define cx_strreplace_a(allocator, str, search, replacement) \ |
| 1096 | cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX) | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1097 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1098 | /** |
| 579 | 1099 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1100 | * |
| 582 | 1101 | * The returned string will be allocated by the cxDefaultAllocator and is guaranteed |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1102 | * to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1103 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1104 | * If allocation fails, or the input string is empty, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1105 | * the returned string will be empty. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1106 | * |
| 579 | 1107 | * @param str (@c cxstring) the string where replacements should be applied |
| 1108 | * @param search (@c cxstring) the string to search for | |
| 1109 | * @param replacement (@c cxstring) the replacement string | |
| 1110 | * @return (@c cxmutstr) the resulting string after applying the replacements | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1111 | */ |
| 579 | 1112 | #define cx_strreplace(str, search, replacement) \ |
| 1113 | cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX) | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1114 | |
| 490 | 1115 | /** |
| 1116 | * Creates a string tokenization context. | |
| 1117 | * | |
| 1118 | * @param str the string to tokenize | |
| 1119 | * @param delim the delimiter (must not be empty) | |
| 1120 | * @param limit the maximum number of tokens that shall be returned | |
| 1121 | * @return a new string tokenization context | |
| 1122 | */ | |
| 579 | 1123 | cx_attr_nodiscard |
| 1124 | cx_attr_export | |
| 1125 | CxStrtokCtx cx_strtok_( | |
| 490 | 1126 | cxstring str, |
| 1127 | cxstring delim, | |
| 1128 | size_t limit | |
| 1129 | ); | |
| 1130 | ||
| 1131 | /** | |
| 579 | 1132 | * Creates a string tokenization context. |
| 1133 | * | |
| 1134 | * @param str the string to tokenize | |
| 1135 | * @param delim the delimiter string (must not be empty) | |
| 1136 | * @param limit (@c size_t) the maximum number of tokens that shall be returned | |
| 1137 | * @return (@c CxStrtokCtx) a new string tokenization context | |
| 1138 | */ | |
| 1139 | #define cx_strtok(str, delim, limit) \ | |
| 1140 | cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit)) | |
| 490 | 1141 | |
| 1142 | /** | |
| 1143 | * Returns the next token. | |
| 1144 | * | |
| 1145 | * The token will point to the source string. | |
| 1146 | * | |
| 1147 | * @param ctx the tokenization context | |
| 1148 | * @param token a pointer to memory where the next token shall be stored | |
| 1149 | * @return true if successful, false if the limit or the end of the string | |
| 1150 | * has been reached | |
| 1151 | */ | |
| 579 | 1152 | cx_attr_nonnull |
| 1153 | cx_attr_nodiscard | |
| 1154 | cx_attr_access_w(2) | |
| 1155 | cx_attr_export | |
| 490 | 1156 | bool cx_strtok_next( |
| 1157 | CxStrtokCtx *ctx, | |
| 1158 | cxstring *token | |
| 1159 | ); | |
| 1160 | ||
| 1161 | /** | |
| 1162 | * Returns the next token of a mutable string. | |
| 1163 | * | |
| 1164 | * The token will point to the source string. | |
| 579 | 1165 | * |
| 1166 | * @attention | |
| 490 | 1167 | * If the context was not initialized over a mutable string, modifying |
| 1168 | * the data of the returned token is undefined behavior. | |
| 1169 | * | |
| 1170 | * @param ctx the tokenization context | |
| 1171 | * @param token a pointer to memory where the next token shall be stored | |
| 1172 | * @return true if successful, false if the limit or the end of the string | |
| 1173 | * has been reached | |
| 1174 | */ | |
| 579 | 1175 | cx_attr_nonnull |
| 1176 | cx_attr_nodiscard | |
| 1177 | cx_attr_access_w(2) | |
| 1178 | cx_attr_export | |
| 490 | 1179 | bool cx_strtok_next_m( |
| 1180 | CxStrtokCtx *ctx, | |
| 1181 | cxmutstr *token | |
| 1182 | ); | |
| 1183 | ||
| 1184 | /** | |
| 1185 | * Defines an array of more delimiters for the specified tokenization context. | |
| 1186 | * | |
| 1187 | * @param ctx the tokenization context | |
| 1188 | * @param delim array of more delimiters | |
| 1189 | * @param count number of elements in the array | |
| 1190 | */ | |
| 579 | 1191 | cx_attr_nonnull |
| 1192 | cx_attr_access_r(2, 3) | |
| 1193 | cx_attr_export | |
| 490 | 1194 | void cx_strtok_delim( |
| 1195 | CxStrtokCtx *ctx, | |
| 579 | 1196 | const cxstring *delim, |
| 490 | 1197 | size_t count |
| 1198 | ); | |
| 1199 | ||
| 579 | 1200 | /* ------------------------------------------------------------------------- * |
| 1201 | * string to number conversion functions * | |
| 1202 | * ------------------------------------------------------------------------- */ | |
| 1203 | ||
| 1204 | /** | |
| 1205 | * Converts a string to a number. | |
| 1206 | * | |
| 1207 | * The function returns non-zero when conversion is not possible. | |
| 1208 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1209 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1210 | * | |
| 1211 | * @param str the string to convert | |
| 1212 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1213 | * @param base 2, 8, 10, or 16 | |
| 1214 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1215 | * @retval zero success | |
| 1216 | * @retval non-zero conversion was not possible | |
| 1217 | */ | |
| 1218 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1219 | int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep); | |
| 1220 | ||
| 1221 | /** | |
| 1222 | * Converts a string to a number. | |
| 1223 | * | |
| 1224 | * The function returns non-zero when conversion is not possible. | |
| 1225 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1226 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1227 | * | |
| 1228 | * @param str the string to convert | |
| 1229 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1230 | * @param base 2, 8, 10, or 16 | |
| 1231 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1232 | * @retval zero success | |
| 1233 | * @retval non-zero conversion was not possible | |
| 1234 | */ | |
| 1235 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1236 | int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep); | |
| 1237 | ||
| 1238 | /** | |
| 1239 | * Converts a string to a number. | |
| 1240 | * | |
| 1241 | * The function returns non-zero when conversion is not possible. | |
| 1242 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1243 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1244 | * | |
| 1245 | * @param str the string to convert | |
| 1246 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1247 | * @param base 2, 8, 10, or 16 | |
| 1248 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1249 | * @retval zero success | |
| 1250 | * @retval non-zero conversion was not possible | |
| 1251 | */ | |
| 1252 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1253 | int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep); | |
| 1254 | ||
| 1255 | /** | |
| 1256 | * Converts a string to a number. | |
| 1257 | * | |
| 1258 | * The function returns non-zero when conversion is not possible. | |
| 1259 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1260 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1261 | * | |
| 1262 | * @param str the string to convert | |
| 1263 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1264 | * @param base 2, 8, 10, or 16 | |
| 1265 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1266 | * @retval zero success | |
| 1267 | * @retval non-zero conversion was not possible | |
| 1268 | */ | |
| 1269 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1270 | int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep); | |
| 1271 | ||
| 1272 | /** | |
| 1273 | * Converts a string to a number. | |
| 1274 | * | |
| 1275 | * The function returns non-zero when conversion is not possible. | |
| 1276 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1277 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1278 | * | |
| 1279 | * @param str the string to convert | |
| 1280 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1281 | * @param base 2, 8, 10, or 16 | |
| 1282 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1283 | * @retval zero success | |
| 1284 | * @retval non-zero conversion was not possible | |
| 1285 | */ | |
| 1286 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1287 | int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep); | |
| 1288 | ||
| 1289 | /** | |
| 1290 | * Converts a string to a number. | |
| 1291 | * | |
| 1292 | * The function returns non-zero when conversion is not possible. | |
| 1293 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1294 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1295 | * | |
| 1296 | * @param str the string to convert | |
| 1297 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1298 | * @param base 2, 8, 10, or 16 | |
| 1299 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1300 | * @retval zero success | |
| 1301 | * @retval non-zero conversion was not possible | |
| 1302 | */ | |
| 1303 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1304 | int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep); | |
| 1305 | ||
| 1306 | /** | |
| 1307 | * Converts a string to a number. | |
| 1308 | * | |
| 1309 | * The function returns non-zero when conversion is not possible. | |
| 1310 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1311 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1312 | * | |
| 1313 | * @param str the string to convert | |
| 1314 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1315 | * @param base 2, 8, 10, or 16 | |
| 1316 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1317 | * @retval zero success | |
| 1318 | * @retval non-zero conversion was not possible | |
| 1319 | */ | |
| 1320 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1321 | int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep); | |
| 1322 | ||
| 1323 | /** | |
| 1324 | * Converts a string to a number. | |
| 1325 | * | |
| 1326 | * The function returns non-zero when conversion is not possible. | |
| 1327 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1328 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1329 | * | |
| 1330 | * @param str the string to convert | |
| 1331 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1332 | * @param base 2, 8, 10, or 16 | |
| 1333 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1334 | * @retval zero success | |
| 1335 | * @retval non-zero conversion was not possible | |
| 1336 | */ | |
| 1337 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1338 | int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep); | |
| 1339 | ||
| 1340 | /** | |
| 1341 | * Converts a string to a number. | |
| 1342 | * | |
| 1343 | * The function returns non-zero when conversion is not possible. | |
| 1344 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1345 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1346 | * | |
| 1347 | * @param str the string to convert | |
| 1348 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1349 | * @param base 2, 8, 10, or 16 | |
| 1350 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1351 | * @retval zero success | |
| 1352 | * @retval non-zero conversion was not possible | |
| 1353 | */ | |
| 1354 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1355 | int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep); | |
| 1356 | ||
| 1357 | /** | |
| 1358 | * Converts a string to a number. | |
| 1359 | * | |
| 1360 | * The function returns non-zero when conversion is not possible. | |
| 1361 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1362 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1363 | * | |
| 1364 | * @param str the string to convert | |
| 1365 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1366 | * @param base 2, 8, 10, or 16 | |
| 1367 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1368 | * @retval zero success | |
| 1369 | * @retval non-zero conversion was not possible | |
| 1370 | */ | |
| 1371 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1372 | int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep); | |
| 1373 | ||
| 1374 | /** | |
| 1375 | * Converts a string to a number. | |
| 1376 | * | |
| 1377 | * The function returns non-zero when conversion is not possible. | |
| 1378 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1379 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1380 | * | |
| 1381 | * @param str the string to convert | |
| 1382 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1383 | * @param base 2, 8, 10, or 16 | |
| 1384 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1385 | * @retval zero success | |
| 1386 | * @retval non-zero conversion was not possible | |
| 1387 | */ | |
| 1388 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1389 | int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep); | |
| 1390 | ||
| 1391 | /** | |
| 1392 | * Converts a string to a number. | |
| 1393 | * | |
| 1394 | * The function returns non-zero when conversion is not possible. | |
| 1395 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1396 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1397 | * | |
| 1398 | * @param str the string to convert | |
| 1399 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1400 | * @param base 2, 8, 10, or 16 | |
| 1401 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1402 | * @retval zero success | |
| 1403 | * @retval non-zero conversion was not possible | |
| 1404 | */ | |
| 1405 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1406 | int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep); | |
| 1407 | ||
| 1408 | /** | |
| 1409 | * Converts a string to a number. | |
| 1410 | * | |
| 1411 | * The function returns non-zero when conversion is not possible. | |
| 1412 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1413 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1414 | * | |
| 1415 | * @param str the string to convert | |
| 1416 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1417 | * @param base 2, 8, 10, or 16 | |
| 1418 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1419 | * @retval zero success | |
| 1420 | * @retval non-zero conversion was not possible | |
| 1421 | */ | |
| 1422 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1423 | int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep); | |
| 1424 | ||
| 1425 | /** | |
| 1426 | * Converts a string to a number. | |
| 1427 | * | |
| 1428 | * The function returns non-zero when conversion is not possible. | |
| 1429 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1430 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1431 | * | |
| 1432 | * @param str the string to convert | |
| 1433 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1434 | * @param base 2, 8, 10, or 16 | |
| 1435 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1436 | * @retval zero success | |
| 1437 | * @retval non-zero conversion was not possible | |
| 1438 | */ | |
| 1439 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1440 | int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep); | |
| 1441 | ||
| 1442 | /** | |
| 1443 | * Converts a string to a number. | |
| 1444 | * | |
| 1445 | * The function returns non-zero when conversion is not possible. | |
| 1446 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1447 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1448 | * | |
| 1449 | * @param str the string to convert | |
| 1450 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1451 | * @param base 2, 8, 10, or 16 | |
| 1452 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1453 | * @retval zero success | |
| 1454 | * @retval non-zero conversion was not possible | |
| 1455 | */ | |
| 1456 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1457 | int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep); | |
| 1458 | ||
| 1459 | /** | |
| 1460 | * Converts a string to a number. | |
| 1461 | * | |
| 1462 | * The function returns non-zero when conversion is not possible. | |
| 1463 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1464 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1465 | * | |
| 1466 | * @param str the string to convert | |
| 1467 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1468 | * @param base 2, 8, 10, or 16 | |
| 1469 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1470 | * @retval zero success | |
| 1471 | * @retval non-zero conversion was not possible | |
| 1472 | */ | |
| 1473 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1474 | int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep); | |
| 1475 | ||
| 1476 | /** | |
| 1477 | * Converts a string to a number. | |
| 1478 | * | |
| 1479 | * The function returns non-zero when conversion is not possible. | |
| 1480 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1481 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1482 | * | |
| 1483 | * @param str the string to convert | |
| 1484 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1485 | * @param base 2, 8, 10, or 16 | |
| 1486 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1487 | * @retval zero success | |
| 1488 | * @retval non-zero conversion was not possible | |
| 1489 | */ | |
| 1490 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1491 | int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep); | |
| 1492 | ||
| 1493 | /** | |
| 1494 | * Converts a string to a single precision floating point number. | |
| 1495 | * | |
| 1496 | * The function returns non-zero when conversion is not possible. | |
| 1497 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 1498 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 1499 | * | |
| 1500 | * @param str the string to convert | |
| 1501 | * @param output a pointer to the float variable where the result shall be stored | |
| 1502 | * @param decsep the decimal separator | |
| 1503 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1504 | * @retval zero success | |
| 1505 | * @retval non-zero conversion was not possible | |
| 1506 | */ | |
| 1507 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1508 | int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep); | |
| 1509 | ||
| 1510 | /** | |
| 1511 | * Converts a string to a double precision floating point number. | |
| 1512 | * | |
| 1513 | * The function returns non-zero when conversion is not possible. | |
| 1514 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 1515 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 1516 | * | |
| 1517 | * @param str the string to convert | |
| 1518 | * @param output a pointer to the float variable where the result shall be stored | |
| 1519 | * @param decsep the decimal separator | |
| 1520 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1521 | * @retval zero success | |
| 1522 | * @retval non-zero conversion was not possible | |
| 1523 | */ | |
| 1524 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1525 | int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep); | |
| 1526 | ||
| 1527 | /** | |
| 1528 | * Converts a string to a number. | |
| 1529 | * | |
| 1530 | * The function returns non-zero when conversion is not possible. | |
| 1531 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1532 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1533 | * | |
| 1534 | * @param str the string to convert | |
| 1535 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1536 | * @param base 2, 8, 10, or 16 | |
| 1537 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1538 | * @retval zero success | |
| 1539 | * @retval non-zero conversion was not possible | |
| 1540 | */ | |
| 1541 | #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep) | |
| 1542 | ||
| 1543 | /** | |
| 1544 | * Converts a string to a number. | |
| 1545 | * | |
| 1546 | * The function returns non-zero when conversion is not possible. | |
| 1547 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1548 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1549 | * | |
| 1550 | * @param str the string to convert | |
| 1551 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1552 | * @param base 2, 8, 10, or 16 | |
| 1553 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1554 | * @retval zero success | |
| 1555 | * @retval non-zero conversion was not possible | |
| 1556 | */ | |
| 1557 | #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep) | |
| 1558 | ||
| 1559 | /** | |
| 1560 | * Converts a string to a number. | |
| 1561 | * | |
| 1562 | * The function returns non-zero when conversion is not possible. | |
| 1563 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1564 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1565 | * | |
| 1566 | * @param str the string to convert | |
| 1567 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1568 | * @param base 2, 8, 10, or 16 | |
| 1569 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1570 | * @retval zero success | |
| 1571 | * @retval non-zero conversion was not possible | |
| 1572 | */ | |
| 1573 | #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep) | |
| 1574 | ||
| 1575 | /** | |
| 1576 | * Converts a string to a number. | |
| 1577 | * | |
| 1578 | * The function returns non-zero when conversion is not possible. | |
| 1579 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1580 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1581 | * | |
| 1582 | * @param str the string to convert | |
| 1583 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1584 | * @param base 2, 8, 10, or 16 | |
| 1585 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1586 | * @retval zero success | |
| 1587 | * @retval non-zero conversion was not possible | |
| 1588 | */ | |
| 1589 | #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep) | |
| 1590 | ||
| 1591 | /** | |
| 1592 | * Converts a string to a number. | |
| 1593 | * | |
| 1594 | * The function returns non-zero when conversion is not possible. | |
| 1595 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1596 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1597 | * | |
| 1598 | * @param str the string to convert | |
| 1599 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1600 | * @param base 2, 8, 10, or 16 | |
| 1601 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1602 | * @retval zero success | |
| 1603 | * @retval non-zero conversion was not possible | |
| 1604 | */ | |
| 1605 | #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep) | |
| 1606 | ||
| 1607 | /** | |
| 1608 | * Converts a string to a number. | |
| 1609 | * | |
| 1610 | * The function returns non-zero when conversion is not possible. | |
| 1611 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1612 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1613 | * | |
| 1614 | * @param str the string to convert | |
| 1615 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1616 | * @param base 2, 8, 10, or 16 | |
| 1617 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1618 | * @retval zero success | |
| 1619 | * @retval non-zero conversion was not possible | |
| 1620 | */ | |
| 1621 | #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep) | |
| 1622 | ||
| 1623 | /** | |
| 1624 | * Converts a string to a number. | |
| 1625 | * | |
| 1626 | * The function returns non-zero when conversion is not possible. | |
| 1627 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1628 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1629 | * | |
| 1630 | * @param str the string to convert | |
| 1631 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1632 | * @param base 2, 8, 10, or 16 | |
| 1633 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1634 | * @retval zero success | |
| 1635 | * @retval non-zero conversion was not possible | |
| 1636 | */ | |
| 1637 | #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep) | |
| 1638 | ||
| 1639 | /** | |
| 1640 | * Converts a string to a number. | |
| 1641 | * | |
| 1642 | * The function returns non-zero when conversion is not possible. | |
| 1643 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1644 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1645 | * | |
| 1646 | * @param str the string to convert | |
| 1647 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1648 | * @param base 2, 8, 10, or 16 | |
| 1649 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1650 | * @retval zero success | |
| 1651 | * @retval non-zero conversion was not possible | |
| 1652 | */ | |
| 1653 | #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep) | |
| 1654 | ||
| 1655 | /** | |
| 1656 | * Converts a string to a number. | |
| 1657 | * | |
| 1658 | * The function returns non-zero when conversion is not possible. | |
| 1659 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1660 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1661 | * | |
| 1662 | * @param str the string to convert | |
| 1663 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1664 | * @param base 2, 8, 10, or 16 | |
| 1665 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1666 | * @retval zero success | |
| 1667 | * @retval non-zero conversion was not possible | |
| 1668 | */ | |
| 1669 | #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep) | |
| 1670 | ||
| 1671 | /** | |
| 1672 | * Converts a string to a number. | |
| 1673 | * | |
| 1674 | * The function returns non-zero when conversion is not possible. | |
| 1675 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1676 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1677 | * | |
| 1678 | * @param str the string to convert | |
| 1679 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1680 | * @param base 2, 8, 10, or 16 | |
| 1681 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1682 | * @retval zero success | |
| 1683 | * @retval non-zero conversion was not possible | |
| 1684 | */ | |
| 1685 | #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep) | |
| 1686 | ||
| 1687 | /** | |
| 1688 | * Converts a string to a number. | |
| 1689 | * | |
| 1690 | * The function returns non-zero when conversion is not possible. | |
| 1691 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1692 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1693 | * | |
| 1694 | * @param str the string to convert | |
| 1695 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1696 | * @param base 2, 8, 10, or 16 | |
| 1697 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1698 | * @retval zero success | |
| 1699 | * @retval non-zero conversion was not possible | |
| 1700 | */ | |
| 1701 | #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep) | |
| 1702 | ||
| 1703 | /** | |
| 1704 | * Converts a string to a number. | |
| 1705 | * | |
| 1706 | * The function returns non-zero when conversion is not possible. | |
| 1707 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1708 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1709 | * | |
| 1710 | * @param str the string to convert | |
| 1711 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1712 | * @param base 2, 8, 10, or 16 | |
| 1713 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1714 | * @retval zero success | |
| 1715 | * @retval non-zero conversion was not possible | |
| 1716 | */ | |
| 1717 | #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep) | |
| 1718 | ||
| 1719 | /** | |
| 1720 | * Converts a string to a number. | |
| 1721 | * | |
| 1722 | * The function returns non-zero when conversion is not possible. | |
| 1723 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1724 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1725 | * | |
| 1726 | * @param str the string to convert | |
| 1727 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1728 | * @param base 2, 8, 10, or 16 | |
| 1729 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1730 | * @retval zero success | |
| 1731 | * @retval non-zero conversion was not possible | |
| 1732 | */ | |
| 1733 | #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep) | |
| 1734 | ||
| 1735 | /** | |
| 1736 | * Converts a string to a number. | |
| 1737 | * | |
| 1738 | * The function returns non-zero when conversion is not possible. | |
| 1739 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1740 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1741 | * | |
| 1742 | * @param str the string to convert | |
| 1743 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1744 | * @param base 2, 8, 10, or 16 | |
| 1745 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1746 | * @retval zero success | |
| 1747 | * @retval non-zero conversion was not possible | |
| 1748 | */ | |
| 1749 | #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep) | |
| 1750 | ||
| 1751 | /** | |
| 1752 | * Converts a string to a number. | |
| 1753 | * | |
| 1754 | * The function returns non-zero when conversion is not possible. | |
| 1755 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1756 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1757 | * | |
| 1758 | * @param str the string to convert | |
| 1759 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1760 | * @param base 2, 8, 10, or 16 | |
| 1761 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1762 | * @retval zero success | |
| 1763 | * @retval non-zero conversion was not possible | |
| 1764 | */ | |
| 1765 | #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep) | |
| 1766 | ||
| 1767 | /** | |
| 1768 | * Converts a string to a number. | |
| 1769 | * | |
| 1770 | * The function returns non-zero when conversion is not possible. | |
| 1771 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1772 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1773 | * | |
| 1774 | * @param str the string to convert | |
| 1775 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1776 | * @param base 2, 8, 10, or 16 | |
| 1777 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1778 | * @retval zero success | |
| 1779 | * @retval non-zero conversion was not possible | |
| 1780 | */ | |
| 1781 | #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep) | |
| 1782 | ||
| 1783 | /** | |
| 1784 | * Converts a string to a number. | |
| 1785 | * | |
| 1786 | * The function returns non-zero when conversion is not possible. | |
| 1787 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1788 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1789 | * | |
| 1790 | * @param str the string to convert | |
| 1791 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1792 | * @param base 2, 8, 10, or 16 | |
| 1793 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1794 | * @retval zero success | |
| 1795 | * @retval non-zero conversion was not possible | |
| 1796 | */ | |
| 1797 | #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep) | |
| 1798 | ||
| 1799 | /** | |
| 1800 | * Converts a string to a number. | |
| 1801 | * | |
| 1802 | * The function returns non-zero when conversion is not possible. | |
| 1803 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1804 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1805 | * | |
| 1806 | * The comma character is treated as group separator and ignored during parsing. | |
| 1807 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1808 | * | |
| 1809 | * @param str the string to convert | |
| 1810 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1811 | * @param base 2, 8, 10, or 16 | |
| 1812 | * @retval zero success | |
| 1813 | * @retval non-zero conversion was not possible | |
| 1814 | */ | |
| 1815 | #define cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",") | |
| 1816 | ||
| 1817 | /** | |
| 1818 | * Converts a string to a number. | |
| 1819 | * | |
| 1820 | * The function returns non-zero when conversion is not possible. | |
| 1821 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1822 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1823 | * | |
| 1824 | * The comma character is treated as group separator and ignored during parsing. | |
| 1825 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1826 | * | |
| 1827 | * @param str the string to convert | |
| 1828 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1829 | * @param base 2, 8, 10, or 16 | |
| 1830 | * @retval zero success | |
| 1831 | * @retval non-zero conversion was not possible | |
| 1832 | */ | |
| 1833 | #define cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",") | |
| 1834 | ||
| 1835 | /** | |
| 1836 | * Converts a string to a number. | |
| 1837 | * | |
| 1838 | * The function returns non-zero when conversion is not possible. | |
| 1839 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1840 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1841 | * | |
| 1842 | * The comma character is treated as group separator and ignored during parsing. | |
| 1843 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1844 | * | |
| 1845 | * @param str the string to convert | |
| 1846 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1847 | * @param base 2, 8, 10, or 16 | |
| 1848 | * @retval zero success | |
| 1849 | * @retval non-zero conversion was not possible | |
| 1850 | */ | |
| 1851 | #define cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",") | |
| 1852 | ||
| 1853 | /** | |
| 1854 | * Converts a string to a number. | |
| 1855 | * | |
| 1856 | * The function returns non-zero when conversion is not possible. | |
| 1857 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1858 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1859 | * | |
| 1860 | * The comma character is treated as group separator and ignored during parsing. | |
| 1861 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1862 | * | |
| 1863 | * @param str the string to convert | |
| 1864 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1865 | * @param base 2, 8, 10, or 16 | |
| 1866 | * @retval zero success | |
| 1867 | * @retval non-zero conversion was not possible | |
| 1868 | */ | |
| 1869 | #define cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",") | |
| 1870 | ||
| 1871 | /** | |
| 1872 | * Converts a string to a number. | |
| 1873 | * | |
| 1874 | * The function returns non-zero when conversion is not possible. | |
| 1875 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1876 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1877 | * | |
| 1878 | * The comma character is treated as group separator and ignored during parsing. | |
| 1879 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1880 | * | |
| 1881 | * @param str the string to convert | |
| 1882 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1883 | * @param base 2, 8, 10, or 16 | |
| 1884 | * @retval zero success | |
| 1885 | * @retval non-zero conversion was not possible | |
| 1886 | */ | |
| 1887 | #define cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",") | |
| 1888 | ||
| 1889 | /** | |
| 1890 | * Converts a string to a number. | |
| 1891 | * | |
| 1892 | * The function returns non-zero when conversion is not possible. | |
| 1893 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1894 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1895 | * | |
| 1896 | * The comma character is treated as group separator and ignored during parsing. | |
| 1897 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1898 | * | |
| 1899 | * @param str the string to convert | |
| 1900 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1901 | * @param base 2, 8, 10, or 16 | |
| 1902 | * @retval zero success | |
| 1903 | * @retval non-zero conversion was not possible | |
| 1904 | */ | |
| 1905 | #define cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",") | |
| 1906 | ||
| 1907 | /** | |
| 1908 | * Converts a string to a number. | |
| 1909 | * | |
| 1910 | * The function returns non-zero when conversion is not possible. | |
| 1911 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1912 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1913 | * | |
| 1914 | * The comma character is treated as group separator and ignored during parsing. | |
| 1915 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1916 | * | |
| 1917 | * @param str the string to convert | |
| 1918 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1919 | * @param base 2, 8, 10, or 16 | |
| 1920 | * @retval zero success | |
| 1921 | * @retval non-zero conversion was not possible | |
| 1922 | */ | |
| 1923 | #define cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",") | |
| 1924 | ||
| 1925 | /** | |
| 1926 | * Converts a string to a number. | |
| 1927 | * | |
| 1928 | * The function returns non-zero when conversion is not possible. | |
| 1929 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1930 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1931 | * | |
| 1932 | * The comma character is treated as group separator and ignored during parsing. | |
| 1933 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1934 | * | |
| 1935 | * @param str the string to convert | |
| 1936 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1937 | * @param base 2, 8, 10, or 16 | |
| 1938 | * @retval zero success | |
| 1939 | * @retval non-zero conversion was not possible | |
| 1940 | */ | |
| 1941 | #define cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",") | |
| 1942 | ||
| 1943 | /** | |
| 1944 | * Converts a string to a number. | |
| 1945 | * | |
| 1946 | * The function returns non-zero when conversion is not possible. | |
| 1947 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1948 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1949 | * | |
| 1950 | * The comma character is treated as group separator and ignored during parsing. | |
| 1951 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1952 | * | |
| 1953 | * @param str the string to convert | |
| 1954 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1955 | * @param base 2, 8, 10, or 16 | |
| 1956 | * @retval zero success | |
| 1957 | * @retval non-zero conversion was not possible | |
| 1958 | */ | |
| 1959 | #define cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",") | |
| 1960 | ||
| 1961 | /** | |
| 1962 | * Converts a string to a number. | |
| 1963 | * | |
| 1964 | * The function returns non-zero when conversion is not possible. | |
| 1965 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1966 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1967 | * | |
| 1968 | * The comma character is treated as group separator and ignored during parsing. | |
| 1969 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1970 | * | |
| 1971 | * @param str the string to convert | |
| 1972 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1973 | * @param base 2, 8, 10, or 16 | |
| 1974 | * @retval zero success | |
| 1975 | * @retval non-zero conversion was not possible | |
| 1976 | */ | |
| 1977 | #define cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",") | |
| 1978 | ||
| 1979 | /** | |
| 1980 | * Converts a string to a number. | |
| 1981 | * | |
| 1982 | * The function returns non-zero when conversion is not possible. | |
| 1983 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1984 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1985 | * | |
| 1986 | * The comma character is treated as group separator and ignored during parsing. | |
| 1987 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 1988 | * | |
| 1989 | * @param str the string to convert | |
| 1990 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1991 | * @param base 2, 8, 10, or 16 | |
| 1992 | * @retval zero success | |
| 1993 | * @retval non-zero conversion was not possible | |
| 1994 | */ | |
| 1995 | #define cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",") | |
| 1996 | ||
| 1997 | /** | |
| 1998 | * Converts a string to a number. | |
| 1999 | * | |
| 2000 | * The function returns non-zero when conversion is not possible. | |
| 2001 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 2002 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2003 | * | |
| 2004 | * The comma character is treated as group separator and ignored during parsing. | |
| 2005 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2006 | * | |
| 2007 | * @param str the string to convert | |
| 2008 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2009 | * @param base 2, 8, 10, or 16 | |
| 2010 | * @retval zero success | |
| 2011 | * @retval non-zero conversion was not possible | |
| 2012 | */ | |
| 2013 | #define cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",") | |
| 2014 | ||
| 2015 | /** | |
| 2016 | * Converts a string to a number. | |
| 2017 | * | |
| 2018 | * The function returns non-zero when conversion is not possible. | |
| 2019 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 2020 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2021 | * | |
| 2022 | * The comma character is treated as group separator and ignored during parsing. | |
| 2023 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2024 | * | |
| 2025 | * @param str the string to convert | |
| 2026 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2027 | * @param base 2, 8, 10, or 16 | |
| 2028 | * @retval zero success | |
| 2029 | * @retval non-zero conversion was not possible | |
| 2030 | */ | |
| 2031 | #define cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",") | |
| 2032 | ||
| 2033 | /** | |
| 2034 | * Converts a string to a number. | |
| 2035 | * | |
| 2036 | * The function returns non-zero when conversion is not possible. | |
| 2037 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 2038 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2039 | * | |
| 2040 | * The comma character is treated as group separator and ignored during parsing. | |
| 2041 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2042 | * | |
| 2043 | * @param str the string to convert | |
| 2044 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2045 | * @param base 2, 8, 10, or 16 | |
| 2046 | * @retval zero success | |
| 2047 | * @retval non-zero conversion was not possible | |
| 2048 | */ | |
| 2049 | #define cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",") | |
| 2050 | ||
| 2051 | /** | |
| 2052 | * Converts a string to a number. | |
| 2053 | * | |
| 2054 | * The function returns non-zero when conversion is not possible. | |
| 2055 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 2056 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2057 | * | |
| 2058 | * The comma character is treated as group separator and ignored during parsing. | |
| 2059 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2060 | * | |
| 2061 | * @param str the string to convert | |
| 2062 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2063 | * @param base 2, 8, 10, or 16 | |
| 2064 | * @retval zero success | |
| 2065 | * @retval non-zero conversion was not possible | |
| 2066 | */ | |
| 2067 | #define cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",") | |
| 2068 | ||
| 2069 | /** | |
| 2070 | * Converts a string to a number. | |
| 2071 | * | |
| 2072 | * The function returns non-zero when conversion is not possible. | |
| 2073 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 2074 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2075 | * | |
| 2076 | * The comma character is treated as group separator and ignored during parsing. | |
| 2077 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2078 | * | |
| 2079 | * @param str the string to convert | |
| 2080 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2081 | * @param base 2, 8, 10, or 16 | |
| 2082 | * @retval zero success | |
| 2083 | * @retval non-zero conversion was not possible | |
| 2084 | */ | |
| 2085 | #define cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",") | |
| 2086 | ||
| 2087 | /** | |
| 2088 | * Converts a string to a number. | |
| 2089 | * | |
| 2090 | * The function returns non-zero when conversion is not possible. | |
| 2091 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 2092 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2093 | * | |
| 2094 | * The comma character is treated as group separator and ignored during parsing. | |
| 2095 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2096 | * | |
| 2097 | * @param str the string to convert | |
| 2098 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2099 | * @param base 2, 8, 10, or 16 | |
| 2100 | * @retval zero success | |
| 2101 | * @retval non-zero conversion was not possible | |
| 2102 | */ | |
| 2103 | #define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",") | |
| 2104 | ||
| 2105 | /** | |
| 2106 | * Converts a string to a single precision floating point number. | |
| 2107 | * | |
| 2108 | * The function returns non-zero when conversion is not possible. | |
| 2109 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2110 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 2111 | * | |
| 2112 | * @param str the string to convert | |
| 2113 | * @param output a pointer to the float variable where the result shall be stored | |
| 2114 | * @param decsep the decimal separator | |
| 2115 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 2116 | * @retval zero success | |
| 2117 | * @retval non-zero conversion was not possible | |
| 2118 | */ | |
| 2119 | #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep) | |
| 2120 | ||
| 2121 | /** | |
| 2122 | * Converts a string to a double precision floating point number. | |
| 2123 | * | |
| 2124 | * The function returns non-zero when conversion is not possible. | |
| 2125 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2126 | * | |
| 2127 | * @param str the string to convert | |
| 2128 | * @param output a pointer to the double variable where the result shall be stored | |
| 2129 | * @param decsep the decimal separator | |
| 2130 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 2131 | * @retval zero success | |
| 2132 | * @retval non-zero conversion was not possible | |
| 2133 | */ | |
| 2134 | #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep) | |
| 2135 | ||
| 2136 | /** | |
| 2137 | * Converts a string to a single precision floating point number. | |
| 2138 | * | |
| 2139 | * The function returns non-zero when conversion is not possible. | |
| 2140 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2141 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 2142 | * | |
| 2143 | * The decimal separator is assumed to be a dot character. | |
| 2144 | * The comma character is treated as group separator and ignored during parsing. | |
| 2145 | * If you want to choose a different format, use cx_strtof_lc(). | |
| 2146 | * | |
| 2147 | * @param str the string to convert | |
| 2148 | * @param output a pointer to the float variable where the result shall be stored | |
| 2149 | * @retval zero success | |
| 2150 | * @retval non-zero conversion was not possible | |
| 2151 | */ | |
| 2152 | #define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",") | |
| 2153 | ||
| 2154 | /** | |
| 2155 | * Converts a string to a double precision floating point number. | |
| 2156 | * | |
| 2157 | * The function returns non-zero when conversion is not possible. | |
| 2158 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2159 | * | |
| 2160 | * The decimal separator is assumed to be a dot character. | |
| 2161 | * The comma character is treated as group separator and ignored during parsing. | |
| 2162 | * If you want to choose a different format, use cx_strtof_lc(). | |
| 2163 | * | |
| 2164 | * @param str the string to convert | |
| 2165 | * @param output a pointer to the double variable where the result shall be stored | |
| 2166 | * @retval zero success | |
| 2167 | * @retval non-zero conversion was not possible | |
| 2168 | */ | |
| 2169 | #define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",") | |
| 490 | 2170 | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2171 | #ifdef __cplusplus |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2172 | } // extern "C" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2173 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2174 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2175 | #endif //UCX_STRING_H |