Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1 | /************************************************************************* |
| 2 | * |
| 3 | * $Id$ |
| 4 | * |
| 5 | * Copyright (C) 2001 Bjorn Reese and Daniel Stenberg. |
| 6 | * |
| 7 | * Permission to use, copy, modify, and distribute this software for any |
| 8 | * purpose with or without fee is hereby granted, provided that the above |
| 9 | * copyright notice and this permission notice appear in all copies. |
| 10 | * |
| 11 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 12 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 13 | * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND |
| 14 | * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. |
| 15 | * |
| 16 | ************************************************************************/ |
| 17 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 18 | /************************************************************************* |
| 19 | * Include files |
| 20 | */ |
| 21 | |
| 22 | #include <assert.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <ctype.h> |
| 26 | #include <math.h> |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 27 | #include "triodef.h" |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 28 | #include "triostr.h" |
| 29 | |
| 30 | /************************************************************************* |
| 31 | * Definitions |
| 32 | */ |
| 33 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 34 | #if !defined(TRIO_STRING_PUBLIC) |
| 35 | # define TRIO_STRING_PUBLIC TRIO_PUBLIC |
| 36 | #endif |
| 37 | #if !defined(TRIO_STRING_PRIVATE) |
| 38 | # define TRIO_STRING_PRIVATE TRIO_PRIVATE |
| 39 | #endif |
| 40 | |
| 41 | #if !defined(NULL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 42 | # define NULL 0 |
| 43 | #endif |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 44 | #if !defined(NIL) |
| 45 | # define NIL ((char)0) |
| 46 | #endif |
| 47 | #if !defined(FALSE) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 48 | # define FALSE (1 == 0) |
| 49 | # define TRUE (! FALSE) |
| 50 | #endif |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 51 | #if !defined(BOOLEAN_T) |
| 52 | # define BOOLEAN_T int |
| 53 | #endif |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 54 | |
| 55 | #if defined(TRIO_COMPILER_SUPPORTS_C99) |
| 56 | # define USE_STRTOD |
| 57 | # define USE_STRTOF |
| 58 | #elif defined(TRIO_COMPILER_MSVC) |
| 59 | # define USE_STRTOD |
| 60 | #endif |
| 61 | |
| 62 | #if defined(TRIO_PLATFORM_UNIX) |
| 63 | # define USE_STRCASECMP |
| 64 | # define USE_STRNCASECMP |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 65 | # if defined(TRIO_PLATFORM_SUNOS) |
| 66 | # define USE_SYS_ERRLIST |
| 67 | # else |
| 68 | # define USE_STRERROR |
| 69 | # endif |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 70 | # if defined(TRIO_PLATFORM_QNX) |
| 71 | # define strcasecmp(x,y) stricmp(x,y) |
| 72 | # define strncasecmp(x,y,n) strnicmp(x,y,n) |
| 73 | # endif |
| 74 | #elif defined(TRIO_PLATFORM_WIN32) |
| 75 | # define USE_STRCASECMP |
Daniel Veillard | 59d3ed8 | 2007-04-17 12:44:58 +0000 | [diff] [blame] | 76 | # if defined(_WIN32_WCE) |
| 77 | # define strcasecmp(x,y) _stricmp(x,y) |
| 78 | # else |
| 79 | # define strcasecmp(x,y) strcmpi(x,y) |
| 80 | # endif |
Patrick Monnerat | ca9fc43 | 2013-12-12 15:11:40 +0800 | [diff] [blame^] | 81 | #elif defined(TRIO_PLATFORM_OS400) |
| 82 | # define USE_STRCASECMP |
| 83 | # define USE_STRNCASECMP |
| 84 | # include <strings.h> |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 87 | #if !(defined(TRIO_PLATFORM_SUNOS)) |
| 88 | # define USE_TOLOWER |
| 89 | # define USE_TOUPPER |
| 90 | #endif |
| 91 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 92 | /************************************************************************* |
| 93 | * Structures |
| 94 | */ |
| 95 | |
| 96 | struct _trio_string_t |
| 97 | { |
| 98 | char *content; |
| 99 | size_t length; |
| 100 | size_t allocated; |
| 101 | }; |
| 102 | |
| 103 | /************************************************************************* |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 104 | * Constants |
| 105 | */ |
| 106 | |
| 107 | #if !defined(TRIO_MINIMAL) |
| 108 | static TRIO_CONST char rcsid[] = "@(#)$Id$"; |
| 109 | #endif |
| 110 | |
| 111 | /************************************************************************* |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 112 | * Static String Functions |
| 113 | */ |
| 114 | |
| 115 | #if defined(TRIO_DOCUMENTATION) |
| 116 | # include "doc/doc_static.h" |
| 117 | #endif |
| 118 | /** @addtogroup StaticStrings |
| 119 | @{ |
| 120 | */ |
| 121 | |
| 122 | /** |
| 123 | Create new string. |
| 124 | |
| 125 | @param size Size of new string. |
| 126 | @return Pointer to string, or NULL if allocation failed. |
| 127 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 128 | TRIO_STRING_PUBLIC char * |
| 129 | trio_create |
| 130 | TRIO_ARGS1((size), |
| 131 | size_t size) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 132 | { |
| 133 | return (char *)TRIO_MALLOC(size); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /** |
| 138 | Destroy string. |
| 139 | |
| 140 | @param string String to be freed. |
| 141 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 142 | TRIO_STRING_PUBLIC void |
| 143 | trio_destroy |
| 144 | TRIO_ARGS1((string), |
| 145 | char *string) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 146 | { |
| 147 | if (string) |
| 148 | { |
| 149 | TRIO_FREE(string); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | /** |
| 155 | Count the number of characters in a string. |
| 156 | |
| 157 | @param string String to measure. |
| 158 | @return Number of characters in @string. |
| 159 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 160 | TRIO_STRING_PUBLIC size_t |
| 161 | trio_length |
| 162 | TRIO_ARGS1((string), |
| 163 | TRIO_CONST char *string) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 164 | { |
| 165 | return strlen(string); |
| 166 | } |
| 167 | |
| 168 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 169 | #if !defined(TRIO_MINIMAL) |
| 170 | /** |
| 171 | Append @p source at the end of @p target. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 172 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 173 | @param target Target string. |
| 174 | @param source Source string. |
| 175 | @return Boolean value indicating success or failure. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 176 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 177 | @pre @p target must point to a memory chunk with sufficient room to |
| 178 | contain the @p target string and @p source string. |
| 179 | @pre No boundary checking is performed, so insufficient memory will |
| 180 | result in a buffer overrun. |
| 181 | @post @p target will be zero terminated. |
| 182 | */ |
| 183 | TRIO_STRING_PUBLIC int |
| 184 | trio_append |
| 185 | TRIO_ARGS2((target, source), |
| 186 | char *target, |
| 187 | TRIO_CONST char *source) |
| 188 | { |
| 189 | assert(target); |
| 190 | assert(source); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 191 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 192 | return (strcat(target, source) != NULL); |
| 193 | } |
| 194 | #endif /* !defined(TRIO_MINIMAL) */ |
| 195 | |
| 196 | #if !defined(TRIO_MINIMAL) |
| 197 | /** |
| 198 | Append at most @p max characters from @p source to @p target. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 199 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 200 | @param target Target string. |
| 201 | @param max Maximum number of characters to append. |
| 202 | @param source Source string. |
| 203 | @return Boolean value indicating success or failure. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 204 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 205 | @pre @p target must point to a memory chuck with sufficient room to |
| 206 | contain the @p target string and the @p source string (at most @p max |
| 207 | characters). |
| 208 | @pre No boundary checking is performed, so insufficient memory will |
| 209 | result in a buffer overrun. |
| 210 | @post @p target will be zero terminated. |
| 211 | */ |
| 212 | TRIO_STRING_PUBLIC int |
| 213 | trio_append_max |
| 214 | TRIO_ARGS3((target, max, source), |
| 215 | char *target, |
| 216 | size_t max, |
| 217 | TRIO_CONST char *source) |
| 218 | { |
| 219 | size_t length; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 220 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 221 | assert(target); |
| 222 | assert(source); |
| 223 | |
| 224 | length = trio_length(target); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 225 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 226 | if (max > length) |
| 227 | { |
| 228 | strncat(target, source, max - length - 1); |
| 229 | } |
| 230 | return TRUE; |
| 231 | } |
| 232 | #endif /* !defined(TRIO_MINIMAL) */ |
| 233 | |
| 234 | |
| 235 | #if !defined(TRIO_MINIMAL) |
| 236 | /** |
| 237 | Determine if a string contains a substring. |
| 238 | |
| 239 | @param string String to be searched. |
| 240 | @param substring String to be found. |
| 241 | @return Boolean value indicating success or failure. |
| 242 | */ |
| 243 | TRIO_STRING_PUBLIC int |
| 244 | trio_contains |
| 245 | TRIO_ARGS2((string, substring), |
| 246 | TRIO_CONST char *string, |
| 247 | TRIO_CONST char *substring) |
| 248 | { |
| 249 | assert(string); |
| 250 | assert(substring); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 251 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 252 | return (0 != strstr(string, substring)); |
| 253 | } |
| 254 | #endif /* !defined(TRIO_MINIMAL) */ |
| 255 | |
| 256 | |
| 257 | #if !defined(TRIO_MINIMAL) |
| 258 | /** |
| 259 | Copy @p source to @p target. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 260 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 261 | @param target Target string. |
| 262 | @param source Source string. |
| 263 | @return Boolean value indicating success or failure. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 264 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 265 | @pre @p target must point to a memory chunk with sufficient room to |
| 266 | contain the @p source string. |
| 267 | @pre No boundary checking is performed, so insufficient memory will |
| 268 | result in a buffer overrun. |
| 269 | @post @p target will be zero terminated. |
| 270 | */ |
| 271 | TRIO_STRING_PUBLIC int |
| 272 | trio_copy |
| 273 | TRIO_ARGS2((target, source), |
| 274 | char *target, |
| 275 | TRIO_CONST char *source) |
| 276 | { |
| 277 | assert(target); |
| 278 | assert(source); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 279 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 280 | (void)strcpy(target, source); |
| 281 | return TRUE; |
| 282 | } |
| 283 | #endif /* !defined(TRIO_MINIMAL) */ |
| 284 | |
| 285 | |
| 286 | /** |
| 287 | Copy at most @p max characters from @p source to @p target. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 288 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 289 | @param target Target string. |
| 290 | @param max Maximum number of characters to append. |
| 291 | @param source Source string. |
| 292 | @return Boolean value indicating success or failure. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 293 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 294 | @pre @p target must point to a memory chunk with sufficient room to |
| 295 | contain the @p source string (at most @p max characters). |
| 296 | @pre No boundary checking is performed, so insufficient memory will |
| 297 | result in a buffer overrun. |
| 298 | @post @p target will be zero terminated. |
| 299 | */ |
| 300 | TRIO_STRING_PUBLIC int |
| 301 | trio_copy_max |
| 302 | TRIO_ARGS3((target, max, source), |
| 303 | char *target, |
| 304 | size_t max, |
| 305 | TRIO_CONST char *source) |
| 306 | { |
| 307 | assert(target); |
| 308 | assert(source); |
| 309 | assert(max > 0); /* Includes != 0 */ |
| 310 | |
| 311 | (void)strncpy(target, source, max - 1); |
| 312 | target[max - 1] = (char)0; |
| 313 | return TRUE; |
| 314 | } |
| 315 | |
| 316 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 317 | /* |
| 318 | * TrioDuplicateMax |
| 319 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 320 | TRIO_STRING_PRIVATE char * |
| 321 | TrioDuplicateMax |
| 322 | TRIO_ARGS2((source, size), |
| 323 | TRIO_CONST char *source, |
| 324 | size_t size) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 325 | { |
| 326 | char *target; |
| 327 | |
| 328 | assert(source); |
| 329 | |
| 330 | /* Make room for string plus a terminating zero */ |
| 331 | size++; |
| 332 | target = trio_create(size); |
| 333 | if (target) |
| 334 | { |
| 335 | trio_copy_max(target, size, source); |
| 336 | } |
| 337 | return target; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | /** |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 342 | Duplicate @p source. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 343 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 344 | @param source Source string. |
| 345 | @return A copy of the @p source string. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 346 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 347 | @post @p target will be zero terminated. |
| 348 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 349 | TRIO_STRING_PUBLIC char * |
| 350 | trio_duplicate |
| 351 | TRIO_ARGS1((source), |
| 352 | TRIO_CONST char *source) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 353 | { |
| 354 | return TrioDuplicateMax(source, trio_length(source)); |
| 355 | } |
| 356 | |
| 357 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 358 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 359 | /** |
| 360 | Duplicate at most @p max characters of @p source. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 361 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 362 | @param source Source string. |
| 363 | @param max Maximum number of characters to duplicate. |
| 364 | @return A copy of the @p source string. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 365 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 366 | @post @p target will be zero terminated. |
| 367 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 368 | TRIO_STRING_PUBLIC char * |
| 369 | trio_duplicate_max TRIO_ARGS2((source, max), |
| 370 | TRIO_CONST char *source, |
| 371 | size_t max) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 372 | { |
| 373 | size_t length; |
| 374 | |
| 375 | assert(source); |
| 376 | assert(max > 0); |
| 377 | |
| 378 | length = trio_length(source); |
| 379 | if (length > max) |
| 380 | { |
| 381 | length = max; |
| 382 | } |
| 383 | return TrioDuplicateMax(source, length); |
| 384 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 385 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 386 | |
| 387 | |
| 388 | /** |
| 389 | Compare if two strings are equal. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 390 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 391 | @param first First string. |
| 392 | @param second Second string. |
| 393 | @return Boolean indicating whether the two strings are equal or not. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 394 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 395 | Case-insensitive comparison. |
| 396 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 397 | TRIO_STRING_PUBLIC int |
| 398 | trio_equal |
| 399 | TRIO_ARGS2((first, second), |
| 400 | TRIO_CONST char *first, |
| 401 | TRIO_CONST char *second) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 402 | { |
| 403 | assert(first); |
| 404 | assert(second); |
| 405 | |
| 406 | if ((first != NULL) && (second != NULL)) |
| 407 | { |
| 408 | #if defined(USE_STRCASECMP) |
| 409 | return (0 == strcasecmp(first, second)); |
| 410 | #else |
| 411 | while ((*first != NIL) && (*second != NIL)) |
| 412 | { |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 413 | if (trio_to_upper(*first) != trio_to_upper(*second)) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 414 | { |
| 415 | break; |
| 416 | } |
| 417 | first++; |
| 418 | second++; |
| 419 | } |
| 420 | return ((*first == NIL) && (*second == NIL)); |
| 421 | #endif |
| 422 | } |
| 423 | return FALSE; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | /** |
| 428 | Compare if two strings are equal. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 429 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 430 | @param first First string. |
| 431 | @param second Second string. |
| 432 | @return Boolean indicating whether the two strings are equal or not. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 433 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 434 | Case-sensitive comparison. |
| 435 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 436 | TRIO_STRING_PUBLIC int |
| 437 | trio_equal_case |
| 438 | TRIO_ARGS2((first, second), |
| 439 | TRIO_CONST char *first, |
| 440 | TRIO_CONST char *second) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 441 | { |
| 442 | assert(first); |
| 443 | assert(second); |
| 444 | |
| 445 | if ((first != NULL) && (second != NULL)) |
| 446 | { |
| 447 | return (0 == strcmp(first, second)); |
| 448 | } |
| 449 | return FALSE; |
| 450 | } |
| 451 | |
| 452 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 453 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 454 | /** |
| 455 | Compare if two strings up until the first @p max characters are equal. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 456 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 457 | @param first First string. |
| 458 | @param max Maximum number of characters to compare. |
| 459 | @param second Second string. |
| 460 | @return Boolean indicating whether the two strings are equal or not. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 461 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 462 | Case-sensitive comparison. |
| 463 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 464 | TRIO_STRING_PUBLIC int |
| 465 | trio_equal_case_max |
| 466 | TRIO_ARGS3((first, max, second), |
| 467 | TRIO_CONST char *first, |
| 468 | size_t max, |
| 469 | TRIO_CONST char *second) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 470 | { |
| 471 | assert(first); |
| 472 | assert(second); |
| 473 | |
| 474 | if ((first != NULL) && (second != NULL)) |
| 475 | { |
| 476 | return (0 == strncmp(first, second, max)); |
| 477 | } |
| 478 | return FALSE; |
| 479 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 480 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 481 | |
| 482 | |
| 483 | /** |
| 484 | Compare if two strings are equal. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 485 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 486 | @param first First string. |
| 487 | @param second Second string. |
| 488 | @return Boolean indicating whether the two strings are equal or not. |
| 489 | |
| 490 | Collating characters are considered equal. |
| 491 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 492 | TRIO_STRING_PUBLIC int |
| 493 | trio_equal_locale |
| 494 | TRIO_ARGS2((first, second), |
| 495 | TRIO_CONST char *first, |
| 496 | TRIO_CONST char *second) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 497 | { |
| 498 | assert(first); |
| 499 | assert(second); |
| 500 | |
| 501 | #if defined(LC_COLLATE) |
| 502 | return (strcoll(first, second) == 0); |
| 503 | #else |
| 504 | return trio_equal(first, second); |
| 505 | #endif |
| 506 | } |
| 507 | |
| 508 | |
| 509 | /** |
| 510 | Compare if two strings up until the first @p max characters are equal. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 511 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 512 | @param first First string. |
| 513 | @param max Maximum number of characters to compare. |
| 514 | @param second Second string. |
| 515 | @return Boolean indicating whether the two strings are equal or not. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 516 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 517 | Case-insensitive comparison. |
| 518 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 519 | TRIO_STRING_PUBLIC int |
| 520 | trio_equal_max |
| 521 | TRIO_ARGS3((first, max, second), |
| 522 | TRIO_CONST char *first, |
| 523 | size_t max, |
| 524 | TRIO_CONST char *second) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 525 | { |
| 526 | assert(first); |
| 527 | assert(second); |
| 528 | |
| 529 | if ((first != NULL) && (second != NULL)) |
| 530 | { |
| 531 | #if defined(USE_STRNCASECMP) |
| 532 | return (0 == strncasecmp(first, second, max)); |
| 533 | #else |
| 534 | /* Not adequately tested yet */ |
| 535 | size_t cnt = 0; |
| 536 | while ((*first != NIL) && (*second != NIL) && (cnt <= max)) |
| 537 | { |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 538 | if (trio_to_upper(*first) != trio_to_upper(*second)) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 539 | { |
| 540 | break; |
| 541 | } |
| 542 | first++; |
| 543 | second++; |
| 544 | cnt++; |
| 545 | } |
| 546 | return ((cnt == max) || ((*first == NIL) && (*second == NIL))); |
| 547 | #endif |
| 548 | } |
| 549 | return FALSE; |
| 550 | } |
| 551 | |
| 552 | |
| 553 | /** |
| 554 | Provide a textual description of an error code (errno). |
| 555 | |
| 556 | @param error_number Error number. |
| 557 | @return Textual description of @p error_number. |
| 558 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 559 | TRIO_STRING_PUBLIC TRIO_CONST char * |
| 560 | trio_error |
| 561 | TRIO_ARGS1((error_number), |
| 562 | int error_number) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 563 | { |
| 564 | #if defined(USE_STRERROR) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 565 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 566 | return strerror(error_number); |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 567 | |
| 568 | #elif defined(USE_SYS_ERRLIST) |
| 569 | |
| 570 | extern char *sys_errlist[]; |
| 571 | extern int sys_nerr; |
| 572 | |
| 573 | return ((error_number < 0) || (error_number >= sys_nerr)) |
| 574 | ? "unknown" |
| 575 | : sys_errlist[error_number]; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 576 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 577 | #else |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 578 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 579 | return "unknown"; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 580 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 581 | #endif |
| 582 | } |
| 583 | |
| 584 | |
Daniel Veillard | 59d3ed8 | 2007-04-17 12:44:58 +0000 | [diff] [blame] | 585 | #if !defined(TRIO_MINIMAL) && !defined(_WIN32_WCE) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 586 | /** |
| 587 | Format the date/time according to @p format. |
| 588 | |
| 589 | @param target Target string. |
| 590 | @param max Maximum number of characters to format. |
| 591 | @param format Formatting string. |
| 592 | @param datetime Date/time structure. |
| 593 | @return Number of formatted characters. |
| 594 | |
| 595 | The formatting string accepts the same specifiers as the standard C |
| 596 | function strftime. |
| 597 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 598 | TRIO_STRING_PUBLIC size_t |
| 599 | trio_format_date_max |
| 600 | TRIO_ARGS4((target, max, format, datetime), |
| 601 | char *target, |
| 602 | size_t max, |
| 603 | TRIO_CONST char *format, |
| 604 | TRIO_CONST struct tm *datetime) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 605 | { |
| 606 | assert(target); |
| 607 | assert(format); |
| 608 | assert(datetime); |
| 609 | assert(max > 0); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 610 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 611 | return strftime(target, max, format, datetime); |
| 612 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 613 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 614 | |
| 615 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 616 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 617 | /** |
| 618 | Calculate a hash value for a string. |
| 619 | |
| 620 | @param string String to be calculated on. |
| 621 | @param type Hash function. |
| 622 | @return Calculated hash value. |
| 623 | |
| 624 | @p type can be one of the following |
| 625 | @li @c TRIO_HASH_PLAIN Plain hash function. |
| 626 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 627 | TRIO_STRING_PUBLIC unsigned long |
| 628 | trio_hash |
| 629 | TRIO_ARGS2((string, type), |
| 630 | TRIO_CONST char *string, |
| 631 | int type) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 632 | { |
| 633 | unsigned long value = 0L; |
| 634 | char ch; |
| 635 | |
| 636 | assert(string); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 637 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 638 | switch (type) |
| 639 | { |
| 640 | case TRIO_HASH_PLAIN: |
| 641 | while ( (ch = *string++) != NIL ) |
| 642 | { |
| 643 | value *= 31; |
| 644 | value += (unsigned long)ch; |
| 645 | } |
| 646 | break; |
| 647 | default: |
| 648 | assert(FALSE); |
| 649 | break; |
| 650 | } |
| 651 | return value; |
| 652 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 653 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 654 | |
| 655 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 656 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 657 | /** |
| 658 | Find first occurrence of a character in a string. |
| 659 | |
| 660 | @param string String to be searched. |
| 661 | @param character Character to be found. |
| 662 | @param A pointer to the found character, or NULL if character was not found. |
| 663 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 664 | TRIO_STRING_PUBLIC char * |
| 665 | trio_index |
| 666 | TRIO_ARGS2((string, character), |
| 667 | TRIO_CONST char *string, |
| 668 | int character) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 669 | { |
| 670 | assert(string); |
| 671 | |
| 672 | return strchr(string, character); |
| 673 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 674 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 675 | |
| 676 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 677 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 678 | /** |
| 679 | Find last occurrence of a character in a string. |
| 680 | |
| 681 | @param string String to be searched. |
| 682 | @param character Character to be found. |
| 683 | @param A pointer to the found character, or NULL if character was not found. |
| 684 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 685 | TRIO_STRING_PUBLIC char * |
| 686 | trio_index_last |
| 687 | TRIO_ARGS2((string, character), |
| 688 | TRIO_CONST char *string, |
| 689 | int character) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 690 | { |
| 691 | assert(string); |
| 692 | |
| 693 | return strchr(string, character); |
| 694 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 695 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 696 | |
| 697 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 698 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 699 | /** |
| 700 | Convert the alphabetic letters in the string to lower-case. |
| 701 | |
| 702 | @param target String to be converted. |
| 703 | @return Number of processed characters (converted or not). |
| 704 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 705 | TRIO_STRING_PUBLIC int |
| 706 | trio_lower |
| 707 | TRIO_ARGS1((target), |
| 708 | char *target) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 709 | { |
| 710 | assert(target); |
| 711 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 712 | return trio_span_function(target, target, trio_to_lower); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 713 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 714 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 715 | |
| 716 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 717 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 718 | /** |
| 719 | Compare two strings using wildcards. |
| 720 | |
| 721 | @param string String to be searched. |
| 722 | @param pattern Pattern, including wildcards, to search for. |
| 723 | @return Boolean value indicating success or failure. |
| 724 | |
| 725 | Case-insensitive comparison. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 726 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 727 | The following wildcards can be used |
| 728 | @li @c * Match any number of characters. |
| 729 | @li @c ? Match a single character. |
| 730 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 731 | TRIO_STRING_PUBLIC int |
| 732 | trio_match |
| 733 | TRIO_ARGS2((string, pattern), |
| 734 | TRIO_CONST char *string, |
| 735 | TRIO_CONST char *pattern) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 736 | { |
| 737 | assert(string); |
| 738 | assert(pattern); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 739 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 740 | for (; ('*' != *pattern); ++pattern, ++string) |
| 741 | { |
| 742 | if (NIL == *string) |
| 743 | { |
| 744 | return (NIL == *pattern); |
| 745 | } |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 746 | if ((trio_to_upper((int)*string) != trio_to_upper((int)*pattern)) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 747 | && ('?' != *pattern)) |
| 748 | { |
| 749 | return FALSE; |
| 750 | } |
| 751 | } |
| 752 | /* two-line patch to prevent *too* much recursiveness: */ |
| 753 | while ('*' == pattern[1]) |
| 754 | pattern++; |
| 755 | |
| 756 | do |
| 757 | { |
| 758 | if ( trio_match(string, &pattern[1]) ) |
| 759 | { |
| 760 | return TRUE; |
| 761 | } |
| 762 | } |
| 763 | while (*string++); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 764 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 765 | return FALSE; |
| 766 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 767 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 768 | |
| 769 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 770 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 771 | /** |
| 772 | Compare two strings using wildcards. |
| 773 | |
| 774 | @param string String to be searched. |
| 775 | @param pattern Pattern, including wildcards, to search for. |
| 776 | @return Boolean value indicating success or failure. |
| 777 | |
| 778 | Case-sensitive comparison. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 779 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 780 | The following wildcards can be used |
| 781 | @li @c * Match any number of characters. |
| 782 | @li @c ? Match a single character. |
| 783 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 784 | TRIO_STRING_PUBLIC int |
| 785 | trio_match_case |
| 786 | TRIO_ARGS2((string, pattern), |
| 787 | TRIO_CONST char *string, |
| 788 | TRIO_CONST char *pattern) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 789 | { |
| 790 | assert(string); |
| 791 | assert(pattern); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 792 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 793 | for (; ('*' != *pattern); ++pattern, ++string) |
| 794 | { |
| 795 | if (NIL == *string) |
| 796 | { |
| 797 | return (NIL == *pattern); |
| 798 | } |
| 799 | if ((*string != *pattern) |
| 800 | && ('?' != *pattern)) |
| 801 | { |
| 802 | return FALSE; |
| 803 | } |
| 804 | } |
| 805 | /* two-line patch to prevent *too* much recursiveness: */ |
| 806 | while ('*' == pattern[1]) |
| 807 | pattern++; |
| 808 | |
| 809 | do |
| 810 | { |
| 811 | if ( trio_match_case(string, &pattern[1]) ) |
| 812 | { |
| 813 | return TRUE; |
| 814 | } |
| 815 | } |
| 816 | while (*string++); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 817 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 818 | return FALSE; |
| 819 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 820 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 821 | |
| 822 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 823 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 824 | /** |
| 825 | Execute a function on each character in string. |
| 826 | |
| 827 | @param target Target string. |
| 828 | @param source Source string. |
| 829 | @param Function Function to be executed. |
| 830 | @return Number of processed characters. |
| 831 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 832 | TRIO_STRING_PUBLIC size_t |
| 833 | trio_span_function |
| 834 | TRIO_ARGS3((target, source, Function), |
| 835 | char *target, |
| 836 | TRIO_CONST char *source, |
| 837 | int (*Function) TRIO_PROTO((int))) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 838 | { |
| 839 | size_t count = 0; |
| 840 | |
| 841 | assert(target); |
| 842 | assert(source); |
| 843 | assert(Function); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 844 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 845 | while (*source != NIL) |
| 846 | { |
| 847 | *target++ = Function(*source++); |
| 848 | count++; |
| 849 | } |
| 850 | return count; |
| 851 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 852 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 853 | |
| 854 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 855 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 856 | /** |
| 857 | Search for a substring in a string. |
| 858 | |
| 859 | @param string String to be searched. |
| 860 | @param substring String to be found. |
| 861 | @return Pointer to first occurrence of @p substring in @p string, or NULL |
| 862 | if no match was found. |
| 863 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 864 | TRIO_STRING_PUBLIC char * |
| 865 | trio_substring |
| 866 | TRIO_ARGS2((string, substring), |
| 867 | TRIO_CONST char *string, |
| 868 | TRIO_CONST char *substring) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 869 | { |
| 870 | assert(string); |
| 871 | assert(substring); |
| 872 | |
| 873 | return strstr(string, substring); |
| 874 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 875 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 876 | |
| 877 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 878 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 879 | /** |
| 880 | Search for a substring in the first @p max characters of a string. |
| 881 | |
| 882 | @param string String to be searched. |
| 883 | @param max Maximum characters to be searched. |
| 884 | @param substring String to be found. |
| 885 | @return Pointer to first occurrence of @p substring in @p string, or NULL |
| 886 | if no match was found. |
| 887 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 888 | TRIO_STRING_PUBLIC char * |
| 889 | trio_substring_max |
| 890 | TRIO_ARGS3((string, max, substring), |
| 891 | TRIO_CONST char *string, |
| 892 | size_t max, |
| 893 | TRIO_CONST char *substring) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 894 | { |
| 895 | size_t count; |
| 896 | size_t size; |
| 897 | char *result = NULL; |
| 898 | |
| 899 | assert(string); |
| 900 | assert(substring); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 901 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 902 | size = trio_length(substring); |
| 903 | if (size <= max) |
| 904 | { |
| 905 | for (count = 0; count <= max - size; count++) |
| 906 | { |
| 907 | if (trio_equal_max(substring, size, &string[count])) |
| 908 | { |
| 909 | result = (char *)&string[count]; |
| 910 | break; |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | return result; |
| 915 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 916 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 917 | |
| 918 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 919 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 920 | /** |
| 921 | Tokenize string. |
| 922 | |
| 923 | @param string String to be tokenized. |
| 924 | @param tokens String containing list of delimiting characters. |
| 925 | @return Start of new token. |
| 926 | |
| 927 | @warning @p string will be destroyed. |
| 928 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 929 | TRIO_STRING_PUBLIC char * |
| 930 | trio_tokenize |
| 931 | TRIO_ARGS2((string, delimiters), |
| 932 | char *string, |
| 933 | TRIO_CONST char *delimiters) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 934 | { |
| 935 | assert(delimiters); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 936 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 937 | return strtok(string, delimiters); |
| 938 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 939 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 940 | |
| 941 | |
| 942 | /** |
| 943 | Convert string to floating-point number. |
| 944 | |
| 945 | @param source String to be converted. |
| 946 | @param endp Pointer to end of the converted string. |
| 947 | @return A floating-point number. |
| 948 | |
| 949 | The following Extended Backus-Naur form is used |
| 950 | @verbatim |
| 951 | double ::= [ <sign> ] |
| 952 | ( <number> | |
| 953 | <number> <decimal_point> <number> | |
| 954 | <decimal_point> <number> ) |
| 955 | [ <exponential> [ <sign> ] <number> ] |
| 956 | number ::= 1*( <digit> ) |
| 957 | digit ::= ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ) |
| 958 | exponential ::= ( 'e' | 'E' ) |
| 959 | sign ::= ( '-' | '+' ) |
| 960 | decimal_point ::= '.' |
| 961 | @endverbatim |
| 962 | */ |
| 963 | /* FIXME: Add EBNF for hex-floats */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 964 | TRIO_STRING_PUBLIC trio_long_double_t |
| 965 | trio_to_long_double |
| 966 | TRIO_ARGS2((source, endp), |
| 967 | TRIO_CONST char *source, |
| 968 | char **endp) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 969 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 970 | #if defined(USE_STRTOLD) |
| 971 | return strtold(source, endp); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 972 | #else |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 973 | int isNegative = FALSE; |
| 974 | int isExponentNegative = FALSE; |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 975 | trio_long_double_t integer = 0.0; |
| 976 | trio_long_double_t fraction = 0.0; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 977 | unsigned long exponent = 0; |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 978 | trio_long_double_t base; |
| 979 | trio_long_double_t fracdiv = 1.0; |
| 980 | trio_long_double_t value = 0.0; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 981 | |
| 982 | /* First try hex-floats */ |
| 983 | if ((source[0] == '0') && ((source[1] == 'x') || (source[1] == 'X'))) |
| 984 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 985 | base = 16.0; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 986 | source += 2; |
| 987 | while (isxdigit((int)*source)) |
| 988 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 989 | integer *= base; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 990 | integer += (isdigit((int)*source) |
| 991 | ? (*source - '0') |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 992 | : 10 + (trio_to_upper((int)*source) - 'A')); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 993 | source++; |
| 994 | } |
| 995 | if (*source == '.') |
| 996 | { |
| 997 | source++; |
| 998 | while (isxdigit((int)*source)) |
| 999 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1000 | fracdiv /= base; |
| 1001 | fraction += fracdiv * (isdigit((int)*source) |
| 1002 | ? (*source - '0') |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1003 | : 10 + (trio_to_upper((int)*source) - 'A')); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1004 | source++; |
| 1005 | } |
| 1006 | if ((*source == 'p') || (*source == 'P')) |
| 1007 | { |
| 1008 | source++; |
| 1009 | if ((*source == '+') || (*source == '-')) |
| 1010 | { |
| 1011 | isExponentNegative = (*source == '-'); |
| 1012 | source++; |
| 1013 | } |
| 1014 | while (isdigit((int)*source)) |
| 1015 | { |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1016 | exponent *= 10; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1017 | exponent += (*source - '0'); |
| 1018 | source++; |
| 1019 | } |
| 1020 | } |
| 1021 | } |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1022 | /* For later use with exponent */ |
| 1023 | base = 2.0; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1024 | } |
| 1025 | else /* Then try normal decimal floats */ |
| 1026 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1027 | base = 10.0; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1028 | isNegative = (*source == '-'); |
| 1029 | /* Skip sign */ |
| 1030 | if ((*source == '+') || (*source == '-')) |
| 1031 | source++; |
| 1032 | |
| 1033 | /* Integer part */ |
| 1034 | while (isdigit((int)*source)) |
| 1035 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1036 | integer *= base; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1037 | integer += (*source - '0'); |
| 1038 | source++; |
| 1039 | } |
| 1040 | |
| 1041 | if (*source == '.') |
| 1042 | { |
| 1043 | source++; /* skip decimal point */ |
| 1044 | while (isdigit((int)*source)) |
| 1045 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1046 | fracdiv /= base; |
| 1047 | fraction += (*source - '0') * fracdiv; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1048 | source++; |
| 1049 | } |
| 1050 | } |
| 1051 | if ((*source == 'e') |
| 1052 | || (*source == 'E') |
| 1053 | #if TRIO_MICROSOFT |
| 1054 | || (*source == 'd') |
| 1055 | || (*source == 'D') |
| 1056 | #endif |
| 1057 | ) |
| 1058 | { |
| 1059 | source++; /* Skip exponential indicator */ |
| 1060 | isExponentNegative = (*source == '-'); |
| 1061 | if ((*source == '+') || (*source == '-')) |
| 1062 | source++; |
| 1063 | while (isdigit((int)*source)) |
| 1064 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1065 | exponent *= (int)base; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1066 | exponent += (*source - '0'); |
| 1067 | source++; |
| 1068 | } |
| 1069 | } |
| 1070 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1071 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1072 | value = integer + fraction; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1073 | if (exponent != 0) |
| 1074 | { |
| 1075 | if (isExponentNegative) |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1076 | value /= pow(base, (double)exponent); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1077 | else |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1078 | value *= pow(base, (double)exponent); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1079 | } |
| 1080 | if (isNegative) |
| 1081 | value = -value; |
| 1082 | |
| 1083 | if (endp) |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1084 | *endp = (char *)source; |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1085 | return value; |
| 1086 | #endif |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | /** |
| 1091 | Convert string to floating-point number. |
| 1092 | |
| 1093 | @param source String to be converted. |
| 1094 | @param endp Pointer to end of the converted string. |
| 1095 | @return A floating-point number. |
| 1096 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1097 | See @ref trio_to_long_double. |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1098 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1099 | TRIO_STRING_PUBLIC double |
| 1100 | trio_to_double |
| 1101 | TRIO_ARGS2((source, endp), |
| 1102 | TRIO_CONST char *source, |
| 1103 | char **endp) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1104 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1105 | #if defined(USE_STRTOD) |
| 1106 | return strtod(source, endp); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1107 | #else |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1108 | return (double)trio_to_long_double(source, endp); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1109 | #endif |
| 1110 | } |
| 1111 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1112 | #if !defined(TRIO_MINIMAL) |
| 1113 | /** |
| 1114 | Convert string to floating-point number. |
| 1115 | |
| 1116 | @param source String to be converted. |
| 1117 | @param endp Pointer to end of the converted string. |
| 1118 | @return A floating-point number. |
| 1119 | |
| 1120 | See @ref trio_to_long_double. |
| 1121 | */ |
| 1122 | TRIO_STRING_PUBLIC float |
| 1123 | trio_to_float |
| 1124 | TRIO_ARGS2((source, endp), |
| 1125 | TRIO_CONST char *source, |
| 1126 | char **endp) |
| 1127 | { |
| 1128 | #if defined(USE_STRTOF) |
| 1129 | return strtof(source, endp); |
| 1130 | #else |
| 1131 | return (float)trio_to_long_double(source, endp); |
| 1132 | #endif |
| 1133 | } |
| 1134 | #endif /* !defined(TRIO_MINIMAL) */ |
| 1135 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1136 | |
| 1137 | /** |
| 1138 | Convert string to signed integer. |
| 1139 | |
| 1140 | @param string String to be converted. |
| 1141 | @param endp Pointer to end of converted string. |
| 1142 | @param base Radix number of number. |
| 1143 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1144 | TRIO_STRING_PUBLIC long |
| 1145 | trio_to_long |
| 1146 | TRIO_ARGS3((string, endp, base), |
| 1147 | TRIO_CONST char *string, |
| 1148 | char **endp, |
| 1149 | int base) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1150 | { |
| 1151 | assert(string); |
| 1152 | assert((base >= 2) && (base <= 36)); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1153 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1154 | return strtol(string, endp, base); |
| 1155 | } |
| 1156 | |
| 1157 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1158 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1159 | /** |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1160 | Convert one alphabetic letter to lower-case. |
| 1161 | |
| 1162 | @param source The letter to be converted. |
| 1163 | @return The converted letter. |
| 1164 | */ |
| 1165 | TRIO_STRING_PUBLIC int |
| 1166 | trio_to_lower |
| 1167 | TRIO_ARGS1((source), |
| 1168 | int source) |
| 1169 | { |
| 1170 | #if defined(USE_TOLOWER) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1171 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1172 | return tolower(source); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1173 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1174 | #else |
| 1175 | |
| 1176 | /* Does not handle locales or non-contiguous alphabetic characters */ |
| 1177 | return ((source >= (int)'A') && (source <= (int)'Z')) |
| 1178 | ? source - 'A' + 'a' |
| 1179 | : source; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1180 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1181 | #endif |
| 1182 | } |
| 1183 | #endif /* !defined(TRIO_MINIMAL) */ |
| 1184 | |
| 1185 | #if !defined(TRIO_MINIMAL) |
| 1186 | /** |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1187 | Convert string to unsigned integer. |
| 1188 | |
| 1189 | @param string String to be converted. |
| 1190 | @param endp Pointer to end of converted string. |
| 1191 | @param base Radix number of number. |
| 1192 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1193 | TRIO_STRING_PUBLIC unsigned long |
| 1194 | trio_to_unsigned_long |
| 1195 | TRIO_ARGS3((string, endp, base), |
| 1196 | TRIO_CONST char *string, |
| 1197 | char **endp, |
| 1198 | int base) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1199 | { |
| 1200 | assert(string); |
| 1201 | assert((base >= 2) && (base <= 36)); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1202 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1203 | return strtoul(string, endp, base); |
| 1204 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1205 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1206 | |
| 1207 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1208 | /** |
| 1209 | Convert one alphabetic letter to upper-case. |
| 1210 | |
| 1211 | @param source The letter to be converted. |
| 1212 | @return The converted letter. |
| 1213 | */ |
| 1214 | TRIO_STRING_PUBLIC int |
| 1215 | trio_to_upper |
| 1216 | TRIO_ARGS1((source), |
| 1217 | int source) |
| 1218 | { |
| 1219 | #if defined(USE_TOUPPER) |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1220 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1221 | return toupper(source); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1222 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1223 | #else |
| 1224 | |
| 1225 | /* Does not handle locales or non-contiguous alphabetic characters */ |
| 1226 | return ((source >= (int)'a') && (source <= (int)'z')) |
| 1227 | ? source - 'a' + 'A' |
| 1228 | : source; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1229 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1230 | #endif |
| 1231 | } |
| 1232 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1233 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1234 | /** |
| 1235 | Convert the alphabetic letters in the string to upper-case. |
| 1236 | |
| 1237 | @param target The string to be converted. |
| 1238 | @return The number of processed characters (converted or not). |
| 1239 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1240 | TRIO_STRING_PUBLIC int |
| 1241 | trio_upper |
| 1242 | TRIO_ARGS1((target), |
| 1243 | char *target) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1244 | { |
| 1245 | assert(target); |
| 1246 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1247 | return trio_span_function(target, target, trio_to_upper); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1248 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1249 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1250 | |
| 1251 | |
| 1252 | /** @} End of StaticStrings */ |
| 1253 | |
| 1254 | |
| 1255 | /************************************************************************* |
| 1256 | * Dynamic String Functions |
| 1257 | */ |
| 1258 | |
| 1259 | #if defined(TRIO_DOCUMENTATION) |
| 1260 | # include "doc/doc_dynamic.h" |
| 1261 | #endif |
| 1262 | /** @addtogroup DynamicStrings |
| 1263 | @{ |
| 1264 | */ |
| 1265 | |
| 1266 | /* |
| 1267 | * TrioStringAlloc |
| 1268 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1269 | TRIO_STRING_PRIVATE trio_string_t * |
| 1270 | TrioStringAlloc(TRIO_NOARGS) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1271 | { |
| 1272 | trio_string_t *self; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1273 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1274 | self = (trio_string_t *)TRIO_MALLOC(sizeof(trio_string_t)); |
| 1275 | if (self) |
| 1276 | { |
| 1277 | self->content = NULL; |
| 1278 | self->length = 0; |
| 1279 | self->allocated = 0; |
| 1280 | } |
| 1281 | return self; |
| 1282 | } |
| 1283 | |
| 1284 | |
| 1285 | /* |
| 1286 | * TrioStringGrow |
| 1287 | * |
| 1288 | * The size of the string will be increased by 'delta' characters. If |
| 1289 | * 'delta' is zero, the size will be doubled. |
| 1290 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1291 | TRIO_STRING_PRIVATE BOOLEAN_T |
| 1292 | TrioStringGrow |
| 1293 | TRIO_ARGS2((self, delta), |
| 1294 | trio_string_t *self, |
| 1295 | size_t delta) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1296 | { |
| 1297 | BOOLEAN_T status = FALSE; |
| 1298 | char *new_content; |
| 1299 | size_t new_size; |
| 1300 | |
| 1301 | new_size = (delta == 0) |
| 1302 | ? ( (self->allocated == 0) ? 1 : self->allocated * 2 ) |
| 1303 | : self->allocated + delta; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1304 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1305 | new_content = (char *)TRIO_REALLOC(self->content, new_size); |
| 1306 | if (new_content) |
| 1307 | { |
| 1308 | self->content = new_content; |
| 1309 | self->allocated = new_size; |
| 1310 | status = TRUE; |
| 1311 | } |
| 1312 | return status; |
| 1313 | } |
| 1314 | |
| 1315 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1316 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1317 | /* |
| 1318 | * TrioStringGrowTo |
| 1319 | * |
| 1320 | * The size of the string will be increased to 'length' plus one characters. |
| 1321 | * If 'length' is less than the original size, the original size will be |
| 1322 | * used (that is, the size of the string is never decreased). |
| 1323 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1324 | TRIO_STRING_PRIVATE BOOLEAN_T |
| 1325 | TrioStringGrowTo |
| 1326 | TRIO_ARGS2((self, length), |
| 1327 | trio_string_t *self, |
| 1328 | size_t length) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1329 | { |
| 1330 | length++; /* Room for terminating zero */ |
| 1331 | return (self->allocated < length) |
| 1332 | ? TrioStringGrow(self, length - self->allocated) |
| 1333 | : TRUE; |
| 1334 | } |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 1335 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1336 | |
| 1337 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1338 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1339 | /** |
| 1340 | Create a new dynamic string. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1341 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1342 | @param initial_size Initial size of the buffer. |
| 1343 | @return Newly allocated dynamic string, or NULL if memory allocation failed. |
| 1344 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1345 | TRIO_STRING_PUBLIC trio_string_t * |
| 1346 | trio_string_create |
| 1347 | TRIO_ARGS1((initial_size), |
| 1348 | int initial_size) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1349 | { |
| 1350 | trio_string_t *self; |
| 1351 | |
| 1352 | self = TrioStringAlloc(); |
| 1353 | if (self) |
| 1354 | { |
| 1355 | if (TrioStringGrow(self, |
| 1356 | (size_t)((initial_size > 0) ? initial_size : 1))) |
| 1357 | { |
| 1358 | self->content[0] = (char)0; |
| 1359 | self->allocated = initial_size; |
| 1360 | } |
| 1361 | else |
| 1362 | { |
| 1363 | trio_string_destroy(self); |
| 1364 | self = NULL; |
| 1365 | } |
| 1366 | } |
| 1367 | return self; |
| 1368 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1369 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1370 | |
| 1371 | |
| 1372 | /** |
| 1373 | Deallocate the dynamic string and its contents. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1374 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1375 | @param self Dynamic string |
| 1376 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1377 | TRIO_STRING_PUBLIC void |
| 1378 | trio_string_destroy |
| 1379 | TRIO_ARGS1((self), |
| 1380 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1381 | { |
| 1382 | assert(self); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1383 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1384 | if (self) |
| 1385 | { |
| 1386 | trio_destroy(self->content); |
| 1387 | TRIO_FREE(self); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1392 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1393 | /** |
| 1394 | Get a pointer to the content. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1395 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1396 | @param self Dynamic string. |
| 1397 | @param offset Offset into content. |
| 1398 | @return Pointer to the content. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1399 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1400 | @p Offset can be zero, positive, or negative. If @p offset is zero, |
| 1401 | then the start of the content will be returned. If @p offset is positive, |
| 1402 | then a pointer to @p offset number of characters from the beginning of the |
| 1403 | content is returned. If @p offset is negative, then a pointer to @p offset |
| 1404 | number of characters from the ending of the string, starting at the |
| 1405 | terminating zero, is returned. |
| 1406 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1407 | TRIO_STRING_PUBLIC char * |
| 1408 | trio_string_get |
| 1409 | TRIO_ARGS2((self, offset), |
| 1410 | trio_string_t *self, |
| 1411 | int offset) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1412 | { |
| 1413 | char *result = NULL; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1414 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1415 | assert(self); |
| 1416 | |
| 1417 | if (self->content != NULL) |
| 1418 | { |
| 1419 | if (self->length == 0) |
| 1420 | { |
| 1421 | (void)trio_string_length(self); |
| 1422 | } |
| 1423 | if (offset >= 0) |
| 1424 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1425 | if (offset > (int)self->length) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1426 | { |
| 1427 | offset = self->length; |
| 1428 | } |
| 1429 | } |
| 1430 | else |
| 1431 | { |
| 1432 | offset += self->length + 1; |
| 1433 | if (offset < 0) |
| 1434 | { |
| 1435 | offset = 0; |
| 1436 | } |
| 1437 | } |
| 1438 | result = &(self->content[offset]); |
| 1439 | } |
| 1440 | return result; |
| 1441 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1442 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1443 | |
| 1444 | |
| 1445 | /** |
| 1446 | Extract the content. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1447 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1448 | @param self Dynamic String |
| 1449 | @return Content of dynamic string. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1450 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1451 | The content is removed from the dynamic string. This enables destruction |
| 1452 | of the dynamic string without deallocation of the content. |
| 1453 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1454 | TRIO_STRING_PUBLIC char * |
| 1455 | trio_string_extract |
| 1456 | TRIO_ARGS1((self), |
| 1457 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1458 | { |
| 1459 | char *result; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1460 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1461 | assert(self); |
| 1462 | |
| 1463 | result = self->content; |
| 1464 | /* FIXME: Allocate new empty buffer? */ |
| 1465 | self->content = NULL; |
| 1466 | self->length = self->allocated = 0; |
| 1467 | return result; |
| 1468 | } |
| 1469 | |
| 1470 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1471 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1472 | /** |
| 1473 | Set the content of the dynamic string. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1474 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1475 | @param self Dynamic String |
| 1476 | @param buffer The new content. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1477 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1478 | Sets the content of the dynamic string to a copy @p buffer. |
| 1479 | An existing content will be deallocated first, if necessary. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1480 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1481 | @remark |
| 1482 | This function will make a copy of @p buffer. |
| 1483 | You are responsible for deallocating @p buffer yourself. |
| 1484 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1485 | TRIO_STRING_PUBLIC void |
| 1486 | trio_xstring_set |
| 1487 | TRIO_ARGS2((self, buffer), |
| 1488 | trio_string_t *self, |
| 1489 | char *buffer) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1490 | { |
| 1491 | assert(self); |
| 1492 | |
| 1493 | trio_destroy(self->content); |
| 1494 | self->content = trio_duplicate(buffer); |
| 1495 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1496 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1497 | |
| 1498 | |
| 1499 | /* |
| 1500 | * trio_string_size |
| 1501 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1502 | TRIO_STRING_PUBLIC int |
| 1503 | trio_string_size |
| 1504 | TRIO_ARGS1((self), |
| 1505 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1506 | { |
| 1507 | assert(self); |
| 1508 | |
| 1509 | return self->allocated; |
| 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | /* |
| 1514 | * trio_string_terminate |
| 1515 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1516 | TRIO_STRING_PUBLIC void |
| 1517 | trio_string_terminate |
| 1518 | TRIO_ARGS1((self), |
| 1519 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1520 | { |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1521 | trio_xstring_append_char(self, 0); |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1525 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1526 | /** |
| 1527 | Append the second string to the first. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1528 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1529 | @param self Dynamic string to be modified. |
| 1530 | @param other Dynamic string to copy from. |
| 1531 | @return Boolean value indicating success or failure. |
| 1532 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1533 | TRIO_STRING_PUBLIC int |
| 1534 | trio_string_append |
| 1535 | TRIO_ARGS2((self, other), |
| 1536 | trio_string_t *self, |
| 1537 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1538 | { |
| 1539 | size_t length; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1540 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1541 | assert(self); |
| 1542 | assert(other); |
| 1543 | |
| 1544 | length = self->length + other->length; |
| 1545 | if (!TrioStringGrowTo(self, length)) |
| 1546 | goto error; |
| 1547 | trio_copy(&self->content[self->length], other->content); |
| 1548 | self->length = length; |
| 1549 | return TRUE; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1550 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1551 | error: |
| 1552 | return FALSE; |
| 1553 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1554 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1555 | |
| 1556 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1557 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1558 | /* |
| 1559 | * trio_xstring_append |
| 1560 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1561 | TRIO_STRING_PUBLIC int |
| 1562 | trio_xstring_append |
| 1563 | TRIO_ARGS2((self, other), |
| 1564 | trio_string_t *self, |
| 1565 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1566 | { |
| 1567 | size_t length; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1568 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1569 | assert(self); |
| 1570 | assert(other); |
| 1571 | |
| 1572 | length = self->length + trio_length(other); |
| 1573 | if (!TrioStringGrowTo(self, length)) |
| 1574 | goto error; |
| 1575 | trio_copy(&self->content[self->length], other); |
| 1576 | self->length = length; |
| 1577 | return TRUE; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1578 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1579 | error: |
| 1580 | return FALSE; |
| 1581 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1582 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1583 | |
| 1584 | |
| 1585 | /* |
| 1586 | * trio_xstring_append_char |
| 1587 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1588 | TRIO_STRING_PUBLIC int |
| 1589 | trio_xstring_append_char |
| 1590 | TRIO_ARGS2((self, character), |
| 1591 | trio_string_t *self, |
| 1592 | char character) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1593 | { |
| 1594 | assert(self); |
| 1595 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1596 | if ((int)self->length >= trio_string_size(self)) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1597 | { |
| 1598 | if (!TrioStringGrow(self, 0)) |
| 1599 | goto error; |
| 1600 | } |
| 1601 | self->content[self->length] = character; |
| 1602 | self->length++; |
| 1603 | return TRUE; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1604 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1605 | error: |
| 1606 | return FALSE; |
| 1607 | } |
| 1608 | |
| 1609 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1610 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1611 | /** |
| 1612 | Search for the first occurrence of second parameter in the first. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1613 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1614 | @param self Dynamic string to be modified. |
| 1615 | @param other Dynamic string to copy from. |
| 1616 | @return Boolean value indicating success or failure. |
| 1617 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1618 | TRIO_STRING_PUBLIC int |
| 1619 | trio_string_contains |
| 1620 | TRIO_ARGS2((self, other), |
| 1621 | trio_string_t *self, |
| 1622 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1623 | { |
| 1624 | assert(self); |
| 1625 | assert(other); |
| 1626 | |
| 1627 | return trio_contains(self->content, other->content); |
| 1628 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1629 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1630 | |
| 1631 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1632 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1633 | /* |
| 1634 | * trio_xstring_contains |
| 1635 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1636 | TRIO_STRING_PUBLIC int |
| 1637 | trio_xstring_contains |
| 1638 | TRIO_ARGS2((self, other), |
| 1639 | trio_string_t *self, |
| 1640 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1641 | { |
| 1642 | assert(self); |
| 1643 | assert(other); |
| 1644 | |
| 1645 | return trio_contains(self->content, other); |
| 1646 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1647 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1648 | |
| 1649 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1650 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1651 | /* |
| 1652 | * trio_string_copy |
| 1653 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1654 | TRIO_STRING_PUBLIC int |
| 1655 | trio_string_copy |
| 1656 | TRIO_ARGS2((self, other), |
| 1657 | trio_string_t *self, |
| 1658 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1659 | { |
| 1660 | assert(self); |
| 1661 | assert(other); |
| 1662 | |
| 1663 | self->length = 0; |
| 1664 | return trio_string_append(self, other); |
| 1665 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1666 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1667 | |
| 1668 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1669 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1670 | /* |
| 1671 | * trio_xstring_copy |
| 1672 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1673 | TRIO_STRING_PUBLIC int |
| 1674 | trio_xstring_copy |
| 1675 | TRIO_ARGS2((self, other), |
| 1676 | trio_string_t *self, |
| 1677 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1678 | { |
| 1679 | assert(self); |
| 1680 | assert(other); |
| 1681 | |
| 1682 | self->length = 0; |
| 1683 | return trio_xstring_append(self, other); |
| 1684 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1685 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1686 | |
| 1687 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1688 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1689 | /* |
| 1690 | * trio_string_duplicate |
| 1691 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1692 | TRIO_STRING_PUBLIC trio_string_t * |
| 1693 | trio_string_duplicate |
| 1694 | TRIO_ARGS1((other), |
| 1695 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1696 | { |
| 1697 | trio_string_t *self; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1698 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1699 | assert(other); |
| 1700 | |
| 1701 | self = TrioStringAlloc(); |
| 1702 | if (self) |
| 1703 | { |
| 1704 | self->content = TrioDuplicateMax(other->content, other->length); |
| 1705 | if (self->content) |
| 1706 | { |
| 1707 | self->length = other->length; |
| 1708 | self->allocated = self->length + 1; |
| 1709 | } |
| 1710 | else |
| 1711 | { |
| 1712 | self->length = self->allocated = 0; |
| 1713 | } |
| 1714 | } |
| 1715 | return self; |
| 1716 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1717 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1718 | |
| 1719 | |
| 1720 | /* |
| 1721 | * trio_xstring_duplicate |
| 1722 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1723 | TRIO_STRING_PUBLIC trio_string_t * |
| 1724 | trio_xstring_duplicate |
| 1725 | TRIO_ARGS1((other), |
| 1726 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1727 | { |
| 1728 | trio_string_t *self; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1729 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1730 | assert(other); |
| 1731 | |
| 1732 | self = TrioStringAlloc(); |
| 1733 | if (self) |
| 1734 | { |
| 1735 | self->content = TrioDuplicateMax(other, trio_length(other)); |
| 1736 | if (self->content) |
| 1737 | { |
| 1738 | self->length = trio_length(self->content); |
| 1739 | self->allocated = self->length + 1; |
| 1740 | } |
| 1741 | else |
| 1742 | { |
| 1743 | self->length = self->allocated = 0; |
| 1744 | } |
| 1745 | } |
| 1746 | return self; |
| 1747 | } |
| 1748 | |
| 1749 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1750 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1751 | /* |
| 1752 | * trio_string_equal |
| 1753 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1754 | TRIO_STRING_PUBLIC int |
| 1755 | trio_string_equal |
| 1756 | TRIO_ARGS2((self, other), |
| 1757 | trio_string_t *self, |
| 1758 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1759 | { |
| 1760 | assert(self); |
| 1761 | assert(other); |
| 1762 | |
| 1763 | return trio_equal(self->content, other->content); |
| 1764 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1765 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1766 | |
| 1767 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1768 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1769 | /* |
| 1770 | * trio_xstring_equal |
| 1771 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1772 | TRIO_STRING_PUBLIC int |
| 1773 | trio_xstring_equal |
| 1774 | TRIO_ARGS2((self, other), |
| 1775 | trio_string_t *self, |
| 1776 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1777 | { |
| 1778 | assert(self); |
| 1779 | assert(other); |
| 1780 | |
| 1781 | return trio_equal(self->content, other); |
| 1782 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1783 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1784 | |
| 1785 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1786 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1787 | /* |
| 1788 | * trio_string_equal_max |
| 1789 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1790 | TRIO_STRING_PUBLIC int |
| 1791 | trio_string_equal_max |
| 1792 | TRIO_ARGS3((self, max, other), |
| 1793 | trio_string_t *self, |
| 1794 | size_t max, |
| 1795 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1796 | { |
| 1797 | assert(self); |
| 1798 | assert(other); |
| 1799 | |
| 1800 | return trio_equal_max(self->content, max, other->content); |
| 1801 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1802 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1803 | |
| 1804 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1805 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1806 | /* |
| 1807 | * trio_xstring_equal_max |
| 1808 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1809 | TRIO_STRING_PUBLIC int |
| 1810 | trio_xstring_equal_max |
| 1811 | TRIO_ARGS3((self, max, other), |
| 1812 | trio_string_t *self, |
| 1813 | size_t max, |
| 1814 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1815 | { |
| 1816 | assert(self); |
| 1817 | assert(other); |
| 1818 | |
| 1819 | return trio_equal_max(self->content, max, other); |
| 1820 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1821 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1822 | |
| 1823 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1824 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1825 | /* |
| 1826 | * trio_string_equal_case |
| 1827 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1828 | TRIO_STRING_PUBLIC int |
| 1829 | trio_string_equal_case |
| 1830 | TRIO_ARGS2((self, other), |
| 1831 | trio_string_t *self, |
| 1832 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1833 | { |
| 1834 | assert(self); |
| 1835 | assert(other); |
| 1836 | |
| 1837 | return trio_equal_case(self->content, other->content); |
| 1838 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1839 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1840 | |
| 1841 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1842 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1843 | /* |
| 1844 | * trio_xstring_equal_case |
| 1845 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1846 | TRIO_STRING_PUBLIC int |
| 1847 | trio_xstring_equal_case |
| 1848 | TRIO_ARGS2((self, other), |
| 1849 | trio_string_t *self, |
| 1850 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1851 | { |
| 1852 | assert(self); |
| 1853 | assert(other); |
| 1854 | |
| 1855 | return trio_equal_case(self->content, other); |
| 1856 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1857 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1858 | |
| 1859 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1860 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1861 | /* |
| 1862 | * trio_string_equal_case_max |
| 1863 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1864 | TRIO_STRING_PUBLIC int |
| 1865 | trio_string_equal_case_max |
| 1866 | TRIO_ARGS3((self, max, other), |
| 1867 | trio_string_t *self, |
| 1868 | size_t max, |
| 1869 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1870 | { |
| 1871 | assert(self); |
| 1872 | assert(other); |
| 1873 | |
| 1874 | return trio_equal_case_max(self->content, max, other->content); |
| 1875 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1876 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1877 | |
| 1878 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1879 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1880 | /* |
| 1881 | * trio_xstring_equal_case_max |
| 1882 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1883 | TRIO_STRING_PUBLIC int |
| 1884 | trio_xstring_equal_case_max |
| 1885 | TRIO_ARGS3((self, max, other), |
| 1886 | trio_string_t *self, |
| 1887 | size_t max, |
| 1888 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1889 | { |
| 1890 | assert(self); |
| 1891 | assert(other); |
| 1892 | |
| 1893 | return trio_equal_case_max(self->content, max, other); |
| 1894 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1895 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1896 | |
| 1897 | |
Daniel Veillard | 59d3ed8 | 2007-04-17 12:44:58 +0000 | [diff] [blame] | 1898 | #if !defined(TRIO_MINIMAL) && !defined(_WIN32_WCE) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1899 | /* |
| 1900 | * trio_string_format_data_max |
| 1901 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1902 | TRIO_STRING_PUBLIC size_t |
| 1903 | trio_string_format_date_max |
| 1904 | TRIO_ARGS4((self, max, format, datetime), |
| 1905 | trio_string_t *self, |
| 1906 | size_t max, |
| 1907 | TRIO_CONST char *format, |
| 1908 | TRIO_CONST struct tm *datetime) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1909 | { |
| 1910 | assert(self); |
| 1911 | |
| 1912 | return trio_format_date_max(self->content, max, format, datetime); |
| 1913 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1914 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1915 | |
| 1916 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1917 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1918 | /* |
| 1919 | * trio_string_index |
| 1920 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1921 | TRIO_STRING_PUBLIC char * |
| 1922 | trio_string_index |
| 1923 | TRIO_ARGS2((self, character), |
| 1924 | trio_string_t *self, |
| 1925 | int character) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1926 | { |
| 1927 | assert(self); |
| 1928 | |
| 1929 | return trio_index(self->content, character); |
| 1930 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1931 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1932 | |
| 1933 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1934 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1935 | /* |
| 1936 | * trio_string_index_last |
| 1937 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1938 | TRIO_STRING_PUBLIC char * |
| 1939 | trio_string_index_last |
| 1940 | TRIO_ARGS2((self, character), |
| 1941 | trio_string_t *self, |
| 1942 | int character) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1943 | { |
| 1944 | assert(self); |
| 1945 | |
| 1946 | return trio_index_last(self->content, character); |
| 1947 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1948 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1949 | |
| 1950 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1951 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1952 | /* |
| 1953 | * trio_string_length |
| 1954 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1955 | TRIO_STRING_PUBLIC int |
| 1956 | trio_string_length |
| 1957 | TRIO_ARGS1((self), |
| 1958 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1959 | { |
| 1960 | assert(self); |
| 1961 | |
| 1962 | if (self->length == 0) |
| 1963 | { |
| 1964 | self->length = trio_length(self->content); |
| 1965 | } |
| 1966 | return self->length; |
| 1967 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1968 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1969 | |
| 1970 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1971 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1972 | /* |
| 1973 | * trio_string_lower |
| 1974 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1975 | TRIO_STRING_PUBLIC int |
| 1976 | trio_string_lower |
| 1977 | TRIO_ARGS1((self), |
| 1978 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1979 | { |
| 1980 | assert(self); |
| 1981 | |
| 1982 | return trio_lower(self->content); |
| 1983 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1984 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1985 | |
| 1986 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1987 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1988 | /* |
| 1989 | * trio_string_match |
| 1990 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 1991 | TRIO_STRING_PUBLIC int |
| 1992 | trio_string_match |
| 1993 | TRIO_ARGS2((self, other), |
| 1994 | trio_string_t *self, |
| 1995 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 1996 | { |
| 1997 | assert(self); |
| 1998 | assert(other); |
| 1999 | |
| 2000 | return trio_match(self->content, other->content); |
| 2001 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2002 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2003 | |
| 2004 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2005 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2006 | /* |
| 2007 | * trio_xstring_match |
| 2008 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2009 | TRIO_STRING_PUBLIC int |
| 2010 | trio_xstring_match |
| 2011 | TRIO_ARGS2((self, other), |
| 2012 | trio_string_t *self, |
| 2013 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2014 | { |
| 2015 | assert(self); |
| 2016 | assert(other); |
| 2017 | |
| 2018 | return trio_match(self->content, other); |
| 2019 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2020 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2021 | |
| 2022 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2023 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2024 | /* |
| 2025 | * trio_string_match_case |
| 2026 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2027 | TRIO_STRING_PUBLIC int |
| 2028 | trio_string_match_case |
| 2029 | TRIO_ARGS2((self, other), |
| 2030 | trio_string_t *self, |
| 2031 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2032 | { |
| 2033 | assert(self); |
| 2034 | assert(other); |
| 2035 | |
| 2036 | return trio_match_case(self->content, other->content); |
| 2037 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2038 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2039 | |
| 2040 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2041 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2042 | /* |
| 2043 | * trio_xstring_match_case |
| 2044 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2045 | TRIO_STRING_PUBLIC int |
| 2046 | trio_xstring_match_case |
| 2047 | TRIO_ARGS2((self, other), |
| 2048 | trio_string_t *self, |
| 2049 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2050 | { |
| 2051 | assert(self); |
| 2052 | assert(other); |
| 2053 | |
| 2054 | return trio_match_case(self->content, other); |
| 2055 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2056 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2057 | |
| 2058 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2059 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2060 | /* |
| 2061 | * trio_string_substring |
| 2062 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2063 | TRIO_STRING_PUBLIC char * |
| 2064 | trio_string_substring |
| 2065 | TRIO_ARGS2((self, other), |
| 2066 | trio_string_t *self, |
| 2067 | trio_string_t *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2068 | { |
| 2069 | assert(self); |
| 2070 | assert(other); |
| 2071 | |
| 2072 | return trio_substring(self->content, other->content); |
| 2073 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2074 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2075 | |
| 2076 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2077 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2078 | /* |
| 2079 | * trio_xstring_substring |
| 2080 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2081 | TRIO_STRING_PUBLIC char * |
| 2082 | trio_xstring_substring |
| 2083 | TRIO_ARGS2((self, other), |
| 2084 | trio_string_t *self, |
| 2085 | TRIO_CONST char *other) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2086 | { |
| 2087 | assert(self); |
| 2088 | assert(other); |
| 2089 | |
| 2090 | return trio_substring(self->content, other); |
| 2091 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2092 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2093 | |
| 2094 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2095 | #if !defined(TRIO_MINIMAL) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2096 | /* |
| 2097 | * trio_string_upper |
| 2098 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2099 | TRIO_STRING_PUBLIC int |
| 2100 | trio_string_upper |
| 2101 | TRIO_ARGS1((self), |
| 2102 | trio_string_t *self) |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2103 | { |
| 2104 | assert(self); |
| 2105 | |
| 2106 | return trio_upper(self->content); |
| 2107 | } |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 2108 | #endif /* !defined(TRIO_MINIMAL) */ |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 2109 | |
| 2110 | /** @} End of DynamicStrings */ |