Thu, 30 Oct 2025 16:59:31 +0100
fix cgi pipe fd initialization
|
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 | * |
| 613 | 170 | * When @c NULL is passed, the length will be set to zero. |
| 171 | * | |
| 579 | 172 | * @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
|
173 | * 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
|
174 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | * 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
|
176 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | * @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
|
178 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | * @see cx_mutstrn() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | */ |
| 579 | 182 | cx_attr_nodiscard |
| 183 | cx_attr_cstr_arg(1) | |
| 184 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | cxmutstr cx_mutstr(char *cstring); |
|
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 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | * 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
|
189 | * |
| 579 | 190 | * 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
|
191 | * |
| 579 | 192 | * @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
|
193 | * 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
|
194 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | * 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
|
196 | * |
| 579 | 197 | * @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
|
198 | * @param length the length of the string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | * @see cx_mutstr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | */ |
| 579 | 203 | cx_attr_nodiscard |
| 204 | cx_attr_access_rw(1, 2) | |
| 205 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | cxmutstr cx_mutstrn( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | char *cstring, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | size_t length |
|
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 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | * Wraps a string that must be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | * |
| 579 | 214 | * 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
|
215 | * |
| 613 | 216 | * When @c NULL is passed, the length will be set to zero. |
| 217 | * | |
| 579 | 218 | * @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
|
219 | * 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
|
220 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | * 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
|
222 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | * @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
|
224 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | * @see cx_strn() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | */ |
| 579 | 228 | cx_attr_nodiscard |
| 229 | cx_attr_cstr_arg(1) | |
| 230 | cx_attr_export | |
| 231 | cxstring cx_str(const char *cstring); | |
|
415
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 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | * 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
|
236 | * |
| 579 | 237 | * 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
|
238 | * |
| 579 | 239 | * @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
|
240 | * 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
|
241 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | * 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
|
243 | * |
| 579 | 244 | * @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
|
245 | * @param length the length of the string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | * @return the wrapped string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | * @see cx_str() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | */ |
| 579 | 250 | cx_attr_nodiscard |
| 251 | cx_attr_access_r(1, 2) | |
| 252 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | cxstring cx_strn( |
| 579 | 254 | const char *cstring, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | |
| 579 | 258 | #ifdef __cplusplus |
| 259 | } // extern "C" | |
| 260 | cx_attr_nodiscard | |
| 261 | static inline cxstring cx_strcast(cxmutstr str) { | |
| 262 | return cx_strn(str.ptr, str.length); | |
| 263 | } | |
| 264 | cx_attr_nodiscard | |
| 265 | static inline cxstring cx_strcast(cxstring str) { | |
| 266 | return str; | |
| 267 | } | |
| 613 | 268 | cx_attr_nodiscard |
| 269 | static inline cxstring cx_strcast(const char *str) { | |
| 270 | return cx_str(str); | |
| 271 | } | |
| 579 | 272 | extern "C" { |
| 273 | #else | |
| 274 | /** | |
| 275 | * Internal function, do not use. | |
| 276 | * @param str | |
| 277 | * @return | |
| 278 | * @see cx_strcast() | |
| 279 | */ | |
| 280 | cx_attr_nodiscard | |
| 281 | static inline cxstring cx_strcast_m(cxmutstr str) { | |
| 282 | return (cxstring) {str.ptr, str.length}; | |
| 283 | } | |
| 284 | /** | |
| 285 | * Internal function, do not use. | |
| 286 | * @param str | |
| 287 | * @return | |
| 288 | * @see cx_strcast() | |
| 289 | */ | |
| 290 | cx_attr_nodiscard | |
| 291 | static inline cxstring cx_strcast_c(cxstring str) { | |
| 292 | return str; | |
| 293 | } | |
| 294 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | /** |
| 613 | 296 | * Internal function, do not use. |
| 297 | * @param str | |
| 298 | * @return | |
| 299 | * @see cx_strcast() | |
| 300 | */ | |
| 301 | cx_attr_nodiscard | |
| 302 | static inline cxstring cx_strcast_z(const char *str) { | |
| 303 | return cx_str(str); | |
| 304 | } | |
| 305 | ||
| 306 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | * Casts a mutable string to an immutable string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | * |
| 579 | 309 | * Does nothing for already immutable strings. |
| 310 | * | |
| 311 | * @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
|
312 | * 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
|
313 | * point to the same location, though! |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | * |
| 579 | 315 | * @param str (@c cxstring or @c cxmutstr) the string to cast |
| 316 | * @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
|
317 | */ |
| 579 | 318 | #define cx_strcast(str) _Generic((str), \ |
| 319 | cxmutstr: cx_strcast_m, \ | |
| 613 | 320 | cxstring: cx_strcast_c, \ |
| 321 | const char*: cx_strcast_z, \ | |
| 322 | char *: cx_strcast_z) (str) | |
| 579 | 323 | #endif |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | /** |
| 582 | 326 | * 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
|
327 | * |
| 579 | 328 | * The pointer in the struct is set to @c NULL and the length is set to zero |
| 329 | * which means that this function protects you against double-free. | |
| 330 | * | |
| 331 | * @note There is no implementation for cxstring, because it is unlikely that | |
| 332 | * you ever have a <code>const char*</code> you are really supposed to free. | |
| 333 | * 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
|
334 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | * @param str the string to free |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | */ |
| 579 | 337 | cx_attr_export |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | void cx_strfree(cxmutstr *str); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | |
|
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 | * 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
|
342 | * |
| 579 | 343 | * The pointer in the struct is set to @c NULL and the length is set to zero |
| 344 | * 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
|
345 | * |
| 579 | 346 | * @note There is no implementation for cxstring, because it is unlikely that |
| 347 | * you ever have a <code>const char*</code> you are really supposed to free. | |
| 348 | * 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
|
349 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | * @param alloc the allocator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | * @param str the string to free |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | */ |
| 579 | 353 | cx_attr_nonnull_arg(1) |
| 354 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | void cx_strfree_a( |
| 579 | 356 | const CxAllocator *alloc, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | cxmutstr *str |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | /** |
| 582 | 361 | * Copies a string. |
| 362 | * | |
| 363 | * The memory in the @p dest structure is either allocated or re-allocated to fit the entire | |
| 364 | * source string, including a zero-terminator. | |
| 365 | * | |
| 366 | * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. | |
| 367 | * | |
| 368 | * @param alloc the allocator | |
| 369 | * @param dest a pointer to the structure where to copy the contents to | |
| 370 | * @param src the source string | |
| 371 | * | |
| 372 | * @retval zero success | |
| 373 | * @retval non-zero if re-allocation failed | |
| 374 | */ | |
| 375 | cx_attr_nonnull_arg(1) | |
| 376 | cx_attr_export | |
| 377 | int cx_strcpy_a( | |
| 378 | const CxAllocator *alloc, | |
| 379 | cxmutstr *dest, | |
| 380 | cxstring src | |
| 381 | ); | |
| 382 | ||
| 383 | ||
| 384 | /** | |
| 385 | * Copies a string. | |
| 386 | * | |
| 387 | * The memory in the @p dest structure is either allocated or re-allocated to fit the entire | |
| 388 | * source string, including a zero-terminator. | |
| 389 | * | |
| 390 | * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. | |
| 391 | * | |
| 392 | * @param dest (@c cxmutstr*) a pointer to the structure where to copy the contents to | |
| 393 | * @param src (@c cxstring) the source string | |
| 394 | * | |
| 395 | * @retval zero success | |
| 396 | * @retval non-zero if re-allocation failed | |
| 397 | */ | |
| 398 | #define cx_strcpy(dest, src) cx_strcpy_a(cxDefaultAllocator, dest, src) | |
| 399 | ||
| 400 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | * Returns the accumulated length of all specified strings. |
| 579 | 402 | * |
| 403 | * 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
|
404 | * |
| 579 | 405 | * @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
|
406 | * specified strings, the behavior is undefined. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | * @param count the total number of specified strings |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | * @param ... all strings |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | * @return the accumulated length of all strings |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | */ |
| 579 | 412 | cx_attr_nodiscard |
| 413 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | size_t cx_strlen( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | size_t count, |
|
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 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | /** |
| 490 | 420 | * Concatenates strings. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | * The resulting string will be allocated by the specified allocator. |
| 579 | 423 | * So developers @em must pass the return value to cx_strfree_a() eventually. |
| 490 | 424 | * |
| 579 | 425 | * If @p str already contains a string, the memory will be reallocated and |
| 490 | 426 | * the other strings are appended. Otherwise, new memory is allocated. |
| 427 | * | |
| 579 | 428 | * If memory allocation fails, the pointer in the returned string will |
| 429 | * be @c NULL. Depending on the allocator, @c errno might be set. | |
| 430 | * | |
| 431 | * @note It is guaranteed that there is only one allocation for the | |
| 432 | * resulting string. | |
| 490 | 433 | * 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
|
434 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | * @param alloc the allocator to use |
| 490 | 436 | * @param str the string the other strings shall be concatenated to |
| 437 | * @param count the number of the other following strings to concatenate | |
| 579 | 438 | * @param ... all other UCX strings |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | * @return the concatenated string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | */ |
| 579 | 441 | cx_attr_nodiscard |
| 442 | cx_attr_nonnull | |
| 443 | cx_attr_export | |
| 490 | 444 | cxmutstr cx_strcat_ma( |
| 579 | 445 | const CxAllocator *alloc, |
| 490 | 446 | cxmutstr str, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | size_t count, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | ... |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | /** |
| 490 | 452 | * Concatenates strings and returns a new string. |
| 453 | * | |
| 454 | * The resulting string will be allocated by the specified allocator. | |
| 579 | 455 | * So developers @em must pass the return value to cx_strfree_a() eventually. |
| 490 | 456 | * |
| 579 | 457 | * If memory allocation fails, the pointer in the returned string will |
| 458 | * be @c NULL. Depending on the allocator, @c errno might be set. | |
| 459 | * | |
| 460 | * @note It is guaranteed that there is only one allocation for the | |
| 461 | * resulting string. | |
| 490 | 462 | * It is also guaranteed that the returned string is zero-terminated. |
| 463 | * | |
| 579 | 464 | * @param alloc (@c CxAllocator*) the allocator to use |
| 465 | * @param count (@c size_t) the number of the other following strings to concatenate | |
| 466 | * @param ... all other UCX strings | |
| 467 | * @return (@c cxmutstr) the concatenated string | |
| 490 | 468 | */ |
| 469 | #define cx_strcat_a(alloc, count, ...) \ | |
| 470 | cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) | |
| 471 | ||
| 472 | /** | |
| 473 | * Concatenates strings and returns a new string. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | * |
| 582 | 475 | * The resulting string will be allocated by the cxDefaultAllocator. |
| 579 | 476 | * 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
|
477 | * |
| 579 | 478 | * If memory allocation fails, the pointer in the returned string will |
| 479 | * be @c NULL and @c errno might be set. | |
| 480 | * | |
| 481 | * @note It is guaranteed that there is only one allocation for the | |
| 482 | * resulting string. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | * 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
|
484 | * |
| 579 | 485 | * @param count (@c size_t) the number of the other following strings to concatenate |
| 486 | * @param ... all other UCX strings | |
| 487 | * @return (@c cxmutstr) the concatenated string | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | #define cx_strcat(count, ...) \ |
| 490 | 490 | cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
| 491 | ||
| 492 | /** | |
| 493 | * Concatenates strings. | |
| 494 | * | |
| 582 | 495 | * The resulting string will be allocated by the cxDefaultAllocator. |
| 579 | 496 | * So developers @em must pass the return value to cx_strfree() eventually. |
| 490 | 497 | * |
| 579 | 498 | * If @p str already contains a string, the memory will be reallocated and |
| 490 | 499 | * the other strings are appended. Otherwise, new memory is allocated. |
| 500 | * | |
| 579 | 501 | * If memory allocation fails, the pointer in the returned string will |
| 502 | * be @c NULL and @c errno might be set. | |
| 503 | * | |
| 504 | * @note It is guaranteed that there is only one allocation for the | |
| 505 | * resulting string. | |
| 490 | 506 | * It is also guaranteed that the returned string is zero-terminated. |
| 507 | * | |
| 579 | 508 | * @param str (@c cxmutstr) the string the other strings shall be concatenated to |
| 509 | * @param count (@c size_t) the number of the other following strings to concatenate | |
| 510 | * @param ... all other strings | |
| 511 | * @return (@c cxmutstr) the concatenated string | |
| 490 | 512 | */ |
| 513 | #define cx_strcat_m(str, count, ...) \ | |
| 514 | 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
|
515 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | * |
| 579 | 519 | * @attention the new string references the same memory area as the |
| 520 | * 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
|
521 | * Use cx_strdup() to get a copy. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | * @param start start location of the substring |
| 579 | 525 | * @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
|
526 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
527 | * @see cx_strsubsl() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | * @see cx_strsubs_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529 | * @see cx_strsubsl_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | */ |
| 579 | 531 | cx_attr_nodiscard |
| 532 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
533 | cxstring cx_strsubs( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
535 | size_t start |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
539 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
540 | * |
| 579 | 541 | * The returned string will be limited to @p length bytes or the number |
| 542 | * 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
|
543 | * |
| 579 | 544 | * @attention the new string references the same memory area as the |
| 545 | * 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
|
546 | * Use cx_strdup() to get a copy. |
|
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 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
549 | * @param start start location of the substring |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
550 | * @param length the maximum length of the returned string |
| 579 | 551 | * @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
|
552 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553 | * @see cx_strsubs() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
554 | * @see cx_strsubs_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555 | * @see cx_strsubsl_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
556 | */ |
| 579 | 557 | cx_attr_nodiscard |
| 558 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | cxstring cx_strsubsl( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561 | size_t start, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | * |
| 579 | 568 | * @attention the new string references the same memory area as the |
| 569 | * 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
|
570 | * Use cx_strdup() to get a copy. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573 | * @param start start location of the substring |
| 579 | 574 | * @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
|
575 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576 | * @see cx_strsubsl_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | * @see cx_strsubs() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | * @see cx_strsubsl() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | */ |
| 579 | 580 | cx_attr_nodiscard |
| 581 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582 | cxmutstr cx_strsubs_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | size_t start |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588 | * Returns a substring starting at the specified location. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | * |
| 579 | 590 | * The returned string will be limited to @p length bytes or the number |
| 591 | * 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
|
592 | * |
| 579 | 593 | * @attention the new string references the same memory area as the |
| 594 | * 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
|
595 | * Use cx_strdup() to get a copy. |
|
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 | * @param string input string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | * @param start start location of the substring |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | * @param length the maximum length of the returned string |
| 579 | 600 | * @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
|
601 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602 | * @see cx_strsubs_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | * @see cx_strsubs() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | * @see cx_strsubsl() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | */ |
| 579 | 606 | cx_attr_nodiscard |
| 607 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | cxmutstr cx_strsubsl_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | size_t start, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
611 | size_t length |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | ); |
|
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 | * 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
|
616 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
618 | * 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
|
619 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | * @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
|
621 | * @param chr the character to locate |
| 579 | 622 | * @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
|
623 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | * @see cx_strchr_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625 | */ |
| 579 | 626 | cx_attr_nodiscard |
| 627 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628 | cxstring cx_strchr( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
630 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | ); |
|
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 | * 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
|
635 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637 | * 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
|
638 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | * @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
|
640 | * @param chr the character to locate |
| 579 | 641 | * @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
|
642 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643 | * @see cx_strchr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644 | */ |
| 579 | 645 | cx_attr_nodiscard |
| 646 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
647 | cxmutstr cx_strchr_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
648 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
649 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
650 | ); |
|
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 | * 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
|
654 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656 | * 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
|
657 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
658 | * @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
|
659 | * @param chr the character to locate |
| 579 | 660 | * @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
|
661 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | * @see cx_strrchr_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | */ |
| 579 | 664 | cx_attr_nodiscard |
| 665 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
666 | cxstring cx_strrchr( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | ); |
|
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 | * 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
|
673 | * specified character. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | * 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
|
676 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | * @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
|
678 | * @param chr the character to locate |
| 579 | 679 | * @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
|
680 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | * @see cx_strrchr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | */ |
| 579 | 683 | cx_attr_nodiscard |
| 684 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | cxmutstr cx_strrchr_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | int chr |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | * 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
|
692 | * specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | * |
| 579 | 694 | * 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
|
695 | * |
| 579 | 696 | * 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
|
697 | * returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | * @param haystack the string to be scanned |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | * @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
|
701 | * @return a substring starting at the first occurrence of |
| 579 | 702 | * @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
|
703 | * contained |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704 | * @see cx_strstr_m() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705 | */ |
| 579 | 706 | cx_attr_nodiscard |
| 707 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708 | cxstring cx_strstr( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709 | cxstring haystack, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710 | cxstring needle |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
711 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
712 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
713 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714 | * 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
|
715 | * specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | * |
| 579 | 717 | * 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
|
718 | * |
| 579 | 719 | * 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
|
720 | * returned. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | * @param haystack the string to be scanned |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | * @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
|
724 | * @return a substring starting at the first occurrence of |
| 579 | 725 | * @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
|
726 | * contained |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727 | * @see cx_strstr() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728 | */ |
| 579 | 729 | cx_attr_nodiscard |
| 730 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731 | cxmutstr cx_strstr_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
732 | cxmutstr haystack, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733 | cxstring needle |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | * |
| 579 | 739 | * @note The resulting array contains strings that point to the source |
| 740 | * @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
|
741 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | * @param limit the maximum number of split items |
| 579 | 745 | * @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
|
746 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | */ |
| 579 | 748 | cx_attr_nodiscard |
| 749 | cx_attr_nonnull | |
| 750 | cx_attr_access_w(4, 3) | |
| 751 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | size_t cx_strsplit( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | cxstring *output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761 | * |
| 579 | 762 | * 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
|
763 | * |
| 579 | 764 | * @note The resulting array contains strings that point to the source |
| 765 | * @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
|
766 | * |
| 579 | 767 | * @attention If allocation fails, the @c NULL pointer will be written to |
| 768 | * @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
|
769 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | * @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
|
771 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | * @param limit the maximum number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | * @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
|
775 | * written to |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | */ |
| 579 | 778 | cx_attr_nodiscard |
| 779 | cx_attr_nonnull | |
| 780 | cx_attr_access_w(5) | |
| 781 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
782 | size_t cx_strsplit_a( |
| 579 | 783 | const CxAllocator *allocator, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
784 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787 | cxstring **output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
788 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793 | * |
| 579 | 794 | * @note The resulting array contains strings that point to the source |
| 795 | * @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
|
796 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | * @param limit the maximum number of split items |
| 579 | 800 | * @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
|
801 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802 | */ |
| 579 | 803 | cx_attr_nodiscard |
| 804 | cx_attr_nonnull | |
| 805 | cx_attr_access_w(4, 3) | |
| 806 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807 | size_t cx_strsplit_m( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
808 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
809 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
810 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811 | cxmutstr *output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815 | * Splits a given string using a delimiter string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | * |
| 579 | 817 | * 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
|
818 | * |
| 579 | 819 | * @note The resulting array contains strings that point to the source |
| 820 | * @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
|
821 | * |
| 579 | 822 | * @attention If allocation fails, the @c NULL pointer will be written to |
| 823 | * @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
|
824 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | * @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
|
826 | * @param string the string to split |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | * @param delim the delimiter |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | * @param limit the maximum number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829 | * @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
|
830 | * written to |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | * @return the actual number of split items |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | */ |
| 579 | 833 | cx_attr_nodiscard |
| 834 | cx_attr_nonnull | |
| 835 | cx_attr_access_w(5) | |
| 836 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
837 | size_t cx_strsplit_ma( |
| 579 | 838 | const CxAllocator *allocator, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | cxmutstr string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | cxstring delim, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | size_t limit, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | cxmutstr **output |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843 | ); |
|
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 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | * Compares two strings. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | * @param s1 the first string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | * @param s2 the second string |
| 579 | 850 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 851 | * 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
|
852 | */ |
| 579 | 853 | cx_attr_nodiscard |
| 854 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
855 | int cx_strcmp( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
856 | cxstring s1, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
857 | cxstring s2 |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
858 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
859 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
860 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
861 | * Compares two strings ignoring case. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
862 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
863 | * @param s1 the first string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
864 | * @param s2 the second string |
| 579 | 865 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 866 | * 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
|
867 | */ |
| 579 | 868 | cx_attr_nodiscard |
| 869 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
870 | int cx_strcasecmp( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
871 | cxstring s1, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
872 | cxstring s2 |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
873 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
874 | |
| 490 | 875 | /** |
| 876 | * Compares two strings. | |
| 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 | |
| 490 | 884 | */ |
| 579 | 885 | cx_attr_nodiscard |
| 886 | cx_attr_nonnull | |
| 887 | cx_attr_export | |
| 490 | 888 | int cx_strcmp_p( |
| 579 | 889 | const void *s1, |
| 890 | const void *s2 | |
| 490 | 891 | ); |
| 892 | ||
| 893 | /** | |
| 894 | * Compares two strings ignoring case. | |
| 895 | * | |
| 896 | * This function has a compatible signature for the use as a cx_compare_func. | |
| 897 | * | |
| 898 | * @param s1 the first string | |
| 899 | * @param s2 the second string | |
| 579 | 900 | * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 901 | * than @p s2, zero if both strings equal ignoring case | |
| 490 | 902 | */ |
| 579 | 903 | cx_attr_nodiscard |
| 904 | cx_attr_nonnull | |
| 905 | cx_attr_export | |
| 490 | 906 | int cx_strcasecmp_p( |
| 579 | 907 | const void *s1, |
| 908 | const void *s2 | |
| 490 | 909 | ); |
| 910 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | |
|
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 | * Creates a duplicate of the specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | * |
| 579 | 915 | * 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
|
916 | * |
| 579 | 917 | * @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
|
918 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
919 | * @param allocator the allocator to use |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920 | * @param string the string to duplicate |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
921 | * @return a duplicate of the string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922 | * @see cx_strdup() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923 | */ |
| 579 | 924 | cx_attr_nodiscard |
| 925 | cx_attr_nonnull | |
| 926 | cx_attr_export | |
| 927 | cxmutstr cx_strdup_a_( | |
| 928 | const CxAllocator *allocator, | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | cxstring string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
930 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | * Creates a duplicate of the specified string. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | * |
| 579 | 935 | * The new string will contain a copy allocated by @p allocator. |
| 936 | * | |
| 937 | * @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
|
938 | * |
| 579 | 939 | * @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
|
940 | * @param string the string to duplicate |
| 579 | 941 | * @return (@c cxmutstr) a duplicate of the string |
| 942 | * @see cx_strdup() | |
| 943 | * @see cx_strfree_a() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | */ |
| 579 | 945 | #define cx_strdup_a(allocator, string) \ |
| 946 | cx_strdup_a_((allocator), cx_strcast(string)) | |
| 490 | 947 | |
| 948 | /** | |
| 949 | * Creates a duplicate of the specified string. | |
| 950 | * | |
| 582 | 951 | * The new string will contain a copy allocated by the cxDefaultAllocator. |
| 952 | * So developers @em must pass the return value to cx_strfree(). | |
| 490 | 953 | * |
| 579 | 954 | * @note The returned string is guaranteed to be zero-terminated. |
| 490 | 955 | * |
| 956 | * @param string the string to duplicate | |
| 579 | 957 | * @return (@c cxmutstr) a duplicate of the string |
| 958 | * @see cx_strdup_a() | |
| 959 | * @see cx_strfree() | |
| 490 | 960 | */ |
| 579 | 961 | #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
| 490 | 962 | |
|
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 | * Omits leading and trailing spaces. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | * |
| 579 | 966 | * @note the returned string references the same memory, thus you |
| 967 | * must @em not free the returned memory. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
968 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969 | * @param string the string that shall be trimmed |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970 | * @return the trimmed string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
971 | */ |
| 579 | 972 | cx_attr_nodiscard |
| 973 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
974 | cxstring cx_strtrim(cxstring string); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
975 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
976 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
977 | * Omits leading and trailing spaces. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
978 | * |
| 579 | 979 | * @note the returned string references the same memory, thus you |
| 980 | * must @em not free the returned memory. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
981 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
982 | * @param string the string that shall be trimmed |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
983 | * @return the trimmed string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
984 | */ |
| 579 | 985 | cx_attr_nodiscard |
| 986 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
987 | cxmutstr cx_strtrim_m(cxmutstr string); |
|
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 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
990 | * Checks, if a string has a specific prefix. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
991 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
992 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
993 | * @param prefix the prefix the string should have |
| 579 | 994 | * @return @c true, if and only if the string has the specified prefix, |
| 995 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
996 | */ |
| 579 | 997 | cx_attr_nodiscard |
| 998 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
999 | bool cx_strprefix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1000 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1001 | cxstring prefix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1002 | ); |
|
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 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1005 | * Checks, if a string has a specific suffix. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1006 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1007 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1008 | * @param suffix the suffix the string should have |
| 579 | 1009 | * @return @c true, if and only if the string has the specified suffix, |
| 1010 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1011 | */ |
| 579 | 1012 | cx_attr_nodiscard |
| 1013 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1014 | bool cx_strsuffix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1015 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1016 | cxstring suffix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1017 | ); |
|
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 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1020 | * 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
|
1021 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1022 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1023 | * @param prefix the prefix the string should have |
| 579 | 1024 | * @return @c true, if and only if the string has the specified prefix, |
| 1025 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026 | */ |
| 579 | 1027 | cx_attr_nodiscard |
| 1028 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029 | bool cx_strcaseprefix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1030 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1031 | cxstring prefix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1032 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1033 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1034 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | * 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
|
1036 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037 | * @param string the string to check |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1038 | * @param suffix the suffix the string should have |
| 579 | 1039 | * @return @c true, if and only if the string has the specified suffix, |
| 1040 | * @c false otherwise | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1041 | */ |
| 579 | 1042 | cx_attr_nodiscard |
| 1043 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1044 | bool cx_strcasesuffix( |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1045 | cxstring string, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1046 | cxstring suffix |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1047 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1048 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1049 | /** |
| 579 | 1050 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1051 | * |
| 579 | 1052 | * Replaces at most @p replmax occurrences. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1053 | * |
| 579 | 1054 | * 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
|
1055 | * to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1056 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1057 | * 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
|
1058 | * the returned string will be empty. |
|
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 | * @param allocator the allocator to use |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1061 | * @param str the string where replacements should be applied |
| 579 | 1062 | * @param search the string to search for |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1063 | * @param replacement the replacement string |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1064 | * @param replmax maximum number of replacements |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1065 | * @return the resulting string after applying the replacements |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1066 | */ |
| 579 | 1067 | cx_attr_nodiscard |
| 1068 | cx_attr_nonnull | |
| 1069 | cx_attr_export | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1070 | cxmutstr cx_strreplacen_a( |
| 579 | 1071 | const CxAllocator *allocator, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1072 | cxstring str, |
| 579 | 1073 | cxstring search, |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1074 | cxstring replacement, |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1075 | size_t replmax |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1076 | ); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1077 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1078 | /** |
| 579 | 1079 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1080 | * |
| 579 | 1081 | * Replaces at most @p replmax occurrences. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1082 | * |
| 582 | 1083 | * 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
|
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 str (@c cxstring) the string where replacements should be applied |
| 1090 | * @param search (@c cxstring) the string to search for | |
| 1091 | * @param replacement (@c cxstring) the replacement string | |
| 1092 | * @param replmax (@c size_t) maximum number of replacements | |
| 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_strreplacen(str, search, replacement, replmax) \ |
| 1096 | 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
|
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 | * |
| 579 | 1101 | * 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
|
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 allocator (@c CxAllocator*) the allocator to use |
| 1108 | * @param str (@c cxstring) the string where replacements should be applied | |
| 1109 | * @param search (@c cxstring) the string to search for | |
| 1110 | * @param replacement (@c cxstring) the replacement string | |
| 1111 | * @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
|
1112 | */ |
| 579 | 1113 | #define cx_strreplace_a(allocator, str, search, replacement) \ |
| 1114 | 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
|
1115 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1116 | /** |
| 579 | 1117 | * Replaces a string with another string. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1118 | * |
| 582 | 1119 | * 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
|
1120 | * to be zero-terminated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1121 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1122 | * 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
|
1123 | * the returned string will be empty. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1124 | * |
| 579 | 1125 | * @param str (@c cxstring) the string where replacements should be applied |
| 1126 | * @param search (@c cxstring) the string to search for | |
| 1127 | * @param replacement (@c cxstring) the replacement string | |
| 1128 | * @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
|
1129 | */ |
| 579 | 1130 | #define cx_strreplace(str, search, replacement) \ |
| 1131 | 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
|
1132 | |
| 490 | 1133 | /** |
| 1134 | * Creates a string tokenization context. | |
| 1135 | * | |
| 1136 | * @param str the string to tokenize | |
| 1137 | * @param delim the delimiter (must not be empty) | |
| 1138 | * @param limit the maximum number of tokens that shall be returned | |
| 1139 | * @return a new string tokenization context | |
| 1140 | */ | |
| 579 | 1141 | cx_attr_nodiscard |
| 1142 | cx_attr_export | |
| 1143 | CxStrtokCtx cx_strtok_( | |
| 490 | 1144 | cxstring str, |
| 1145 | cxstring delim, | |
| 1146 | size_t limit | |
| 1147 | ); | |
| 1148 | ||
| 1149 | /** | |
| 579 | 1150 | * Creates a string tokenization context. |
| 1151 | * | |
| 1152 | * @param str the string to tokenize | |
| 1153 | * @param delim the delimiter string (must not be empty) | |
| 1154 | * @param limit (@c size_t) the maximum number of tokens that shall be returned | |
| 1155 | * @return (@c CxStrtokCtx) a new string tokenization context | |
| 1156 | */ | |
| 1157 | #define cx_strtok(str, delim, limit) \ | |
| 1158 | cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit)) | |
| 490 | 1159 | |
| 1160 | /** | |
| 1161 | * Returns the next token. | |
| 1162 | * | |
| 1163 | * The token will point to the source string. | |
| 1164 | * | |
| 1165 | * @param ctx the tokenization context | |
| 1166 | * @param token a pointer to memory where the next token shall be stored | |
| 1167 | * @return true if successful, false if the limit or the end of the string | |
| 1168 | * has been reached | |
| 1169 | */ | |
| 579 | 1170 | cx_attr_nonnull |
| 1171 | cx_attr_nodiscard | |
| 1172 | cx_attr_access_w(2) | |
| 1173 | cx_attr_export | |
| 490 | 1174 | bool cx_strtok_next( |
| 1175 | CxStrtokCtx *ctx, | |
| 1176 | cxstring *token | |
| 1177 | ); | |
| 1178 | ||
| 1179 | /** | |
| 1180 | * Returns the next token of a mutable string. | |
| 1181 | * | |
| 1182 | * The token will point to the source string. | |
| 579 | 1183 | * |
| 1184 | * @attention | |
| 490 | 1185 | * If the context was not initialized over a mutable string, modifying |
| 1186 | * the data of the returned token is undefined behavior. | |
| 1187 | * | |
| 1188 | * @param ctx the tokenization context | |
| 1189 | * @param token a pointer to memory where the next token shall be stored | |
| 1190 | * @return true if successful, false if the limit or the end of the string | |
| 1191 | * has been reached | |
| 1192 | */ | |
| 579 | 1193 | cx_attr_nonnull |
| 1194 | cx_attr_nodiscard | |
| 1195 | cx_attr_access_w(2) | |
| 1196 | cx_attr_export | |
| 490 | 1197 | bool cx_strtok_next_m( |
| 1198 | CxStrtokCtx *ctx, | |
| 1199 | cxmutstr *token | |
| 1200 | ); | |
| 1201 | ||
| 1202 | /** | |
| 1203 | * Defines an array of more delimiters for the specified tokenization context. | |
| 1204 | * | |
| 1205 | * @param ctx the tokenization context | |
| 1206 | * @param delim array of more delimiters | |
| 1207 | * @param count number of elements in the array | |
| 1208 | */ | |
| 579 | 1209 | cx_attr_nonnull |
| 1210 | cx_attr_access_r(2, 3) | |
| 1211 | cx_attr_export | |
| 490 | 1212 | void cx_strtok_delim( |
| 1213 | CxStrtokCtx *ctx, | |
| 579 | 1214 | const cxstring *delim, |
| 490 | 1215 | size_t count |
| 1216 | ); | |
| 1217 | ||
| 579 | 1218 | /* ------------------------------------------------------------------------- * |
| 1219 | * string to number conversion functions * | |
| 1220 | * ------------------------------------------------------------------------- */ | |
| 1221 | ||
| 1222 | /** | |
| 1223 | * Converts a string to a number. | |
| 1224 | * | |
| 1225 | * The function returns non-zero when conversion is not possible. | |
| 1226 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1227 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1228 | * | |
| 1229 | * @param str the string to convert | |
| 1230 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1231 | * @param base 2, 8, 10, or 16 | |
| 1232 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1233 | * @retval zero success | |
| 1234 | * @retval non-zero conversion was not possible | |
| 1235 | */ | |
| 1236 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1237 | int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep); | |
| 1238 | ||
| 1239 | /** | |
| 1240 | * Converts a string to a number. | |
| 1241 | * | |
| 1242 | * The function returns non-zero when conversion is not possible. | |
| 1243 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1244 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1245 | * | |
| 1246 | * @param str the string to convert | |
| 1247 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1248 | * @param base 2, 8, 10, or 16 | |
| 1249 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1250 | * @retval zero success | |
| 1251 | * @retval non-zero conversion was not possible | |
| 1252 | */ | |
| 1253 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1254 | int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep); | |
| 1255 | ||
| 1256 | /** | |
| 1257 | * Converts a string to a number. | |
| 1258 | * | |
| 1259 | * The function returns non-zero when conversion is not possible. | |
| 1260 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1261 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1262 | * | |
| 1263 | * @param str the string to convert | |
| 1264 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1265 | * @param base 2, 8, 10, or 16 | |
| 1266 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1267 | * @retval zero success | |
| 1268 | * @retval non-zero conversion was not possible | |
| 1269 | */ | |
| 1270 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1271 | int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep); | |
| 1272 | ||
| 1273 | /** | |
| 1274 | * Converts a string to a number. | |
| 1275 | * | |
| 1276 | * The function returns non-zero when conversion is not possible. | |
| 1277 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1278 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1279 | * | |
| 1280 | * @param str the string to convert | |
| 1281 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1282 | * @param base 2, 8, 10, or 16 | |
| 1283 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1284 | * @retval zero success | |
| 1285 | * @retval non-zero conversion was not possible | |
| 1286 | */ | |
| 1287 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1288 | int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep); | |
| 1289 | ||
| 1290 | /** | |
| 1291 | * Converts a string to a number. | |
| 1292 | * | |
| 1293 | * The function returns non-zero when conversion is not possible. | |
| 1294 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1295 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1296 | * | |
| 1297 | * @param str the string to convert | |
| 1298 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1299 | * @param base 2, 8, 10, or 16 | |
| 1300 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1301 | * @retval zero success | |
| 1302 | * @retval non-zero conversion was not possible | |
| 1303 | */ | |
| 1304 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1305 | int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep); | |
| 1306 | ||
| 1307 | /** | |
| 1308 | * Converts a string to a number. | |
| 1309 | * | |
| 1310 | * The function returns non-zero when conversion is not possible. | |
| 1311 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1312 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1313 | * | |
| 1314 | * @param str the string to convert | |
| 1315 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1316 | * @param base 2, 8, 10, or 16 | |
| 1317 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1318 | * @retval zero success | |
| 1319 | * @retval non-zero conversion was not possible | |
| 1320 | */ | |
| 1321 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1322 | int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep); | |
| 1323 | ||
| 1324 | /** | |
| 1325 | * Converts a string to a number. | |
| 1326 | * | |
| 1327 | * The function returns non-zero when conversion is not possible. | |
| 1328 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1329 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1330 | * | |
| 1331 | * @param str the string to convert | |
| 1332 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1333 | * @param base 2, 8, 10, or 16 | |
| 1334 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1335 | * @retval zero success | |
| 1336 | * @retval non-zero conversion was not possible | |
| 1337 | */ | |
| 1338 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1339 | int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep); | |
| 1340 | ||
| 1341 | /** | |
| 1342 | * Converts a string to a number. | |
| 1343 | * | |
| 1344 | * The function returns non-zero when conversion is not possible. | |
| 1345 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1346 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1347 | * | |
| 1348 | * @param str the string to convert | |
| 1349 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1350 | * @param base 2, 8, 10, or 16 | |
| 1351 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1352 | * @retval zero success | |
| 1353 | * @retval non-zero conversion was not possible | |
| 1354 | */ | |
| 1355 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1356 | int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep); | |
| 1357 | ||
| 1358 | /** | |
| 1359 | * Converts a string to a number. | |
| 1360 | * | |
| 1361 | * The function returns non-zero when conversion is not possible. | |
| 1362 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1363 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1364 | * | |
| 1365 | * @param str the string to convert | |
| 1366 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1367 | * @param base 2, 8, 10, or 16 | |
| 1368 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1369 | * @retval zero success | |
| 1370 | * @retval non-zero conversion was not possible | |
| 1371 | */ | |
| 1372 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1373 | int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep); | |
| 1374 | ||
| 1375 | /** | |
| 1376 | * Converts a string to a number. | |
| 1377 | * | |
| 1378 | * The function returns non-zero when conversion is not possible. | |
| 1379 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1380 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1381 | * | |
| 1382 | * @param str the string to convert | |
| 1383 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1384 | * @param base 2, 8, 10, or 16 | |
| 1385 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1386 | * @retval zero success | |
| 1387 | * @retval non-zero conversion was not possible | |
| 1388 | */ | |
| 1389 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1390 | int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep); | |
| 1391 | ||
| 1392 | /** | |
| 1393 | * Converts a string to a number. | |
| 1394 | * | |
| 1395 | * The function returns non-zero when conversion is not possible. | |
| 1396 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1397 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1398 | * | |
| 1399 | * @param str the string to convert | |
| 1400 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1401 | * @param base 2, 8, 10, or 16 | |
| 1402 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1403 | * @retval zero success | |
| 1404 | * @retval non-zero conversion was not possible | |
| 1405 | */ | |
| 1406 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1407 | int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep); | |
| 1408 | ||
| 1409 | /** | |
| 1410 | * Converts a string to a number. | |
| 1411 | * | |
| 1412 | * The function returns non-zero when conversion is not possible. | |
| 1413 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1414 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1415 | * | |
| 1416 | * @param str the string to convert | |
| 1417 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1418 | * @param base 2, 8, 10, or 16 | |
| 1419 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1420 | * @retval zero success | |
| 1421 | * @retval non-zero conversion was not possible | |
| 1422 | */ | |
| 1423 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1424 | int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep); | |
| 1425 | ||
| 1426 | /** | |
| 1427 | * Converts a string to a number. | |
| 1428 | * | |
| 1429 | * The function returns non-zero when conversion is not possible. | |
| 1430 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1431 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1432 | * | |
| 1433 | * @param str the string to convert | |
| 1434 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1435 | * @param base 2, 8, 10, or 16 | |
| 1436 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1437 | * @retval zero success | |
| 1438 | * @retval non-zero conversion was not possible | |
| 1439 | */ | |
| 1440 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1441 | int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep); | |
| 1442 | ||
| 1443 | /** | |
| 1444 | * Converts a string to a number. | |
| 1445 | * | |
| 1446 | * The function returns non-zero when conversion is not possible. | |
| 1447 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1448 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1449 | * | |
| 1450 | * @param str the string to convert | |
| 1451 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1452 | * @param base 2, 8, 10, or 16 | |
| 1453 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1454 | * @retval zero success | |
| 1455 | * @retval non-zero conversion was not possible | |
| 1456 | */ | |
| 1457 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1458 | int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep); | |
| 1459 | ||
| 1460 | /** | |
| 1461 | * Converts a string to a number. | |
| 1462 | * | |
| 1463 | * The function returns non-zero when conversion is not possible. | |
| 1464 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1465 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1466 | * | |
| 1467 | * @param str the string to convert | |
| 1468 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1469 | * @param base 2, 8, 10, or 16 | |
| 1470 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1471 | * @retval zero success | |
| 1472 | * @retval non-zero conversion was not possible | |
| 1473 | */ | |
| 1474 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1475 | int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep); | |
| 1476 | ||
| 1477 | /** | |
| 1478 | * Converts a string to a number. | |
| 1479 | * | |
| 1480 | * The function returns non-zero when conversion is not possible. | |
| 1481 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1482 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1483 | * | |
| 1484 | * @param str the string to convert | |
| 1485 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1486 | * @param base 2, 8, 10, or 16 | |
| 1487 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1488 | * @retval zero success | |
| 1489 | * @retval non-zero conversion was not possible | |
| 1490 | */ | |
| 1491 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1492 | int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep); | |
| 1493 | ||
| 1494 | /** | |
| 1495 | * Converts a string to a number. | |
| 1496 | * | |
| 1497 | * The function returns non-zero when conversion is not possible. | |
| 1498 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1499 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1500 | * | |
| 1501 | * @param str the string to convert | |
| 1502 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1503 | * @param base 2, 8, 10, or 16 | |
| 1504 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1505 | * @retval zero success | |
| 1506 | * @retval non-zero conversion was not possible | |
| 1507 | */ | |
| 1508 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1509 | int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep); | |
| 1510 | ||
| 1511 | /** | |
| 1512 | * Converts a string to a single precision floating point number. | |
| 1513 | * | |
| 1514 | * The function returns non-zero when conversion is not possible. | |
| 1515 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 1516 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 1517 | * | |
| 1518 | * @param str the string to convert | |
| 1519 | * @param output a pointer to the float variable where the result shall be stored | |
| 1520 | * @param decsep the decimal separator | |
| 1521 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1522 | * @retval zero success | |
| 1523 | * @retval non-zero conversion was not possible | |
| 1524 | */ | |
| 1525 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1526 | int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep); | |
| 1527 | ||
| 1528 | /** | |
| 1529 | * Converts a string to a double precision floating point number. | |
| 1530 | * | |
| 1531 | * The function returns non-zero when conversion is not possible. | |
| 1532 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 1533 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 1534 | * | |
| 1535 | * @param str the string to convert | |
| 1536 | * @param output a pointer to the float variable where the result shall be stored | |
| 1537 | * @param decsep the decimal separator | |
| 1538 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 1539 | * @retval zero success | |
| 1540 | * @retval non-zero conversion was not possible | |
| 1541 | */ | |
| 1542 | cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export | |
| 1543 | int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep); | |
| 1544 | ||
| 1545 | /** | |
| 1546 | * Converts a string to a number. | |
| 1547 | * | |
| 1548 | * The function returns non-zero when conversion is not possible. | |
| 1549 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1550 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1551 | * | |
| 1552 | * @param str the string to convert | |
| 1553 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1554 | * @param base 2, 8, 10, or 16 | |
| 1555 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1556 | * @retval zero success | |
| 1557 | * @retval non-zero conversion was not possible | |
| 1558 | */ | |
| 1559 | #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep) | |
| 1560 | ||
| 1561 | /** | |
| 1562 | * Converts a string to a number. | |
| 1563 | * | |
| 1564 | * The function returns non-zero when conversion is not possible. | |
| 1565 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1566 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1567 | * | |
| 1568 | * @param str the string to convert | |
| 1569 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1570 | * @param base 2, 8, 10, or 16 | |
| 1571 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1572 | * @retval zero success | |
| 1573 | * @retval non-zero conversion was not possible | |
| 1574 | */ | |
| 1575 | #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep) | |
| 1576 | ||
| 1577 | /** | |
| 1578 | * Converts a string to a number. | |
| 1579 | * | |
| 1580 | * The function returns non-zero when conversion is not possible. | |
| 1581 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1582 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1583 | * | |
| 1584 | * @param str the string to convert | |
| 1585 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1586 | * @param base 2, 8, 10, or 16 | |
| 1587 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1588 | * @retval zero success | |
| 1589 | * @retval non-zero conversion was not possible | |
| 1590 | */ | |
| 1591 | #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep) | |
| 1592 | ||
| 1593 | /** | |
| 1594 | * Converts a string to a number. | |
| 1595 | * | |
| 1596 | * The function returns non-zero when conversion is not possible. | |
| 1597 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1598 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1599 | * | |
| 1600 | * @param str the string to convert | |
| 1601 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1602 | * @param base 2, 8, 10, or 16 | |
| 1603 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1604 | * @retval zero success | |
| 1605 | * @retval non-zero conversion was not possible | |
| 1606 | */ | |
| 1607 | #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep) | |
| 1608 | ||
| 1609 | /** | |
| 1610 | * Converts a string to a number. | |
| 1611 | * | |
| 1612 | * The function returns non-zero when conversion is not possible. | |
| 1613 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1614 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1615 | * | |
| 1616 | * @param str the string to convert | |
| 1617 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1618 | * @param base 2, 8, 10, or 16 | |
| 1619 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1620 | * @retval zero success | |
| 1621 | * @retval non-zero conversion was not possible | |
| 1622 | */ | |
| 1623 | #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep) | |
| 1624 | ||
| 1625 | /** | |
| 1626 | * Converts a string to a number. | |
| 1627 | * | |
| 1628 | * The function returns non-zero when conversion is not possible. | |
| 1629 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1630 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1631 | * | |
| 1632 | * @param str the string to convert | |
| 1633 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1634 | * @param base 2, 8, 10, or 16 | |
| 1635 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1636 | * @retval zero success | |
| 1637 | * @retval non-zero conversion was not possible | |
| 1638 | */ | |
| 1639 | #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep) | |
| 1640 | ||
| 1641 | /** | |
| 1642 | * Converts a string to a number. | |
| 1643 | * | |
| 1644 | * The function returns non-zero when conversion is not possible. | |
| 1645 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1646 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1647 | * | |
| 1648 | * @param str the string to convert | |
| 1649 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1650 | * @param base 2, 8, 10, or 16 | |
| 1651 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1652 | * @retval zero success | |
| 1653 | * @retval non-zero conversion was not possible | |
| 1654 | */ | |
| 1655 | #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep) | |
| 1656 | ||
| 1657 | /** | |
| 1658 | * Converts a string to a number. | |
| 1659 | * | |
| 1660 | * The function returns non-zero when conversion is not possible. | |
| 1661 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1662 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1663 | * | |
| 1664 | * @param str the string to convert | |
| 1665 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1666 | * @param base 2, 8, 10, or 16 | |
| 1667 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1668 | * @retval zero success | |
| 1669 | * @retval non-zero conversion was not possible | |
| 1670 | */ | |
| 1671 | #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep) | |
| 1672 | ||
| 1673 | /** | |
| 1674 | * Converts a string to a number. | |
| 1675 | * | |
| 1676 | * The function returns non-zero when conversion is not possible. | |
| 1677 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1678 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1679 | * | |
| 1680 | * @param str the string to convert | |
| 1681 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1682 | * @param base 2, 8, 10, or 16 | |
| 1683 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1684 | * @retval zero success | |
| 1685 | * @retval non-zero conversion was not possible | |
| 1686 | */ | |
| 1687 | #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep) | |
| 1688 | ||
| 1689 | /** | |
| 1690 | * Converts a string to a number. | |
| 1691 | * | |
| 1692 | * The function returns non-zero when conversion is not possible. | |
| 1693 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1694 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1695 | * | |
| 1696 | * @param str the string to convert | |
| 1697 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1698 | * @param base 2, 8, 10, or 16 | |
| 1699 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1700 | * @retval zero success | |
| 1701 | * @retval non-zero conversion was not possible | |
| 1702 | */ | |
| 1703 | #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep) | |
| 1704 | ||
| 1705 | /** | |
| 1706 | * Converts a string to a number. | |
| 1707 | * | |
| 1708 | * The function returns non-zero when conversion is not possible. | |
| 1709 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1710 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1711 | * | |
| 1712 | * @param str the string to convert | |
| 1713 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1714 | * @param base 2, 8, 10, or 16 | |
| 1715 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1716 | * @retval zero success | |
| 1717 | * @retval non-zero conversion was not possible | |
| 1718 | */ | |
| 1719 | #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep) | |
| 1720 | ||
| 1721 | /** | |
| 1722 | * Converts a string to a number. | |
| 1723 | * | |
| 1724 | * The function returns non-zero when conversion is not possible. | |
| 1725 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1726 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1727 | * | |
| 1728 | * @param str the string to convert | |
| 1729 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1730 | * @param base 2, 8, 10, or 16 | |
| 1731 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1732 | * @retval zero success | |
| 1733 | * @retval non-zero conversion was not possible | |
| 1734 | */ | |
| 1735 | #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep) | |
| 1736 | ||
| 1737 | /** | |
| 1738 | * Converts a string to a number. | |
| 1739 | * | |
| 1740 | * The function returns non-zero when conversion is not possible. | |
| 1741 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1742 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1743 | * | |
| 1744 | * @param str the string to convert | |
| 1745 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1746 | * @param base 2, 8, 10, or 16 | |
| 1747 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1748 | * @retval zero success | |
| 1749 | * @retval non-zero conversion was not possible | |
| 1750 | */ | |
| 1751 | #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep) | |
| 1752 | ||
| 1753 | /** | |
| 1754 | * Converts a string to a number. | |
| 1755 | * | |
| 1756 | * The function returns non-zero when conversion is not possible. | |
| 1757 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1758 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1759 | * | |
| 1760 | * @param str the string to convert | |
| 1761 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1762 | * @param base 2, 8, 10, or 16 | |
| 1763 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1764 | * @retval zero success | |
| 1765 | * @retval non-zero conversion was not possible | |
| 1766 | */ | |
| 1767 | #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep) | |
| 1768 | ||
| 1769 | /** | |
| 1770 | * Converts a string to a number. | |
| 1771 | * | |
| 1772 | * The function returns non-zero when conversion is not possible. | |
| 1773 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1774 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1775 | * | |
| 1776 | * @param str the string to convert | |
| 1777 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1778 | * @param base 2, 8, 10, or 16 | |
| 1779 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1780 | * @retval zero success | |
| 1781 | * @retval non-zero conversion was not possible | |
| 1782 | */ | |
| 1783 | #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep) | |
| 1784 | ||
| 1785 | /** | |
| 1786 | * Converts a string to a number. | |
| 1787 | * | |
| 1788 | * The function returns non-zero when conversion is not possible. | |
| 1789 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1790 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1791 | * | |
| 1792 | * @param str the string to convert | |
| 1793 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1794 | * @param base 2, 8, 10, or 16 | |
| 1795 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1796 | * @retval zero success | |
| 1797 | * @retval non-zero conversion was not possible | |
| 1798 | */ | |
| 1799 | #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep) | |
| 1800 | ||
| 1801 | /** | |
| 1802 | * Converts a string to a number. | |
| 1803 | * | |
| 1804 | * The function returns non-zero when conversion is not possible. | |
| 1805 | * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. | |
| 1806 | * It sets errno to ERANGE when the target datatype is too small. | |
| 1807 | * | |
| 1808 | * @param str the string to convert | |
| 1809 | * @param output a pointer to the integer variable where the result shall be stored | |
| 1810 | * @param base 2, 8, 10, or 16 | |
| 1811 | * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion | |
| 1812 | * @retval zero success | |
| 1813 | * @retval non-zero conversion was not possible | |
| 1814 | */ | |
| 1815 | #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep) | |
| 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_strtos(str, output, base) cx_strtos_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_strtoi(str, output, base) cx_strtoi_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_strtol(str, output, base) cx_strtol_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_strtoll(str, output, base) cx_strtoll_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_strtoi8(str, output, base) cx_strtoi8_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_strtoi16(str, output, base) cx_strtoi16_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_strtoi32(str, output, base) cx_strtoi32_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_strtoi64(str, output, base) cx_strtoi64_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_strtoz(str, output, base) cx_strtoz_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_strtous(str, output, base) cx_strtous_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_strtou(str, output, base) cx_strtou_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_strtoul(str, output, base) cx_strtoul_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_strtoull(str, output, base) cx_strtoull_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_strtou8(str, output, base) cx_strtou8_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_strtou16(str, output, base) cx_strtou16_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_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",") | |
| 2104 | ||
| 2105 | /** | |
| 2106 | * Converts a string to a 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 or an unsupported base. | |
| 2110 | * It sets errno to ERANGE when the target datatype is too small. | |
| 2111 | * | |
| 2112 | * The comma character is treated as group separator and ignored during parsing. | |
| 2113 | * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()). | |
| 2114 | * | |
| 2115 | * @param str the string to convert | |
| 2116 | * @param output a pointer to the integer variable where the result shall be stored | |
| 2117 | * @param base 2, 8, 10, or 16 | |
| 2118 | * @retval zero success | |
| 2119 | * @retval non-zero conversion was not possible | |
| 2120 | */ | |
| 2121 | #define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",") | |
| 2122 | ||
| 2123 | /** | |
| 2124 | * Converts a string to a single precision floating point number. | |
| 2125 | * | |
| 2126 | * The function returns non-zero when conversion is not possible. | |
| 2127 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2128 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 2129 | * | |
| 2130 | * @param str the string to convert | |
| 2131 | * @param output a pointer to the float variable where the result shall be stored | |
| 2132 | * @param decsep the decimal separator | |
| 2133 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 2134 | * @retval zero success | |
| 2135 | * @retval non-zero conversion was not possible | |
| 2136 | */ | |
| 2137 | #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep) | |
| 2138 | ||
| 2139 | /** | |
| 2140 | * Converts a string to a double precision floating point number. | |
| 2141 | * | |
| 2142 | * The function returns non-zero when conversion is not possible. | |
| 2143 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2144 | * | |
| 2145 | * @param str the string to convert | |
| 2146 | * @param output a pointer to the double variable where the result shall be stored | |
| 2147 | * @param decsep the decimal separator | |
| 2148 | * @param groupsep each character in this string is treated as group separator and ignored during conversion | |
| 2149 | * @retval zero success | |
| 2150 | * @retval non-zero conversion was not possible | |
| 2151 | */ | |
| 2152 | #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep) | |
| 2153 | ||
| 2154 | /** | |
| 2155 | * Converts a string to a single 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 | * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. | |
| 2160 | * | |
| 2161 | * The decimal separator is assumed to be a dot character. | |
| 2162 | * The comma character is treated as group separator and ignored during parsing. | |
| 2163 | * If you want to choose a different format, use cx_strtof_lc(). | |
| 2164 | * | |
| 2165 | * @param str the string to convert | |
| 2166 | * @param output a pointer to the float variable where the result shall be stored | |
| 2167 | * @retval zero success | |
| 2168 | * @retval non-zero conversion was not possible | |
| 2169 | */ | |
| 2170 | #define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",") | |
| 2171 | ||
| 2172 | /** | |
| 2173 | * Converts a string to a double precision floating point number. | |
| 2174 | * | |
| 2175 | * The function returns non-zero when conversion is not possible. | |
| 2176 | * In that case the function sets errno to EINVAL when the reason is an invalid character. | |
| 2177 | * | |
| 2178 | * The decimal separator is assumed to be a dot character. | |
| 2179 | * The comma character is treated as group separator and ignored during parsing. | |
| 2180 | * If you want to choose a different format, use cx_strtof_lc(). | |
| 2181 | * | |
| 2182 | * @param str the string to convert | |
| 2183 | * @param output a pointer to the double variable where the result shall be stored | |
| 2184 | * @retval zero success | |
| 2185 | * @retval non-zero conversion was not possible | |
| 2186 | */ | |
| 2187 | #define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",") | |
| 490 | 2188 | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2189 | #ifdef __cplusplus |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2190 | } // extern "C" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2191 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2192 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2193 | #endif //UCX_STRING_H |