annotate th_string.h @ 674:dfabc7eef3dd

Add new functions th_split_string() and th_join_string().
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 25 Feb 2020 05:16:42 +0200
parents 284d5b789b7c
children 83a48de05fe9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Miscellaneous string-handling related utility-functions
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
553
3a852e9f70a6 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
4 * (C) Copyright 2002-2020 Tecnic Software productions (TNSP)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
8 /// @file
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
9 /// @brief String utility functions
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
10 #ifndef TH_STRING_H
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
11 #define TH_STRING_H
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "th_util.h"
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <ctype.h>
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
91
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
16 #ifdef __cplusplus
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
17 extern "C" {
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
18 #endif
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
19
617
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
20
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
21 /** @def String utility wrapper macros
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
617
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
23 #define th_isalnum(c) isalnum((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
24 #define th_isalpha(c) isalpha((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
25 #define th_isascii(c) isascii((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
26 #define th_isblank(c) isblank((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
27 #define th_iscntrl(c) iscntrl((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
28 #define th_isdigit(c) isdigit((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
29 #define th_isgraph(c) isgraph((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
30 #define th_islower(c) islower((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
31 #define th_isprint(c) isprint((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
32 #define th_ispunct(c) ispunct((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
33 #define th_isspace(c) isspace((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
34 #define th_isupper(c) isupper((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
35 #define th_isxdigit(c) isxdigit((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
36 #define th_iscrlf(c) ((c) == '\r' || (c) == '\n')
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
617
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
38 #define th_tolower(c) tolower((int)(unsigned char) (c))
a3d5ddbb6f16 Add some extra () protection in the th_is* macro wrapper arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
39 #define th_toupper(c) toupper((int)(unsigned char) (c))
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
42 /** @brief
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
43 * String trimming option flags for th_strdup_trim()
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
44 */
90
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
45 enum
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
46 {
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
47 TH_TRIM_START = 1, ///< Trim whitespace from start of the string
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
48 TH_TRIM_END = 2, ///< Trim whitespace from end of the string
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
49 TH_TRIM_BOTH = 3, ///< Trim whitespace from start and end of the string
90
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
50 };
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
51
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
52
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
53 /** @brief
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
54 * Internal *printf() implementation flags
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
55 */
299
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
56 enum
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
57 {
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
58 TH_PF_NONE = 0x0000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
59 TH_PF_ALT = 0x0001,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
60 TH_PF_SIGN = 0x0002,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
61 TH_PF_SPACE = 0x0004,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
62 TH_PF_GROUP = 0x0008,
299
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
63
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
64 TH_PF_ZERO = 0x0100,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
65 TH_PF_LEFT = 0x0200,
330
b2c4b0b4d44f Add initial support for ll and L printf modifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
66
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
67 TH_PF_LONG = 0x1000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
68 TH_PF_LONGLONG = 0x2000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
69 TH_PF_POINTER = 0x4000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
70 TH_PF_UPCASE = 0x8000,
299
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
71 };
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
72
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
73
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
74 /** @struct th_vprintf_ctx
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
75 * Internal printf() implementation context structure, contains state information
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
76 * used by the printf() code for "output" purposes.
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
77 */
251
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
78 typedef struct
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
79 {
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
80 th_char_t *buf; ///< Resulting string buffer pointer (might not be used if printing to file or such)
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
81 size_t size; ///< Size of result string buffer
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
82 size_t pos; ///< Current position in the buffer
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
83 int ipos; ///< Signed position
439
9b5a6fb05565 Adjust wording.
Matti Hamalainen <ccr@tnsp.org>
parents: 438
diff changeset
84 void *data; ///< Pointer to other data (for example a FILE pointer)
374
1d8ae82304ec Rename s/th_printf_ctx/th_vprintf_cts/g.
Matti Hamalainen <ccr@tnsp.org>
parents: 373
diff changeset
85 } th_vprintf_ctx;
251
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
86
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
87
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
88 /** @brief
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
89 * A putch() helper function typedef for internal printf() implementation
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
90 * @param[in,out] ctx pointer to internal printf() state context structure.
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
91 * @param[in] ch character to be outputted
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 594
diff changeset
92 * @returns the character @p ch cast to int or @c EOF in case of error
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
93 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
94 typedef int (*th_vprintf_putch)(th_vprintf_ctx *ctx, const th_char_t ch);
277
7450d744e633 Rename internal functions and add a typedef for function pointer used for vputch().
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
95
7450d744e633 Rename internal functions and add a typedef for function pointer used for vputch().
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
96
618
64fd686197d4 Fix a Doxygen comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 617
diff changeset
97 /** @brief
64fd686197d4 Fix a Doxygen comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 617
diff changeset
98 * Internal *printf() implementation helper function typedef
594
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
99 * for alternative formatting, such as octal and hexadecimal
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
100 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
101 typedef th_char_t * (*th_vprintf_altfmt_func)(
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
102 const th_char_t *buf, const size_t len, const int vret, int *prec, int *flags, int *outlen);
594
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
103
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
104 #define TH_VPRINTF_ALTFMT_FUNC(fname) th_char_t * fname ( \
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
105 const th_char_t *buf, const size_t len, const int vret, int *prec, int *flags, int *outlen)
594
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
106
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
107
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
108 TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_oct);
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
109 TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_hex);
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
110
31720ede4b50 Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 584
diff changeset
111
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 /* Normal NUL-terminated string functions
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
114 th_char_t *th_strdup(const th_char_t *src);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
115 th_char_t *th_strndup(const th_char_t *src, const size_t n);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
116 th_char_t *th_strdup_trim(const th_char_t *src, const int flags);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
117 th_char_t *th_strndup_trim(const th_char_t *src, const size_t n, const int flags);
81
c9c0541bed90 Add th_strndup().
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
118
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
119 th_char_t *th_strndup_no0(const th_char_t *src, const size_t len);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
120 th_char_t *th_strndup_no0_trim(const th_char_t *src, const size_t len, const int flags);
487
702c64a6c570 Add new string helper functions th_strndup_no0() and th_strndup_no0_trim()
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
121
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
122 int th_strcasecmp(const th_char_t *haystack, const th_char_t *needle);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
123 int th_strncasecmp(const th_char_t *haystack, const th_char_t *needle, size_t n);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
124 th_char_t *th_strrcasecmp(th_char_t *haystack, const th_char_t *needle);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
126 int th_vsnprintf(th_char_t *buf, size_t size, const th_char_t *fmt, va_list ap);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
127 int th_snprintf(th_char_t *buf, size_t size, const th_char_t *fmt, ...)
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
128 TH_ATTR_PRINTF_FMT(3, 4);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
129 int th_vfprintf(FILE *fh, const th_char_t *fmt, va_list ap);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
130 int th_fprintf(FILE *fh, const th_char_t *fmt, ...)
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
131 TH_ATTR_PRINTF_FMT(2, 3);
228
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
132
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
133
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
134 th_char_t *th_strdup_vprintf(const th_char_t *fmt, va_list ap);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
135 th_char_t *th_strdup_printf(const th_char_t *fmt, ...)
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
136 TH_ATTR_PRINTF_FMT(1, 2);
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
137
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
138 void th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
139 void th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...)
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
140 TH_ATTR_PRINTF_FMT(2, 3);
30
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
141
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
142 int th_pstr_cpy(th_char_t **pdst, const th_char_t *src);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
143 int th_pstr_cat(th_char_t **pdst, const th_char_t *src);
186
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
144
674
dfabc7eef3dd Add new functions th_split_string() and th_join_string().
Matti Hamalainen <ccr@tnsp.org>
parents: 663
diff changeset
145 int th_split_string(const char *str, char ***elems, size_t *nelems, const char *sep);
dfabc7eef3dd Add new functions th_split_string() and th_join_string().
Matti Hamalainen <ccr@tnsp.org>
parents: 663
diff changeset
146 int th_join_string(char **str, char **elems, const size_t nelems, const char *sep);
dfabc7eef3dd Add new functions th_split_string() and th_join_string().
Matti Hamalainen <ccr@tnsp.org>
parents: 663
diff changeset
147
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
149 /* Internal printf() implementation. NOTICE! This API may be unstable.
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
150 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
151 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
152 const th_char_t *fmt, va_list ap);
567
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
153
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
154 int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
155 const th_char_t *str, int f_flags, const int f_width, const int f_prec);
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
156
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
157 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
158 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec,
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
159 const BOOL f_unsig, th_vprintf_altfmt_func f_alt);
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
160
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
161 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
162 th_char_t *buf, int f_flags, int f_width, int f_prec, int f_len, int vret,
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
163 BOOL f_neg, BOOL f_unsig, th_vprintf_altfmt_func f_alt);
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
164
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
165
661
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
166 #define TH_VPRINTF_INTFMT_NAME th_vprintf_buf_int
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
167 #define TH_VPRINTF_INTFMT_TYPE_S int
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
168 #define TH_VPRINTF_INTFMT_TYPE_U unsigned int
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
169 #define TH_VPRINTF_INTFMT_HEADER 1
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
170 #include "th_printf1.c"
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
171
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
172
661
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
173 #define TH_VPRINTF_INTFMT_NAME th_vprintf_buf_int64
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
174 #define TH_VPRINTF_INTFMT_TYPE_S int64_t
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
175 #define TH_VPRINTF_INTFMT_TYPE_U uint64_t
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
176 #define TH_VPRINTF_INTFMT_HEADER 1
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
177 #include "th_printf1.c"
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
178
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
179
525
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
180 #ifdef TH_PRINTF_DEBUG
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
181 extern BOOL th_printf_debug;
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 525
diff changeset
182 extern char *th_printf_debug_prefix;
525
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
183 #endif
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
184
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
185
78
2579250f2a84 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
186 /* Parsing, matching
2579250f2a84 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
187 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
188 const th_char_t *th_findnext(const th_char_t *str, size_t *pos);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
189 const th_char_t *th_findsep(const th_char_t *str, size_t *pos, const th_char_t sep);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
190 const th_char_t *th_findseporspace(const th_char_t *str, size_t *pos, const th_char_t sep);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
192 BOOL th_strmatch(const th_char_t *haystack, const th_char_t *pattern);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
193 BOOL th_strcasematch(const th_char_t *haystack, const th_char_t *pattern);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
195 BOOL th_get_hex_triplet(const th_char_t *str, unsigned int *value);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
196 BOOL th_get_boolean(const th_char_t *str, BOOL *value);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
197 BOOL th_get_int(const th_char_t *str, unsigned int *value, BOOL *neg);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
199
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 #ifdef __cplusplus
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 #endif
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
203 #endif // TH_STRING_H