Sun, 12 May 2019 13:49:36 +0200
fix res_link initialization
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
c1bc13faadaa
updates ucx to version 1.0
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 |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | * Bounded string implementation. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | * The UCX strings (<code>sstr_t</code>) provide an alternative to C strings. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | * The main difference to C strings is, that <code>sstr_t</code> does <b>not |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | * need to be <code>NULL</code>-terminated</b>. Instead the length is stored |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | * within the structure. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | * When using <code>sstr_t</code>, developers must be full aware of what type |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | * of string (<code>NULL</code>-terminated) or not) they are using, when |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | * accessing the <code>char* ptr</code> directly. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | * The UCX string module provides some common string functions, known from |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | * standard libc, working with <code>sstr_t</code>. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | * @file string.h |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | * @author Mike Becker |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | * @author Olaf Wintermann |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | #ifndef UCX_STRING_H |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | #define UCX_STRING_H |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | #include "ucx.h" |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | #include "allocator.h" |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | #include <stddef.h> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
505 | 55 | /* |
56 | * Use this macro to disable the shortcuts if you experience macro collision. | |
57 | */ | |
58 | #ifndef UCX_NO_SSTR_SHORTCUTS | |
59 | /** | |
60 | * Shortcut for a <code>sstr_t struct</code> | |
61 | * or <code>scstr_t struct</code> literal. | |
62 | */ | |
63 | #define ST(s) { s, sizeof(s)-1 } | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | /** Shortcut for the conversion of a C string to a <code>sstr_t</code>. */ |
505 | 66 | #define S(s) sstrn(s, sizeof(s)-1) |
67 | ||
68 | /** Shortcut for the conversion of a C string to a <code>scstr_t</code>. */ | |
69 | #define SC(s) scstrn(s, sizeof(s)-1) | |
70 | #endif /* UCX_NO_SSTR_SHORTCUTS */ | |
71 | ||
72 | /* | |
73 | * Use this macro to disable the format macros. | |
74 | */ | |
75 | #ifndef UCX_NO_SSTR_FORMAT_MACROS | |
76 | /** Expands a sstr_t or scstr_t to printf arguments. */ | |
77 | #define SFMT(s) (int) (s).length, (s).ptr | |
78 | ||
79 | /** Format specifier for a sstr_t or scstr_t. */ | |
80 | #define PRIsstr ".*s" | |
81 | #endif /* UCX_NO_SSTR_FORMAT_MACROS */ | |
82 | ||
83 | #ifdef __cplusplus | |
84 | extern "C" { | |
85 | #endif | |
86 | /** | |
87 | * The UCX string structure. | |
88 | */ | |
89 | typedef struct { | |
90 | /** A pointer to the string | |
91 | * (<b>not necessarily <code>NULL</code>-terminated</b>) */ | |
92 | char *ptr; | |
93 | /** The length of the string */ | |
94 | size_t length; | |
95 | } sstr_t; | |
96 | ||
97 | /** | |
98 | * The UCX string structure for immutable (constant) strings. | |
99 | */ | |
100 | typedef struct { | |
101 | /** A constant pointer to the immutable string | |
102 | * (<b>not necessarily <code>NULL</code>-terminated</b>) */ | |
103 | const char *ptr; | |
104 | /** The length of the string */ | |
105 | size_t length; | |
106 | } scstr_t; | |
107 | ||
108 | #ifdef __cplusplus | |
109 | } | |
110 | #endif | |
111 | ||
112 | ||
113 | #ifdef __cplusplus | |
114 | /** | |
115 | * One of two type adjustment functions that return a scstr_t. | |
116 | * | |
117 | * Used <b>internally</b> to convert a UCX string to an immutable UCX string. | |
118 | * | |
119 | * <b>Do not use this function manually.</b> | |
120 | * | |
121 | * @param str some sstr_t | |
122 | * @return an immutable (scstr_t) version of the provided string. | |
123 | */ | |
124 | inline scstr_t s2scstr(sstr_t s) { | |
125 | scstr_t c; | |
126 | c.ptr = s.ptr; | |
127 | c.length = s.length; | |
128 | return c; | |
129 | } | |
130 | ||
131 | /** | |
132 | * One of two type adjustment functions that return a scstr_t. | |
133 | * | |
134 | * Used <b>internally</b> to convert a UCX string to an immutable UCX string. | |
135 | * This variant is used, when the string is already immutable and no operation | |
136 | * needs to be performed. | |
137 | * | |
138 | * <b>Do not use this function manually.</b> | |
139 | * | |
140 | * @param str some scstr_t | |
141 | * @return the argument itself | |
142 | */ | |
143 | inline scstr_t s2scstr(scstr_t str) { | |
144 | return str; | |
145 | } | |
146 | ||
147 | /** | |
148 | * Converts a UCX string to an immutable UCX string (scstr_t). | |
149 | * @param str some UCX string | |
150 | * @return the an immutable version of the provided string | |
151 | */ | |
152 | #define SCSTR(s) s2scstr(s) | |
153 | #else | |
154 | ||
155 | /** | |
156 | * One of two type adjustment functions that return a scstr_t. | |
157 | * | |
158 | * Used <b>internally</b> to convert a UCX string to an immutable UCX string. | |
159 | * This variant is used, when the string is already immutable and no operation | |
160 | * needs to be performed. | |
161 | * | |
162 | * <b>Do not use this function manually.</b> | |
163 | * | |
164 | * @param str some scstr_t | |
165 | * @return the argument itself | |
166 | */ | |
167 | scstr_t ucx_sc2sc(scstr_t str); | |
168 | ||
169 | /** | |
170 | * One of two type adjustment functions that return a scstr_t. | |
171 | * | |
172 | * Used <b>internally</b> to convert a UCX string to an immutable UCX string. | |
173 | * | |
174 | * <b>Do not use this function manually.</b> | |
175 | * | |
176 | * @param str some sstr_t | |
177 | * @return an immutable (scstr_t) version of the provided string. | |
178 | */ | |
179 | scstr_t ucx_ss2sc(sstr_t str); | |
180 | ||
181 | #if __STDC_VERSION__ >= 201112L | |
182 | /** | |
183 | * Converts a UCX string to an immutable UCX string (scstr_t). | |
184 | * @param str some UCX string | |
185 | * @return the an immutable version of the provided string | |
186 | */ | |
187 | #define SCSTR(str) _Generic(str, sstr_t: ucx_ss2sc, scstr_t: ucx_sc2sc)(str) | |
188 | ||
189 | #elif defined(__GNUC__) || defined(__clang__) | |
190 | ||
191 | /** | |
192 | * Converts a UCX string to an immutable UCX string (scstr_t). | |
193 | * @param str some UCX string | |
194 | * @return the an immutable version of the provided string | |
195 | */ | |
196 | #define SCSTR(str) __builtin_choose_expr( \ | |
197 | __builtin_types_compatible_p(typeof(str), sstr_t), \ | |
198 | ucx_ss2sc, \ | |
199 | ucx_sc2sc)(str) | |
200 | ||
201 | #elif defined(__sun) | |
202 | ||
203 | /** | |
204 | * Converts a UCX string to an immutable UCX string (scstr_t). | |
205 | * @param str some UCX string | |
206 | * @return the an immutable version of the provided string | |
207 | */ | |
208 | #define SCSTR(str) ({typeof(str) ucx_tmp_var_str = str; \ | |
209 | scstr_t ucx_tmp_var_c; \ | |
210 | ucx_tmp_var_c.ptr = ucx_tmp_var_str.ptr;\ | |
211 | ucx_tmp_var_c.length = ucx_tmp_var_str.length;\ | |
212 | ucx_tmp_var_c; }) | |
213 | #else /* no generics and no builtins */ | |
214 | ||
215 | /** | |
216 | * Converts a UCX string to an immutable UCX string (scstr_t). | |
217 | * | |
218 | * This <b>internal</b> function (ab)uses the C standard an expects one single | |
219 | * argument which is then implicitly converted to scstr_t without a warning. | |
220 | * | |
221 | * <b>Do not use this function manually.</b> | |
222 | * | |
223 | * @return the an immutable version of the provided string | |
224 | */ | |
225 | scstr_t ucx_ss2c_s(); | |
226 | ||
227 | /** | |
228 | * Converts a UCX string to an immutable UCX string (scstr_t). | |
229 | * @param str some UCX string | |
230 | * @return the an immutable version of the provided string | |
231 | */ | |
232 | #define SCSTR(str) ucx_ss2c_s(str) | |
233 | #endif /* C11 feature test */ | |
234 | ||
235 | #endif /* C++ */ | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | #ifdef __cplusplus |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | extern "C" { |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | #endif |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | * Creates a new sstr_t based on a C string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | * The length is implicitly inferred by using a call to <code>strlen()</code>. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | * <b>Note:</b> the sstr_t will hold a <i>reference</i> to the C string. If you |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | * do want a copy, use sstrdup() on the return value of this function. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | * |
505 | 250 | * If you need to wrap a constant string, use scstr(). |
251 | * | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | * @param cstring the C string to wrap |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | * @return a new sstr_t containing the C string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | * @see sstrn() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | sstr_t sstr(char *cstring); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | * Creates a new sstr_t of the specified length based on a C string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | * <b>Note:</b> the sstr_t will hold a <i>reference</i> to the C string. If you |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | * do want a copy, use sstrdup() on the return value of this function. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | * |
505 | 265 | * If you need to wrap a constant string, use scstrn(). |
266 | * | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | * @param cstring the C string to wrap |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | * @param length the length of the string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | * @return a new sstr_t containing the C string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | * @see sstr() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | * @see S() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | sstr_t sstrn(char *cstring, size_t length); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | |
505 | 276 | /** |
277 | * Creates a new scstr_t based on a constant C string. | |
278 | * | |
279 | * The length is implicitly inferred by using a call to <code>strlen()</code>. | |
280 | * | |
281 | * <b>Note:</b> the scstr_t will hold a <i>reference</i> to the C string. If you | |
282 | * do want a copy, use scstrdup() on the return value of this function. | |
283 | * | |
284 | * @param cstring the C string to wrap | |
285 | * @return a new scstr_t containing the C string | |
286 | * | |
287 | * @see scstrn() | |
288 | */ | |
289 | scstr_t scstr(const char *cstring); | |
290 | ||
291 | ||
292 | /** | |
293 | * Creates a new scstr_t of the specified length based on a constant C string. | |
294 | * | |
295 | * <b>Note:</b> the scstr_t will hold a <i>reference</i> to the C string. If you | |
296 | * do want a copy, use scstrdup() on the return value of this function. | |
297 | * | |
298 | * | |
299 | * @param cstring the C string to wrap | |
300 | * @param length the length of the string | |
301 | * @return a new scstr_t containing the C string | |
302 | * | |
303 | * @see scstr() | |
304 | */ | |
305 | scstr_t scstrn(const char *cstring, size_t length); | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | * Returns the cumulated length of all specified strings. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | * <b>Attention:</b> if the count argument does not match the count of the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | * specified strings, the behavior is undefined. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | * @param count the total number of specified strings (so at least 1) |
505 | 314 | * @param ... all strings |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | * @return the cumulated length of all strings |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | */ |
505 | 317 | size_t scstrnlen(size_t count, ...); |
318 | ||
319 | /** | |
320 | * Alias for scstrnlen() which automatically converts the arguments. | |
321 | * | |
322 | * @param count the total number of specified strings (so at least 1) | |
323 | * @param ... all strings | |
324 | * @return the cumulated length of all strings | |
325 | */ | |
326 | #define sstrnlen(count, ...) scstrnlen(count, __VA_ARGS__) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | * Concatenates two or more strings. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | * The resulting string will be allocated by standard <code>malloc()</code>. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | * So developers <b>MUST</b> pass the sstr_t.ptr to <code>free()</code>. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>- |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | * terminated. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | * @param count the total number of strings to concatenate |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | * @param s1 first string |
505 | 339 | * @param ... all remaining strings |
340 | * @return the concatenated string | |
341 | */ | |
342 | sstr_t scstrcat(size_t count, scstr_t s1, ...); | |
343 | ||
344 | /** | |
345 | * Alias for scstrcat() which automatically converts the arguments. | |
346 | * | |
347 | * @param count the total number of strings to concatenate | |
348 | * @param s1 first string | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | * @param ... all remaining strings |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | * @return the concatenated string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | */ |
505 | 352 | #define sstrcat(count, s1, ...) scstrcat(count, SCSTR(s1), __VA_ARGS__) |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | * Concatenates two or more strings using a UcxAllocator. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | * |
505 | 357 | * See scstrcat() for details. |
358 | * | |
359 | * @param a the allocator to use | |
360 | * @param count the total number of strings to concatenate | |
361 | * @param s1 first string | |
362 | * @param ... all remaining strings | |
363 | * @return the concatenated string | |
364 | */ | |
365 | sstr_t scstrcat_a(UcxAllocator *a, size_t count, scstr_t s1, ...); | |
366 | ||
367 | /** | |
368 | * Alias for scstrcat_a() which automatically converts the arguments. | |
369 | * | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | * See sstrcat() for details. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | * @param a the allocator to use |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | * @param count the total number of strings to concatenate |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | * @param s1 first string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | * @param ... all remaining strings |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | * @return the concatenated string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | */ |
505 | 378 | #define sstrcat_a(a, count, s1, ...) \ |
379 | scstrcat_a(a, count, SCSTR(s1), __VA_ARGS__) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | * Returns a substring starting at the specified location. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | * <b>Attention:</b> the new string references the same memory area as the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | * input string and will <b>NOT</b> be <code>NULL</code>-terminated. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | * Use sstrdup() to get a copy. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | * @param string input string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | * @param start start location of the substring |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | * @return a substring of <code>string</code> starting at <code>start</code> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | * @see sstrsubsl() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | * @see sstrchr() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | sstr_t sstrsubs(sstr_t string, size_t start); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | * Returns a substring with a maximum length starting at the specified location. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | * <b>Attention:</b> the new string references the same memory area as the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | * input string and will <b>NOT</b> be <code>NULL</code>-terminated. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | * Use sstrdup() to get a copy. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | * @param string input string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | * @param start start location of the substring |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | * @param length the maximum length of the substring |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | * @return a substring of <code>string</code> starting at <code>start</code> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | * with a maximum length of <code>length</code> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | * @see sstrsubs() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | * @see sstrchr() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | sstr_t sstrsubsl(sstr_t string, size_t start, size_t length); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | /** |
505 | 416 | * Returns a substring of an immutable string starting at the specified |
417 | * location. | |
418 | * | |
419 | * <b>Attention:</b> the new string references the same memory area as the | |
420 | * input string and will <b>NOT</b> be <code>NULL</code>-terminated. | |
421 | * Use scstrdup() to get a copy. | |
422 | * | |
423 | * @param string input string | |
424 | * @param start start location of the substring | |
425 | * @return a substring of <code>string</code> starting at <code>start</code> | |
426 | * | |
427 | * @see scstrsubsl() | |
428 | * @see scstrchr() | |
429 | */ | |
430 | scstr_t scstrsubs(scstr_t string, size_t start); | |
431 | ||
432 | /** | |
433 | * Returns a substring of an immutable string with a maximum length starting | |
434 | * at the specified location. | |
435 | * | |
436 | * <b>Attention:</b> the new string references the same memory area as the | |
437 | * input string and will <b>NOT</b> be <code>NULL</code>-terminated. | |
438 | * Use scstrdup() to get a copy. | |
439 | * | |
440 | * @param string input string | |
441 | * @param start start location of the substring | |
442 | * @param length the maximum length of the substring | |
443 | * @return a substring of <code>string</code> starting at <code>start</code> | |
444 | * with a maximum length of <code>length</code> | |
445 | * | |
446 | * @see scstrsubs() | |
447 | * @see scstrchr() | |
448 | */ | |
449 | scstr_t scstrsubsl(scstr_t string, size_t start, size_t length); | |
450 | ||
451 | /** | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | * Returns a substring starting at the location of the first occurrence of the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | * specified character. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | * If the string does not contain the character, an empty string is returned. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | * @param string the string where to locate the character |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | * @param chr the character to locate |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | * @return a substring starting at the first location of <code>chr</code> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | * @see sstrsubs() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | sstr_t sstrchr(sstr_t string, int chr); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | * Returns a substring starting at the location of the last occurrence of the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | * specified character. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | * If the string does not contain the character, an empty string is returned. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | * @param string the string where to locate the character |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | * @param chr the character to locate |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | * @return a substring starting at the last location of <code>chr</code> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | * @see sstrsubs() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | sstr_t sstrrchr(sstr_t string, int chr); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | /** |
505 | 480 | * Returns an immutable substring starting at the location of the first |
481 | * occurrence of the specified character. | |
482 | * | |
483 | * If the string does not contain the character, an empty string is returned. | |
484 | * | |
485 | * @param string the string where to locate the character | |
486 | * @param chr the character to locate | |
487 | * @return a substring starting at the first location of <code>chr</code> | |
488 | * | |
489 | * @see scstrsubs() | |
490 | */ | |
491 | scstr_t scstrchr(scstr_t string, int chr); | |
492 | ||
493 | /** | |
494 | * Returns an immutable substring starting at the location of the last | |
495 | * occurrence of the specified character. | |
496 | * | |
497 | * If the string does not contain the character, an empty string is returned. | |
498 | * | |
499 | * @param string the string where to locate the character | |
500 | * @param chr the character to locate | |
501 | * @return a substring starting at the last location of <code>chr</code> | |
502 | * | |
503 | * @see scstrsubs() | |
504 | */ | |
505 | scstr_t scstrrchr(scstr_t string, int chr); | |
506 | ||
507 | /** | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | * Returns a substring starting at the location of the first occurrence of the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | * specified string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | * If the string does not contain the other string, an empty string is returned. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | * If <code>match</code> is an empty string, the complete <code>string</code> is |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | * returned. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | * @param string the string to be scanned |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | * @param match string containing the sequence of characters to match |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | * @return a substring starting at the first occurrence of |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519 | * <code>match</code>, or an empty string, if the sequence is not |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | * present in <code>string</code> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521 | */ |
505 | 522 | sstr_t scstrsstr(sstr_t string, scstr_t match); |
523 | ||
524 | /** | |
525 | * Alias for scstrsstr() which automatically converts the match string. | |
526 | * | |
527 | * @param string the string to be scanned | |
528 | * @param match string containing the sequence of characters to match | |
529 | * @return a substring starting at the first occurrence of | |
530 | * <code>match</code>, or an empty string, if the sequence is not | |
531 | * present in <code>string</code> | |
532 | */ | |
533 | #define sstrstr(string, match) scstrsstr(string, SCSTR(match)) | |
534 | ||
535 | /** | |
536 | * Returns an immutable substring starting at the location of the | |
537 | * first occurrence of the specified immutable string. | |
538 | * | |
539 | * If the string does not contain the other string, an empty string is returned. | |
540 | * | |
541 | * If <code>match</code> is an empty string, the complete <code>string</code> is | |
542 | * returned. | |
543 | * | |
544 | * @param string the string to be scanned | |
545 | * @param match string containing the sequence of characters to match | |
546 | * @return a substring starting at the first occurrence of | |
547 | * <code>match</code>, or an empty string, if the sequence is not | |
548 | * present in <code>string</code> | |
549 | */ | |
550 | scstr_t scstrscstr(scstr_t string, scstr_t match); | |
551 | ||
552 | /** | |
553 | * Alias for scstrscstr() which automatically converts the match string. | |
554 | * | |
555 | * @param string the string to be scanned | |
556 | * @param match string containing the sequence of characters to match | |
557 | * @return a substring starting at the first occurrence of | |
558 | * <code>match</code>, or an empty string, if the sequence is not | |
559 | * present in <code>string</code> | |
560 | */ | |
561 | #define sstrscstr(string, match) scstrscstr(string, SCSTR(match)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | * Splits a string into parts by using a delimiter string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | * This function will return <code>NULL</code>, if one of the following happens: |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | * <ul> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
568 | * <li>the string length is zero</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
569 | * <li>the delimeter length is zero</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570 | * <li>the string equals the delimeter</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571 | * <li>memory allocation fails</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572 | * </ul> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574 | * The integer referenced by <code>count</code> is used as input and determines |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | * the maximum size of the resulting array, i.e. the maximum count of splits to |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576 | * perform + 1. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | * The integer referenced by <code>count</code> is also used as output and is |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | * set to |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | * <ul> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | * <li>-2, on memory allocation errors</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582 | * <li>-1, if either the string or the delimiter is an empty string</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | * <li>0, if the string equals the delimiter</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | * <li>1, if the string does not contain the delimiter</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | * <li>the count of array items, otherwise</li> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | * </ul> |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588 | * If the string starts with the delimiter, the first item of the resulting |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | * array will be an empty string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | * If the string ends with the delimiter and the maximum list size is not |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
592 | * exceeded, the last array item will be an empty string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | * In case the list size would be exceeded, the last array item will be the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | * remaining string after the last split, <i>including</i> the terminating |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595 | * delimiter. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597 | * <b>Attention:</b> The array pointer <b>AND</b> all sstr_t.ptr of the array |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | * items must be manually passed to <code>free()</code>. Use sstrsplit_a() with |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | * an allocator to managed memory, to avoid this. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
601 | * @param string the string to split |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602 | * @param delim the delimiter string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | * @param count IN: the maximum size of the resulting array (0 = no limit), |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | * OUT: the actual size of the array |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | * @return a sstr_t array containing the split strings or |
505 | 606 | * <code>NULL</code> on error |
607 | * | |
608 | * @see scstrsplit_a() | |
609 | */ | |
610 | sstr_t* scstrsplit(scstr_t string, scstr_t delim, ssize_t *count); | |
611 | ||
612 | /** | |
613 | * Alias for scstrsplit() which automatically converts the arguments. | |
614 | * | |
615 | * @param string the string to split | |
616 | * @param delim the delimiter string | |
617 | * @param count IN: the maximum size of the resulting array (0 = no limit), | |
618 | * OUT: the actual size of the array | |
619 | * @return a sstr_t array containing the split strings or | |
620 | * <code>NULL</code> on error | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | * @see sstrsplit_a() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623 | */ |
505 | 624 | #define sstrsplit(string, delim, count) \ |
625 | scstrsplit(SCSTR(string), SCSTR(delim), count) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
627 | /** |
505 | 628 | * Performing scstrsplit() using a UcxAllocator. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | * |
505 | 630 | * <i>Read the description of scstrsplit() for details.</i> |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632 | * The memory for the sstr_t.ptr pointers of the array items and the memory for |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
633 | * the sstr_t array itself are allocated by using the UcxAllocator.malloc() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
634 | * function. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636 | * <b>Note:</b> the allocator is not used for memory that is freed within the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637 | * same call of this function (locally scoped variables). |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | * @param allocator the UcxAllocator used for allocating memory |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | * @param string the string to split |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641 | * @param delim the delimiter string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
642 | * @param count IN: the maximum size of the resulting array (0 = no limit), |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643 | * OUT: the actual size of the array |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644 | * @return a sstr_t array containing the split strings or |
505 | 645 | * <code>NULL</code> on error |
646 | * | |
647 | * @see scstrsplit() | |
648 | */ | |
649 | sstr_t* scstrsplit_a(UcxAllocator *allocator, scstr_t string, scstr_t delim, | |
650 | ssize_t *count); | |
651 | ||
652 | /** | |
653 | * Alias for scstrsplit_a() which automatically converts the arguments. | |
654 | * | |
655 | * @param allocator the UcxAllocator used for allocating memory | |
656 | * @param string the string to split | |
657 | * @param delim the delimiter string | |
658 | * @param count IN: the maximum size of the resulting array (0 = no limit), | |
659 | * OUT: the actual size of the array | |
660 | * @return a sstr_t array containing the split strings or | |
661 | * <code>NULL</code> on error | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | * @see sstrsplit() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664 | */ |
505 | 665 | #define sstrsplit_a(allocator, string, delim, count) \ |
666 | scstrsplit_a(allocator, SCSTR(string), SCSTR(delim), count) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | * Compares two UCX strings with standard <code>memcmp()</code>. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
670 | * |
505 | 671 | * At first it compares the scstr_t.length attribute of the two strings. The |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
672 | * <code>memcmp()</code> function is called, if and only if the lengths match. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674 | * @param s1 the first string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | * @param s2 the second string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676 | * @return -1, if the length of s1 is less than the length of s2 or 1, if the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | * length of s1 is greater than the length of s2 or the result of |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | * <code>memcmp()</code> otherwise (i.e. 0 if the strings match) |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | */ |
505 | 680 | int scstrcmp(scstr_t s1, scstr_t s2); |
681 | ||
682 | /** | |
683 | * Alias for scstrcmp() which automatically converts its arguments. | |
684 | * | |
685 | * @param s1 the first string | |
686 | * @param s2 the second string | |
687 | * @return -1, if the length of s1 is less than the length of s2 or 1, if the | |
688 | * length of s1 is greater than the length of s2 or the result of | |
689 | * <code>memcmp()</code> otherwise (i.e. 0 if the strings match) | |
690 | */ | |
691 | #define sstrcmp(s1, s2) scstrcmp(SCSTR(s1), SCSTR(s2)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | * Compares two UCX strings ignoring the case. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | * |
505 | 696 | * At first it compares the scstr_t.length attribute of the two strings. If and |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | * only if the lengths match, both strings are compared char by char ignoring |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | * the case. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | * @param s1 the first string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | * @param s2 the second string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702 | * @return -1, if the length of s1 is less than the length of s2 or 1, if the |
505 | 703 | * length of s1 is greater than the length of s2 or the result of the platform |
704 | * specific string comparison function ignoring the case. | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705 | */ |
505 | 706 | int scstrcasecmp(scstr_t s1, scstr_t s2); |
707 | ||
708 | /** | |
709 | * Alias for scstrcasecmp() which automatically converts the arguments. | |
710 | * | |
711 | * @param s1 the first string | |
712 | * @param s2 the second string | |
713 | * @return -1, if the length of s1 is less than the length of s2 or 1, if the | |
714 | * length of s1 is greater than the length of s2 or the result of the platform | |
715 | * specific string comparison function ignoring the case. | |
716 | */ | |
717 | #define sstrcasecmp(s1, s2) scstrcasecmp(SCSTR(s1), SCSTR(s2)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | * Creates a duplicate of the specified string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | * The new sstr_t will contain a copy allocated by standard |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | * <code>malloc()</code>. So developers <b>MUST</b> pass the sstr_t.ptr to |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | * <code>free()</code>. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>- |
505 | 727 | * terminated and mutable, regardless of the argument. |
728 | * | |
729 | * @param string the string to duplicate | |
730 | * @return a duplicate of the string | |
731 | * @see scstrdup_a() | |
732 | */ | |
733 | sstr_t scstrdup(scstr_t string); | |
734 | ||
735 | /** | |
736 | * Alias for scstrdup() which automatically converts the argument. | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | * @param string the string to duplicate |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | * @return a duplicate of the string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | * @see sstrdup_a() |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | */ |
505 | 742 | #define sstrdup(string) scstrdup(SCSTR(string)) |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745 | * Creates a duplicate of the specified string using a UcxAllocator. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | * The new sstr_t will contain a copy allocated by the allocators |
505 | 748 | * UcxAllocator.malloc() function. So it is implementation depended, whether the |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
749 | * returned sstr_t.ptr pointer must be passed to the allocators |
505 | 750 | * UcxAllocator.free() function manually. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
751 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>- |
505 | 753 | * terminated and mutable, regardless of the argument. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | * @param allocator a valid instance of a UcxAllocator |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | * @param string the string to duplicate |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | * @return a duplicate of the string |
505 | 758 | * @see scstrdup() |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | */ |
505 | 760 | sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t string); |
761 | ||
762 | /** | |
763 | * Alias for scstrdup_a() which automatically converts the argument. | |
764 | * | |
765 | * @param allocator a valid instance of a UcxAllocator | |
766 | * @param string the string to duplicate | |
767 | * @return a duplicate of the string | |
768 | * @see scstrdup() | |
769 | */ | |
770 | #define sstrdup_a(allocator, string) scstrdup_a(allocator, SCSTR(string)) | |
771 | ||
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | * Omits leading and trailing spaces. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | * This function returns a new sstr_t containing a trimmed version of the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | * specified string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | * <b>Note:</b> the new sstr_t references the same memory, thus you |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | * <b>MUST NOT</b> pass the sstr_t.ptr of the return value to |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | * <code>free()</code>. It is also highly recommended to avoid assignments like |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
782 | * <code>mystr = sstrtrim(mystr);</code> as you lose the reference to the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
783 | * source string. Assignments of this type are only permitted, if the |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
784 | * sstr_t.ptr of the source string does not need to be freed or if another |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | * reference to the source string exists. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787 | * @param string the string that shall be trimmed |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
788 | * @return a new sstr_t containing the trimmed string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | */ |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | sstr_t sstrtrim(sstr_t string); |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | /** |
505 | 793 | * Omits leading and trailing spaces. |
794 | * | |
795 | * This function returns a new scstr_t containing a trimmed version of the | |
796 | * specified string. | |
797 | * | |
798 | * <b>Note:</b> the new scstr_t references the same memory, thus you | |
799 | * <b>MUST NOT</b> pass the scstr_t.ptr of the return value to | |
800 | * <code>free()</code>. It is also highly recommended to avoid assignments like | |
801 | * <code>mystr = scstrtrim(mystr);</code> as you lose the reference to the | |
802 | * source string. Assignments of this type are only permitted, if the | |
803 | * scstr_t.ptr of the source string does not need to be freed or if another | |
804 | * reference to the source string exists. | |
805 | * | |
806 | * @param string the string that shall be trimmed | |
807 | * @return a new scstr_t containing the trimmed string | |
808 | */ | |
809 | scstr_t scstrtrim(scstr_t string); | |
810 | ||
811 | /** | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | * Checks, if a string has a specific prefix. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | * @param string the string to check |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | * @param prefix the prefix the string should have |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815 | * @return 1, if and only if the string has the specified prefix, 0 otherwise |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | */ |
505 | 817 | int scstrprefix(scstr_t string, scstr_t prefix); |
818 | ||
819 | /** | |
820 | * Alias for scstrprefix() which automatically converts the arguments. | |
821 | * | |
822 | * @param string the string to check | |
823 | * @param prefix the prefix the string should have | |
824 | * @return 1, if and only if the string has the specified prefix, 0 otherwise | |
825 | */ | |
826 | #define sstrprefix(string, prefix) scstrprefix(SCSTR(string), SCSTR(prefix)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829 | * Checks, if a string has a specific suffix. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830 | * @param string the string to check |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | * @param suffix the suffix the string should have |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | * @return 1, if and only if the string has the specified suffix, 0 otherwise |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | */ |
505 | 834 | int scstrsuffix(scstr_t string, scstr_t suffix); |
835 | ||
836 | /** | |
837 | * Alias for scstrsuffix() which automatically converts the arguments. | |
838 | * | |
839 | * @param string the string to check | |
840 | * @param suffix the suffix the string should have | |
841 | * @return 1, if and only if the string has the specified suffix, 0 otherwise | |
842 | */ | |
843 | #define sstrsuffix(string, suffix) scstrsuffix(SCSTR(string), SCSTR(suffix)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | * Returns a lower case version of a string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | * This function creates a duplicate of the input string, first. See the |
505 | 849 | * documentation of scstrdup() for the implications. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
850 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
851 | * @param string the input string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | * @return the resulting lower case string |
505 | 853 | * @see scstrdup() |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
854 | */ |
505 | 855 | sstr_t scstrlower(scstr_t string); |
856 | ||
857 | /** | |
858 | * Alias for scstrlower() which automatically converts the argument. | |
859 | * | |
860 | * @param string the input string | |
861 | * @return the resulting lower case string | |
862 | */ | |
863 | #define sstrlower(string) scstrlower(SCSTR(string)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
864 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
865 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
866 | * Returns a lower case version of a string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
867 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
868 | * This function creates a duplicate of the input string, first. See the |
505 | 869 | * documentation of scstrdup_a() for the implications. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
870 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
871 | * @param allocator the allocator used for duplicating the string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
872 | * @param string the input string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
873 | * @return the resulting lower case string |
505 | 874 | * @see scstrdup_a() |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
875 | */ |
505 | 876 | sstr_t scstrlower_a(UcxAllocator *allocator, scstr_t string); |
877 | ||
878 | ||
879 | /** | |
880 | * Alias for scstrlower_a() which automatically converts the argument. | |
881 | * | |
882 | * @param allocator the allocator used for duplicating the string | |
883 | * @param string the input string | |
884 | * @return the resulting lower case string | |
885 | */ | |
886 | #define sstrlower_a(allocator, string) scstrlower_a(allocator, SCSTR(string)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
887 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
888 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
889 | * Returns a upper case version of a string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
890 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
891 | * This function creates a duplicate of the input string, first. See the |
505 | 892 | * documentation of scstrdup() for the implications. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
894 | * @param string the input string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
895 | * @return the resulting upper case string |
505 | 896 | * @see scstrdup() |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
897 | */ |
505 | 898 | sstr_t scstrupper(scstr_t string); |
899 | ||
900 | /** | |
901 | * Alias for scstrupper() which automatically converts the argument. | |
902 | * | |
903 | * @param string the input string | |
904 | * @return the resulting upper case string | |
905 | */ | |
906 | #define sstrupper(string) scstrupper(SCSTR(string)) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
907 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
908 | /** |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
909 | * Returns a upper case version of a string. |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | * This function creates a duplicate of the input string, first. See the |
505 | 912 | * documentation of scstrdup_a() for the implications. |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | * |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | * @param allocator the allocator used for duplicating the string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | * @param string the input string |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916 | * @return the resulting upper case string |
505 | 917 | * @see scstrdup_a() |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
918 | */ |
505 | 919 | sstr_t scstrupper_a(UcxAllocator *allocator, scstr_t string); |
920 | ||
921 | /** | |
922 | * Alias for scstrupper_a() which automatically converts the argument. | |
923 | * | |
924 | * @param allocator the allocator used for duplicating the string | |
925 | * @param string the input string | |
926 | * @return the resulting upper case string | |
927 | */ | |
928 | #define sstrupper_a(allocator, string) scstrupper_a(allocator, string) | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
930 | #ifdef __cplusplus |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | } |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | #endif |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | |
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | #endif /* UCX_STRING_H */ |