1 /*************************************************************************
3 * $Id: triostr.h,v 1.17 2007/11/11 13:21:49 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_CONTAINS
210 # define TRIO_FUNC_XSTRING_COPY
211 # define TRIO_FUNC_XSTRING_DUPLICATE
212 # define TRIO_FUNC_XSTRING_EQUAL
213 # define TRIO_FUNC_XSTRING_EQUAL_CASE
214 # define TRIO_FUNC_XSTRING_EQUAL_CASE_MAX
215 # define TRIO_FUNC_XSTRING_EQUAL_MAX
216 # define TRIO_FUNC_XSTRING_MATCH
217 # define TRIO_FUNC_XSTRING_MATCH_CASE
218 # define TRIO_FUNC_XSTRING_SET
219 # define TRIO_FUNC_XSTRING_SUBSTRING
224 /*************************************************************************
228 #if defined(TRIO_FUNC_APPEND)
229 TRIO_PUBLIC_STRING int
231 TRIO_PROTO((char *target, TRIO_CONST char *source));
234 #if defined(TRIO_FUNC_APPEND_MAX)
235 TRIO_PUBLIC_STRING int
237 TRIO_PROTO((char *target, size_t max, TRIO_CONST char *source));
240 #if defined(TRIO_FUNC_CONTAINS)
241 TRIO_PUBLIC_STRING int
243 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *substring));
246 #if defined(TRIO_FUNC_COPY)
247 TRIO_PUBLIC_STRING int
249 TRIO_PROTO((char *target, TRIO_CONST char *source));
252 #if defined(TRIO_FUNC_COPY_MAX)
253 TRIO_PUBLIC_STRING int
255 TRIO_PROTO((char *target, size_t max, TRIO_CONST char *source));
258 #if defined(TRIO_FUNC_CREATE)
259 TRIO_PUBLIC_STRING char *
261 TRIO_PROTO((size_t size));
264 #if defined(TRIO_FUNC_DESTROY)
265 TRIO_PUBLIC_STRING void
267 TRIO_PROTO((char *string));
270 #if defined(TRIO_FUNC_DUPLICATE)
271 TRIO_PUBLIC_STRING char *
273 TRIO_PROTO((TRIO_CONST char *source));
276 #if defined(TRIO_FUNC_DUPLICATE_MAX)
277 TRIO_PUBLIC_STRING char *
279 TRIO_PROTO((TRIO_CONST char *source, size_t max));
282 #if defined(TRIO_FUNC_EQUAL)
283 TRIO_PUBLIC_STRING int
285 TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second));
288 #if defined(TRIO_FUNC_EQUAL_CASE)
289 TRIO_PUBLIC_STRING int
291 TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second));
294 #if defined(TRIO_FUNC_EQUAL_CASE_MAX)
295 TRIO_PUBLIC_STRING int
297 TRIO_PROTO((TRIO_CONST char *first, size_t max, TRIO_CONST char *second));
300 #if defined(TRIO_FUNC_EQUAL_LOCALE)
301 TRIO_PUBLIC_STRING int
303 TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second));
306 #if defined(TRIO_FUNC_EQUAL_MAX)
307 TRIO_PUBLIC_STRING int
309 TRIO_PROTO((TRIO_CONST char *first, size_t max, TRIO_CONST char *second));
312 #if defined(TRIO_FUNC_ERROR)
313 TRIO_PUBLIC_STRING TRIO_CONST char *
318 #if defined(TRIO_FUNC_FORMAT_DATE_MAX)
319 TRIO_PUBLIC_STRING size_t
321 TRIO_PROTO((char *target, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime));
324 #if defined(TRIO_FUNC_HASH)
325 TRIO_PUBLIC_STRING unsigned long
327 TRIO_PROTO((TRIO_CONST char *string, int type));
330 #if defined(TRIO_FUNC_INDEX)
331 TRIO_PUBLIC_STRING char *
333 TRIO_PROTO((TRIO_CONST char *string, int character));
336 #if defined(TRIO_FUNC_INDEX_LAST)
337 TRIO_PUBLIC_STRING char *
339 TRIO_PROTO((TRIO_CONST char *string, int character));
342 #if defined(TRIO_FUNC_LENGTH)
343 TRIO_PUBLIC_STRING size_t
345 TRIO_PROTO((TRIO_CONST char *string));
348 #if defined(TRIO_FUNC_LENGTH_MAX)
349 TRIO_PUBLIC_STRING size_t
351 TRIO_PROTO((TRIO_CONST char *string, size_t max));
354 #if defined(TRIO_FUNC_LOWER)
355 TRIO_PUBLIC_STRING int
357 TRIO_PROTO((char *target));
360 #if defined(TRIO_FUNC_MATCH)
361 TRIO_PUBLIC_STRING int
363 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *pattern));
366 #if defined(TRIO_FUNC_MATCH_CASE)
367 TRIO_PUBLIC_STRING int
369 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *pattern));
372 #if defined(TRIO_FUNC_SPAN_FUNCTION)
373 TRIO_PUBLIC_STRING size_t
375 TRIO_PROTO((char *target, TRIO_CONST char *source, int (*Function) TRIO_PROTO((int))));
378 #if defined(TRIO_FUNC_SUBSTRING)
379 TRIO_PUBLIC_STRING char *
381 TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *substring));
384 #if defined(TRIO_FUNC_SUBSTRING_MAX)
385 TRIO_PUBLIC_STRING char *
387 TRIO_PROTO((TRIO_CONST char *string, size_t max, TRIO_CONST char *substring));
390 #if defined(TRIO_FUNC_TO_DOUBLE)
391 TRIO_PUBLIC_STRING double
393 TRIO_PROTO((TRIO_CONST char *source, char **endp));
396 #if defined(TRIO_FUNC_TO_FLOAT)
397 TRIO_PUBLIC_STRING float
399 TRIO_PROTO((TRIO_CONST char *source, char **endp));
402 #if defined(TRIO_FUNC_TO_LONG)
403 TRIO_PUBLIC_STRING long
405 TRIO_PROTO((TRIO_CONST char *source, char **endp, int base));
408 #if defined(TRIO_FUNC_TO_LOWER)
409 TRIO_PUBLIC_STRING int
411 TRIO_PROTO((int source));
414 #if defined(TRIO_FUNC_TO_LONG_DOUBLE)
415 TRIO_PUBLIC_STRING trio_long_double_t
417 TRIO_PROTO((TRIO_CONST char *source, char **endp));
420 #if defined(TRIO_FUNC_TO_UNSIGNED_LONG)
421 TRIO_PUBLIC_STRING unsigned long
422 trio_to_unsigned_long
423 TRIO_PROTO((TRIO_CONST char *source, char **endp, int base));
426 #if defined(TRIO_FUNC_TO_UPPER)
427 TRIO_PUBLIC_STRING int
429 TRIO_PROTO((int source));
432 #if defined(TRIO_FUNC_TOKENIZE)
433 TRIO_PUBLIC_STRING char *
435 TRIO_PROTO((char *string, TRIO_CONST char *delimiters));
438 #if defined(TRIO_FUNC_UPPER)
439 TRIO_PUBLIC_STRING int
441 TRIO_PROTO((char *target));
444 /*************************************************************************
445 * Dynamic string functions
449 * Opaque type for dynamic strings
452 typedef struct _trio_string_t trio_string_t;
454 #if defined(TRIO_FUNC_STRING_APPEND)
455 TRIO_PUBLIC_STRING int
457 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
460 #if defined(TRIO_FUNC_STRING_CONTAINS)
461 TRIO_PUBLIC_STRING int
463 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
466 #if defined(TRIO_FUNC_STRING_COPY)
467 TRIO_PUBLIC_STRING int
469 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
472 #if defined(TRIO_FUNC_STRING_CREATE)
473 TRIO_PUBLIC_STRING trio_string_t *
475 TRIO_PROTO((int initial_size));
478 #if defined(TRIO_FUNC_STRING_DESTROY)
479 TRIO_PUBLIC_STRING void
481 TRIO_PROTO((trio_string_t *self));
484 #if defined(TRIO_FUNC_STRING_DUPLICATE)
485 TRIO_PUBLIC_STRING trio_string_t *
486 trio_string_duplicate
487 TRIO_PROTO((trio_string_t *other));
490 #if defined(TRIO_FUNC_STRING_EQUAL)
491 TRIO_PUBLIC_STRING int
493 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
496 #if defined(TRIO_FUNC_STRING_EQUAL_MAX)
497 TRIO_PUBLIC_STRING int
498 trio_string_equal_max
499 TRIO_PROTO((trio_string_t *self, size_t max, trio_string_t *second));
502 #if defined(TRIO_FUNC_STRING_EQUAL_CASE)
503 TRIO_PUBLIC_STRING int
504 trio_string_equal_case
505 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
508 #if defined(TRIO_FUNC_STRING_EQUAL_CASE_MAX)
509 TRIO_PUBLIC_STRING int
510 trio_string_equal_case_max
511 TRIO_PROTO((trio_string_t *self, size_t max, trio_string_t *other));
514 #if defined(TRIO_FUNC_STRING_EXTRACT)
515 TRIO_PUBLIC_STRING char *
517 TRIO_PROTO((trio_string_t *self));
520 #if defined(TRIO_FUNC_STRING_FORMAT_DATE_MAX)
521 TRIO_PUBLIC_STRING size_t
522 trio_string_format_date_max
523 TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime));
526 #if defined(TRIO_FUNC_STRING_GET)
527 TRIO_PUBLIC_STRING char *
529 TRIO_PROTO((trio_string_t *self, int offset));
532 #if defined(TRIO_FUNC_STRING_INDEX)
533 TRIO_PUBLIC_STRING char *
535 TRIO_PROTO((trio_string_t *self, int character));
538 #if defined(TRIO_FUNC_STRING_INDEX_LAST)
539 TRIO_PUBLIC_STRING char *
540 trio_string_index_last
541 TRIO_PROTO((trio_string_t *self, int character));
544 #if defined(TRIO_FUNC_STRING_LENGTH)
545 TRIO_PUBLIC_STRING int
547 TRIO_PROTO((trio_string_t *self));
550 #if defined(TRIO_FUNC_STRING_LOWER)
551 TRIO_PUBLIC_STRING int
553 TRIO_PROTO((trio_string_t *self));
556 #if defined(TRIO_FUNC_STRING_MATCH)
557 TRIO_PUBLIC_STRING int
559 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
562 #if defined(TRIO_FUNC_STRING_MATCH_CASE)
563 TRIO_PUBLIC_STRING int
564 trio_string_match_case
565 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
568 #if defined(TRIO_FUNC_STRING_SIZE)
569 TRIO_PUBLIC_STRING int
571 TRIO_PROTO((trio_string_t *self));
574 #if defined(TRIO_FUNC_STRING_SUBSTRING)
575 TRIO_PUBLIC_STRING char *
576 trio_string_substring
577 TRIO_PROTO((trio_string_t *self, trio_string_t *other));
580 #if defined(TRIO_FUNC_STRING_TERMINATE)
581 TRIO_PUBLIC_STRING void
582 trio_string_terminate
583 TRIO_PROTO((trio_string_t *self));
586 #if defined(TRIO_FUNC_STRING_UPPER)
587 TRIO_PUBLIC_STRING int
589 TRIO_PROTO((trio_string_t *self));
592 #if defined(TRIO_FUNC_XSTRING_APPEND)
593 TRIO_PUBLIC_STRING int
595 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
598 #if defined(TRIO_FUNC_XSTRING_APPEND_CHAR)
599 TRIO_PUBLIC_STRING int
600 trio_xstring_append_char
601 TRIO_PROTO((trio_string_t *self, char character));
604 #if defined(TRIO_FUNC_XSTRING_CONTAINS)
605 TRIO_PUBLIC_STRING int
606 trio_xstring_contains
607 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
610 #if defined(TRIO_FUNC_XSTRING_COPY)
611 TRIO_PUBLIC_STRING int
613 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
616 #if defined(TRIO_FUNC_XSTRING_DUPLICATE)
617 TRIO_PUBLIC_STRING trio_string_t *
618 trio_xstring_duplicate
619 TRIO_PROTO((TRIO_CONST char *other));
622 #if defined(TRIO_FUNC_XSTRING_EQUAL)
623 TRIO_PUBLIC_STRING int
625 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
628 #if defined(TRIO_FUNC_XSTRING_EQUAL_MAX)
629 TRIO_PUBLIC_STRING int
630 trio_xstring_equal_max
631 TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *other));
634 #if defined(TRIO_FUNC_XSTRING_EQUAL_CASE)
635 TRIO_PUBLIC_STRING int
636 trio_xstring_equal_case
637 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
640 #if defined(TRIO_FUNC_XSTRING_EQUAL_CASE_MAX)
641 TRIO_PUBLIC_STRING int
642 trio_xstring_equal_case_max
643 TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *other));
646 #if defined(TRIO_FUNC_XSTRING_MATCH)
647 TRIO_PUBLIC_STRING int
649 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
652 #if defined(TRIO_FUNC_XSTRING_MATCH_CASE)
653 TRIO_PUBLIC_STRING int
654 trio_xstring_match_case
655 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
658 #if defined(TRIO_FUNC_XSTRING_SET)
659 TRIO_PUBLIC_STRING void
661 TRIO_PROTO((trio_string_t *self, char *buffer));
664 #if defined(TRIO_FUNC_XSTRING_SUBSTRING)
665 TRIO_PUBLIC_STRING char *
666 trio_xstring_substring
667 TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other));
674 #endif /* TRIO_TRIOSTR_H */