1 /*************************************************************************
3 * $Id: triostr.h,v 1.18 2010/01/26 13:02:02 breese Exp $
5 * Copyright (C) 2001 Bjorn Reese and Daniel Stenberg.
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.
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.
16 ************************************************************************/
18 #ifndef TRIO_TRIOSTR_H
19 #define TRIO_TRIOSTR_H
22 * Documentation is located in triostr.c
42 #if !defined(TRIO_PUBLIC_STRING)
43 # if !defined(TRIO_PUBLIC)
46 # define TRIO_PUBLIC_STRING TRIO_PUBLIC
49 /*************************************************************************
53 #if defined(TRIO_EMBED_STRING)
56 * The application that triostr is embedded in must define which functions
59 * The following resolves internal dependencies.
62 # if defined(TRIO_FUNC_XSTRING_SET)
63 # if !defined(TRIO_FUNC_DUPLICATE)
64 # define TRIO_FUNC_DUPLICATE
68 # if defined(TRIO_FUNC_DUPLICATE) \
69 || defined(TRIO_FUNC_DUPLICATE_MAX) \
70 || defined(TRIO_FUNC_STRING_DUPLICATE) \
71 || defined(TRIO_FUNC_XSTRING_DUPLICATE)
72 # if !defined(TRIO_FUNC_CREATE)
73 # define TRIO_FUNC_CREATE
75 # if !defined(TRIO_FUNC_COPY_MAX)
76 # define TRIO_FUNC_COPY_MAX
80 # if defined(TRIO_FUNC_STRING_CREATE)
81 # if !defined(TRIO_FUNC_STRING_DESTROY)
82 # define TRIO_FUNC_STRING_DESTROY
86 # if defined(TRIO_FUNC_STRING_DESTROY) \
87 || defined(TRIO_FUNC_XSTRING_SET)
88 # if !defined(TRIO_FUNC_DESTROY)
89 # define TRIO_FUNC_DESTROY
93 # if defined(TRIO_FUNC_EQUAL_LOCALE) \
94 || defined(TRIO_FUNC_STRING_EQUAL) \
95 || defined(TRIO_FUNC_XSTRING_EQUAL)
96 # if !defined(TRIO_FUNC_EQUAL)
97 # define TRIO_FUNC_EQUAL
101 # if defined(TRIO_FUNC_EQUAL_CASE) \
102 || defined(TRIO_FUNC_STRING_EQUAL_CASE) \
103 || defined(TRIO_FUNC_XSTRING_EQUAL_CASE)
104 # if !defined(TRIO_FUNC_EQUAL_CASE)
105 # define TRIO_FUNC_EQUAL_CASE
109 # if defined(TRIO_FUNC_SUBSTRING_MAX) \
110 || defined(TRIO_FUNC_STRING_EQUAL_MAX) \
111 || defined(TRIO_FUNC_XSTRING_EQUAL_MAX)
112 # if !defined(TRIO_FUNC_EQUAL_MAX)
113 # define TRIO_FUNC_EQUAL_MAX
117 # if defined(TRIO_FUNC_TO_DOUBLE) \
118 || defined(TRIO_FUNC_TO_FLOAT)
119 # if !defined(TRIO_FUNC_TO_LONG_DOUBLE)
120 # define TRIO_FUNC_TO_LONG_DOUBLE
124 # if defined(TRIO_FUNC_STRING_TERMINATE)
125 # if !defined(TRIO_FUNC_XSTRING_APPEND_CHAR)
126 # define TRIO_FUNC_XSTRING_APPEND_CHAR
130 # if defined(TRIO_FUNC_XSTRING_APPEND_CHAR)
131 # if !defined(TRIO_FUNC_STRING_SIZE)
132 # define TRIO_FUNC_STRING_SIZE
139 * When triostr is not embedded all functions are defined.
142 # define TRIO_FUNC_APPEND
143 # define TRIO_FUNC_APPEND_MAX
144 # define TRIO_FUNC_CONTAINS
145 # define TRIO_FUNC_COPY
146 # define TRIO_FUNC_COPY_MAX
147 # define TRIO_FUNC_CREATE
148 # define TRIO_FUNC_DESTROY
149 # define TRIO_FUNC_DUPLICATE
150 # define TRIO_FUNC_DUPLICATE_MAX
151 # define TRIO_FUNC_EQUAL
152 # define TRIO_FUNC_EQUAL_CASE
153 # define TRIO_FUNC_EQUAL_CASE_MAX
154 # define TRIO_FUNC_EQUAL_LOCALE
155 # define TRIO_FUNC_EQUAL_MAX
156 # define TRIO_FUNC_ERROR
157 # if !defined(TRIO_PLATFORM_WINCE)
158 # define TRIO_FUNC_FORMAT_DATE_MAX
160 # define TRIO_FUNC_HASH
161 # define TRIO_FUNC_INDEX
162 # define TRIO_FUNC_INDEX_LAST
163 # define TRIO_FUNC_LENGTH
164 # define TRIO_FUNC_LENGTH_MAX
165 # define TRIO_FUNC_LOWER
166 # define TRIO_FUNC_MATCH
167 # define TRIO_FUNC_MATCH_CASE
168 # define TRIO_FUNC_SPAN_FUNCTION
169 # define TRIO_FUNC_SUBSTRING
170 # define TRIO_FUNC_SUBSTRING_MAX
171 # define TRIO_FUNC_TO_DOUBLE
172 # define TRIO_FUNC_TO_FLOAT
173 # define TRIO_FUNC_TO_LONG
174 # define TRIO_FUNC_TO_LONG_DOUBLE
175 # define TRIO_FUNC_TO_LOWER
176 # define TRIO_FUNC_TO_UNSIGNED_LONG
177 # define TRIO_FUNC_TO_UPPER
178 # define TRIO_FUNC_TOKENIZE
179 # define TRIO_FUNC_UPPER
181 # define TRIO_FUNC_STRING_APPEND
182 # define TRIO_FUNC_STRING_CONTAINS
183 # define TRIO_FUNC_STRING_COPY
184 # define TRIO_FUNC_STRING_CREATE
185 # define TRIO_FUNC_STRING_DESTROY
186 # define TRIO_FUNC_STRING_DUPLICATE
187 # define TRIO_FUNC_STRING_EQUAL
188 # define TRIO_FUNC_STRING_EQUAL_CASE
189 # define TRIO_FUNC_STRING_EQUAL_CASE_MAX
190 # define TRIO_FUNC_STRING_EQUAL_MAX
191 # define TRIO_FUNC_STRING_EXTRACT
192 # if !defined(TRIO_PLATFORM_WINCE)
193 # define TRIO_FUNC_STRING_FORMAT_DATE_MAX
195 # define TRIO_FUNC_STRING_GET
196 # define TRIO_FUNC_STRING_INDEX
197 # define TRIO_FUNC_STRING_INDEX_LAST
198 # define TRIO_FUNC_STRING_LENGTH
199 # define TRIO_FUNC_STRING_LOWER
200 # define TRIO_FUNC_STRING_MATCH
201 # define TRIO_FUNC_STRING_MATCH_CASE
202 # define TRIO_FUNC_STRING_SIZE
203 # define TRIO_FUNC_STRING_SUBSTRING
204 # define TRIO_FUNC_STRING_TERMINATE
205 # define TRIO_FUNC_STRING_UPPER
207 # define TRIO_FUNC_XSTRING_APPEND
208 # define TRIO_FUNC_XSTRING_APPEND_CHAR
209 # define TRIO_FUNC_XSTRING_APPEND_MAX
210 # define TRIO_FUNC_XSTRING_CONTAINS
211 # define TRIO_FUNC_XSTRING_COPY
212 # define TRIO_FUNC_XSTRING_DUPLICATE
213 # define TRIO_FUNC_XSTRING_EQUAL
214 # define TRIO_FUNC_XSTRING_EQUAL_CASE
215 # define TRIO_FUNC_XSTRING_EQUAL_CASE_MAX
216 # define TRIO_FUNC_XSTRING_EQUAL_MAX
217 # define TRIO_FUNC_XSTRING_MATCH
218 # define TRIO_FUNC_XSTRING_MATCH_CASE
219 # define TRIO_FUNC_XSTRING_SET
220 # define TRIO_FUNC_XSTRING_SUBSTRING
225 /*************************************************************************
229 #if defined(TRIO_FUNC_APPEND)
230 TRIO_PUBLIC_STRING int
232 TRIO_PROTO((char *target, TRIO_CONST char *source));
235 #if defined(TRIO_FUNC_APPEND_MAX)
236 TRIO_PUBLIC_STRING int
238 TRIO_PROTO((char *target, size_t max, TRIO_CONST char *source));
241 #if defined(TRIO_FUNC_CONTAINS)
242 TRIO_PUBLIC_STRING int
244 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *substring));
247 #if defined(TRIO_FUNC_COPY)
248 TRIO_PUBLIC_STRING int
250 TRIO_PROTO((char *target, TRIO_CONST char *source));
253 #if defined(TRIO_FUNC_COPY_MAX)
254 TRIO_PUBLIC_STRING int
256 TRIO_PROTO((char *target, size_t max, TRIO_CONST char *source));
259 #if defined(TRIO_FUNC_CREATE)
260 TRIO_PUBLIC_STRING char *
262 TRIO_PROTO((size_t size));
265 #if defined(TRIO_FUNC_DESTROY)
266 TRIO_PUBLIC_STRING void
268 TRIO_PROTO((char *string));
271 #if defined(TRIO_FUNC_DUPLICATE)
272 TRIO_PUBLIC_STRING char *
274 TRIO_PROTO((TRIO_CONST char *source));
277 #if defined(TRIO_FUNC_DUPLICATE_MAX)
278 TRIO_PUBLIC_STRING char *
280 TRIO_PROTO((TRIO_CONST char *source, size_t max));
283 #if defined(TRIO_FUNC_EQUAL)
284 TRIO_PUBLIC_STRING int
286 TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second));
289 #if defined(TRIO_FUNC_EQUAL_CASE)
290 TRIO_PUBLIC_STRING int
292 TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second));
295 #if defined(TRIO_FUNC_EQUAL_CASE_MAX)
296 TRIO_PUBLIC_STRING int
298 TRIO_PROTO((TRIO_CONST char *first, size_t max, TRIO_CONST char *second));
301 #if defined(TRIO_FUNC_EQUAL_LOCALE)
302 TRIO_PUBLIC_STRING int
304 TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second));
307 #if defined(TRIO_FUNC_EQUAL_MAX)
308 TRIO_PUBLIC_STRING int
310 TRIO_PROTO((TRIO_CONST char *first, size_t max, TRIO_CONST char *second));
313 #if defined(TRIO_FUNC_ERROR)
314 TRIO_PUBLIC_STRING TRIO_CONST char *
319 #if defined(TRIO_FUNC_FORMAT_DATE_MAX)
320 TRIO_PUBLIC_STRING size_t
322 TRIO_PROTO((char *target, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime));
325 #if defined(TRIO_FUNC_HASH)
326 TRIO_PUBLIC_STRING unsigned long
328 TRIO_PROTO((TRIO_CONST char *string, int type));
331 #if defined(TRIO_FUNC_INDEX)
332 TRIO_PUBLIC_STRING char *
334 TRIO_PROTO((TRIO_CONST char *string, int character));
337 #if defined(TRIO_FUNC_INDEX_LAST)
338 TRIO_PUBLIC_STRING char *
340 TRIO_PROTO((TRIO_CONST char *string, int character));
343 #if defined(TRIO_FUNC_LENGTH)
344 TRIO_PUBLIC_STRING size_t
346 TRIO_PROTO((TRIO_CONST char *string));
349 #if defined(TRIO_FUNC_LENGTH_MAX)
350 TRIO_PUBLIC_STRING size_t
352 TRIO_PROTO((TRIO_CONST char *string, size_t max));
355 #if defined(TRIO_FUNC_LOWER)
356 TRIO_PUBLIC_STRING int
358 TRIO_PROTO((char *target));
361 #if defined(TRIO_FUNC_MATCH)
362 TRIO_PUBLIC_STRING int
364 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *pattern));
367 #if defined(TRIO_FUNC_MATCH_CASE)
368 TRIO_PUBLIC_STRING int
370 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *pattern));
373 #if defined(TRIO_FUNC_SPAN_FUNCTION)
374 TRIO_PUBLIC_STRING size_t
376 TRIO_PROTO((char *target, TRIO_CONST char *source, int (*Function) TRIO_PROTO((int))));
379 #if defined(TRIO_FUNC_SUBSTRING)
380 TRIO_PUBLIC_STRING char *
382 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *substring));
385 #if defined(TRIO_FUNC_SUBSTRING_MAX)
386 TRIO_PUBLIC_STRING char *
388 TRIO_PROTO((TRIO_CONST char *string, size_t max, TRIO_CONST char *substring));
391 #if defined(TRIO_FUNC_TO_DOUBLE)
392 TRIO_PUBLIC_STRING double
394 TRIO_PROTO((TRIO_CONST char *source, char **endp));
397 #if defined(TRIO_FUNC_TO_FLOAT)
398 TRIO_PUBLIC_STRING float
400 TRIO_PROTO((TRIO_CONST char *source, char **endp));
403 #if defined(TRIO_FUNC_TO_LONG)
404 TRIO_PUBLIC_STRING long
406 TRIO_PROTO((TRIO_CONST char *source, char **endp, int base));
409 #if defined(TRIO_FUNC_TO_LOWER)
410 TRIO_PUBLIC_STRING int
412 TRIO_PROTO((int source));
415 #if defined(TRIO_FUNC_TO_LONG_DOUBLE)
416 TRIO_PUBLIC_STRING trio_long_double_t
418 TRIO_PROTO((TRIO_CONST char *source, char **endp));
421 #if defined(TRIO_FUNC_TO_UNSIGNED_LONG)
422 TRIO_PUBLIC_STRING unsigned long
423 trio_to_unsigned_long
424 TRIO_PROTO((TRIO_CONST char *source, char **endp, int base));
427 #if defined(TRIO_FUNC_TO_UPPER)
428 TRIO_PUBLIC_STRING int
430 TRIO_PROTO((int source));
433 #if defined(TRIO_FUNC_TOKENIZE)
434 TRIO_PUBLIC_STRING char *
436 TRIO_PROTO((char *string, TRIO_CONST char *delimiters));
439 #if defined(TRIO_FUNC_UPPER)
440 TRIO_PUBLIC_STRING int
442 TRIO_PROTO((char *target));
445 /*************************************************************************
446 * Dynamic string functions
450 * Opaque type for dynamic strings
453 typedef struct _trio_string_t trio_string_t;
455 #if defined(TRIO_FUNC_STRING_APPEND)
456 TRIO_PUBLIC_STRING int
458 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
461 #if defined(TRIO_FUNC_STRING_CONTAINS)
462 TRIO_PUBLIC_STRING int
464 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
467 #if defined(TRIO_FUNC_STRING_COPY)
468 TRIO_PUBLIC_STRING int
470 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
473 #if defined(TRIO_FUNC_STRING_CREATE)
474 TRIO_PUBLIC_STRING trio_string_t *
476 TRIO_PROTO((int initial_size));
479 #if defined(TRIO_FUNC_STRING_DESTROY)
480 TRIO_PUBLIC_STRING void
482 TRIO_PROTO((trio_string_t *self));
485 #if defined(TRIO_FUNC_STRING_DUPLICATE)
486 TRIO_PUBLIC_STRING trio_string_t *
487 trio_string_duplicate
488 TRIO_PROTO((trio_string_t *other));
491 #if defined(TRIO_FUNC_STRING_EQUAL)
492 TRIO_PUBLIC_STRING int
494 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
497 #if defined(TRIO_FUNC_STRING_EQUAL_MAX)
498 TRIO_PUBLIC_STRING int
499 trio_string_equal_max
500 TRIO_PROTO((trio_string_t *self, size_t max, trio_string_t *second));
503 #if defined(TRIO_FUNC_STRING_EQUAL_CASE)
504 TRIO_PUBLIC_STRING int
505 trio_string_equal_case
506 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
509 #if defined(TRIO_FUNC_STRING_EQUAL_CASE_MAX)
510 TRIO_PUBLIC_STRING int
511 trio_string_equal_case_max
512 TRIO_PROTO((trio_string_t *self, size_t max, trio_string_t *other));
515 #if defined(TRIO_FUNC_STRING_EXTRACT)
516 TRIO_PUBLIC_STRING char *
518 TRIO_PROTO((trio_string_t *self));
521 #if defined(TRIO_FUNC_STRING_FORMAT_DATE_MAX)
522 TRIO_PUBLIC_STRING size_t
523 trio_string_format_date_max
524 TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime));
527 #if defined(TRIO_FUNC_STRING_GET)
528 TRIO_PUBLIC_STRING char *
530 TRIO_PROTO((trio_string_t *self, int offset));
533 #if defined(TRIO_FUNC_STRING_INDEX)
534 TRIO_PUBLIC_STRING char *
536 TRIO_PROTO((trio_string_t *self, int character));
539 #if defined(TRIO_FUNC_STRING_INDEX_LAST)
540 TRIO_PUBLIC_STRING char *
541 trio_string_index_last
542 TRIO_PROTO((trio_string_t *self, int character));
545 #if defined(TRIO_FUNC_STRING_LENGTH)
546 TRIO_PUBLIC_STRING int
548 TRIO_PROTO((trio_string_t *self));
551 #if defined(TRIO_FUNC_STRING_LOWER)
552 TRIO_PUBLIC_STRING int
554 TRIO_PROTO((trio_string_t *self));
557 #if defined(TRIO_FUNC_STRING_MATCH)
558 TRIO_PUBLIC_STRING int
560 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
563 #if defined(TRIO_FUNC_STRING_MATCH_CASE)
564 TRIO_PUBLIC_STRING int
565 trio_string_match_case
566 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
569 #if defined(TRIO_FUNC_STRING_SIZE)
570 TRIO_PUBLIC_STRING int
572 TRIO_PROTO((trio_string_t *self));
575 #if defined(TRIO_FUNC_STRING_SUBSTRING)
576 TRIO_PUBLIC_STRING char *
577 trio_string_substring
578 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
581 #if defined(TRIO_FUNC_STRING_TERMINATE)
582 TRIO_PUBLIC_STRING void
583 trio_string_terminate
584 TRIO_PROTO((trio_string_t *self));
587 #if defined(TRIO_FUNC_STRING_UPPER)
588 TRIO_PUBLIC_STRING int
590 TRIO_PROTO((trio_string_t *self));
593 #if defined(TRIO_FUNC_XSTRING_APPEND)
594 TRIO_PUBLIC_STRING int
596 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
599 #if defined(TRIO_FUNC_XSTRING_APPEND_CHAR)
600 TRIO_PUBLIC_STRING int
601 trio_xstring_append_char
602 TRIO_PROTO((trio_string_t *self, char character));
605 #if defined(TRIO_FUNC_XSTRING_APPEND_MAX)
606 TRIO_PUBLIC_STRING int
607 trio_xstring_append_max
608 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other, size_t max));
611 #if defined(TRIO_FUNC_XSTRING_CONTAINS)
612 TRIO_PUBLIC_STRING int
613 trio_xstring_contains
614 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
617 #if defined(TRIO_FUNC_XSTRING_COPY)
618 TRIO_PUBLIC_STRING int
620 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
623 #if defined(TRIO_FUNC_XSTRING_DUPLICATE)
624 TRIO_PUBLIC_STRING trio_string_t *
625 trio_xstring_duplicate
626 TRIO_PROTO((TRIO_CONST char *other));
629 #if defined(TRIO_FUNC_XSTRING_EQUAL)
630 TRIO_PUBLIC_STRING int
632 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
635 #if defined(TRIO_FUNC_XSTRING_EQUAL_MAX)
636 TRIO_PUBLIC_STRING int
637 trio_xstring_equal_max
638 TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *other));
641 #if defined(TRIO_FUNC_XSTRING_EQUAL_CASE)
642 TRIO_PUBLIC_STRING int
643 trio_xstring_equal_case
644 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
647 #if defined(TRIO_FUNC_XSTRING_EQUAL_CASE_MAX)
648 TRIO_PUBLIC_STRING int
649 trio_xstring_equal_case_max
650 TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *other));
653 #if defined(TRIO_FUNC_XSTRING_MATCH)
654 TRIO_PUBLIC_STRING int
656 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
659 #if defined(TRIO_FUNC_XSTRING_MATCH_CASE)
660 TRIO_PUBLIC_STRING int
661 trio_xstring_match_case
662 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
665 #if defined(TRIO_FUNC_XSTRING_SET)
666 TRIO_PUBLIC_STRING void
668 TRIO_PROTO((trio_string_t *self, char *buffer));
671 #if defined(TRIO_FUNC_XSTRING_SUBSTRING)
672 TRIO_PUBLIC_STRING char *
673 trio_xstring_substring
674 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
681 #endif /* TRIO_TRIOSTR_H */