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