Mercurial > hg > th-libs
annotate th_string.h @ 727:b415b70254fa
Add set_bit/test_bit helpers.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 06 Jan 2022 13:12:16 +0200 |
parents | 29e44a58bc73 |
children | 31bc1ed07cf5 |
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 |
726 | 4 * (C) Copyright 2002-2022 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 | 8 /// @file |
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 | 16 #ifdef __cplusplus |
17 extern "C" { | |
18 #endif | |
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 | 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 | 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 |
680
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
53 typedef struct |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
54 { |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
55 size_t nelems; |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
56 th_char_t **elems; |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
57 } th_strelems_t; |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
58 |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
59 |
616
594f197f7005
Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
60 /** @brief |
594f197f7005
Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
61 * Internal *printf() implementation flags |
438 | 62 */ |
299
0311f139fcf6
Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
63 enum |
0311f139fcf6
Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
64 { |
372 | 65 TH_PF_NONE = 0x0000, |
66 TH_PF_ALT = 0x0001, | |
67 TH_PF_SIGN = 0x0002, | |
68 TH_PF_SPACE = 0x0004, | |
69 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
|
70 |
372 | 71 TH_PF_ZERO = 0x0100, |
72 TH_PF_LEFT = 0x0200, | |
330
b2c4b0b4d44f
Add initial support for ll and L printf modifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
73 |
372 | 74 TH_PF_LONG = 0x1000, |
75 TH_PF_LONGLONG = 0x2000, | |
76 TH_PF_POINTER = 0x4000, | |
77 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
|
78 }; |
0311f139fcf6
Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
79 |
0311f139fcf6
Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
80 |
616
594f197f7005
Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
81 /** @struct th_vprintf_ctx |
594f197f7005
Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
82 * 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
|
83 * used by the printf() code for "output" purposes. |
438 | 84 */ |
251
7b76108248e9
More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
85 typedef struct |
7b76108248e9
More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
86 { |
663 | 87 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
|
88 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
|
89 size_t pos; ///< Current position in the buffer |
438 | 90 int ipos; ///< Signed position |
439 | 91 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
|
92 } th_vprintf_ctx; |
251
7b76108248e9
More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
93 |
7b76108248e9
More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
94 |
616
594f197f7005
Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
95 /** @brief |
594f197f7005
Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
96 * 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
|
97 * @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
|
98 * @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
|
99 * @returns the character @p ch cast to int or @c EOF in case of error |
438 | 100 */ |
663 | 101 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
|
102 |
7450d744e633
Rename internal functions and add a typedef for function pointer used for vputch().
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
103 |
618 | 104 /** @brief |
105 * Internal *printf() implementation helper function typedef | |
594
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
106 * for alternative formatting, such as octal and hexadecimal |
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
107 */ |
663 | 108 typedef th_char_t * (*th_vprintf_altfmt_func)( |
109 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
|
110 |
663 | 111 #define TH_VPRINTF_ALTFMT_FUNC(fname) th_char_t * fname ( \ |
112 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
|
113 |
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
114 |
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
115 TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_oct); |
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
116 TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_hex); |
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
117 |
31720ede4b50
Reorganize th_string.h header slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
118 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 /* Normal NUL-terminated string functions |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 */ |
679
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
121 #ifdef TH_CHAR_TYPE |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
122 /** |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
123 * Implementation of strlen() that uses th_char_t type. Not optimized. |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
124 * @param[in] src string to get length of |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
125 * @returns length of the string in number of th_char_t units. |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
126 */ |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
127 size_t th_strlen(const th_char_t *str) |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
128 { |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
129 size_t len = 0; |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
130 assert(str != NULL); |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
131 |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
132 while (str[len]) len++; |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
133 |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
134 return len; |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
135 } |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
136 #else |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
137 #define th_strlen(xd) strlen(xd) |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
138 #endif |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
139 |
83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
674
diff
changeset
|
140 |
687 | 141 th_char_t *th_strchr(const th_char_t *str, const th_char_t ch); |
701 | 142 th_char_t *th_strpbrk(const th_char_t *str, const th_char_t *valid); |
663 | 143 th_char_t *th_strdup(const th_char_t *src); |
144 th_char_t *th_strndup(const th_char_t *src, const size_t n); | |
145 th_char_t *th_strdup_trim(const th_char_t *src, const int flags); | |
146 th_char_t *th_strndup_trim(const th_char_t *src, const size_t n, const int flags); | |
81 | 147 |
663 | 148 th_char_t *th_strndup_no0(const th_char_t *src, const size_t len); |
149 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
|
150 |
663 | 151 int th_strcasecmp(const th_char_t *haystack, const th_char_t *needle); |
152 int th_strncasecmp(const th_char_t *haystack, const th_char_t *needle, size_t n); | |
153 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
|
154 |
663 | 155 int th_vsnprintf(th_char_t *buf, size_t size, const th_char_t *fmt, va_list ap); |
156 int th_snprintf(th_char_t *buf, size_t size, const th_char_t *fmt, ...) | |
157 TH_ATTR_PRINTF_FMT(3, 4); | |
158 int th_vfprintf(FILE *fh, const th_char_t *fmt, va_list ap); | |
159 int th_fprintf(FILE *fh, const th_char_t *fmt, ...) | |
160 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
|
161 |
ca9cd98dbcff
Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
162 |
663 | 163 th_char_t *th_strdup_vprintf(const th_char_t *fmt, va_list ap); |
164 th_char_t *th_strdup_printf(const th_char_t *fmt, ...) | |
165 TH_ATTR_PRINTF_FMT(1, 2); | |
14
e5e6370217ef
Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
166 |
663 | 167 void th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap); |
168 void th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...) | |
169 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
|
170 |
663 | 171 int th_pstr_cpy(th_char_t **pdst, const th_char_t *src); |
172 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
|
173 |
680
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
174 int th_split_string_elems(const th_char_t *str, th_strelems_t *ctx, const th_char_t *sep); |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
175 int th_split_string(const th_char_t *str, th_char_t ***elems, size_t *nelems, const th_char_t *sep); |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
176 int th_join_string_elems(th_char_t **str, const th_strelems_t *ctx, const th_char_t *sep); |
39c82d877251
Add new th_strelems_t structure for and join/split functions using them to
Matti Hamalainen <ccr@tnsp.org>
parents:
679
diff
changeset
|
177 int th_join_string(th_char_t **str, th_char_t **elems, const size_t nelems, const th_char_t *sep); |
682 | 178 void th_strelems_free(th_strelems_t *ctx); |
674
dfabc7eef3dd
Add new functions th_split_string() and th_join_string().
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
179 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 |
451
db45d6d2e576
Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
181 /* 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
|
182 */ |
663 | 183 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
184 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
|
185 |
663 | 186 int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
187 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
|
188 |
663 | 189 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
190 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, | |
191 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
|
192 |
663 | 193 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
194 th_char_t *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, | |
195 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
|
196 |
451
db45d6d2e576
Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
197 |
661
7f1efa37288b
Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
198 #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
|
199 #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
|
200 #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
|
201 #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
|
202 #include "th_printf1.c" |
db45d6d2e576
Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
203 |
db45d6d2e576
Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
204 |
661
7f1efa37288b
Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
205 #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
|
206 #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
|
207 #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
|
208 #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
|
209 #include "th_printf1.c" |
db45d6d2e576
Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
210 |
db45d6d2e576
Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
211 |
525
59b8f15c5334
Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents:
497
diff
changeset
|
212 #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
|
213 extern BOOL th_printf_debug; |
529
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
525
diff
changeset
|
214 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
|
215 #endif |
59b8f15c5334
Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents:
497
diff
changeset
|
216 |
59b8f15c5334
Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents:
497
diff
changeset
|
217 |
78 | 218 /* Parsing, matching |
219 */ | |
663 | 220 const th_char_t *th_findnext(const th_char_t *str, size_t *pos); |
221 const th_char_t *th_findsep(const th_char_t *str, size_t *pos, const th_char_t sep); | |
222 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
|
223 |
663 | 224 BOOL th_strmatch(const th_char_t *haystack, const th_char_t *pattern); |
225 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
|
226 |
663 | 227 BOOL th_get_hex_triplet(const th_char_t *str, unsigned int *value); |
228 BOOL th_get_boolean(const th_char_t *str, BOOL *value); | |
229 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
|
230 |
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
|
231 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 #endif |
129 | 235 #endif // TH_STRING_H |