annotate th_string.h @ 682:527a4d29d384

Typofix :S
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Mar 2020 20:17:39 +0200
parents 39c82d877251
children 5a7254b78614
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
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
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
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
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
65 TH_PF_NONE = 0x0000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
66 TH_PF_ALT = 0x0001,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
67 TH_PF_SIGN = 0x0002,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
68 TH_PF_SPACE = 0x0004,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
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
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
71 TH_PF_ZERO = 0x0100,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
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
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
74 TH_PF_LONG = 0x1000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
75 TH_PF_LONGLONG = 0x2000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
76 TH_PF_POINTER = 0x4000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
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
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
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
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
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
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
90 int ipos; ///< Signed position
439
9b5a6fb05565 Adjust wording.
Matti Hamalainen <ccr@tnsp.org>
parents: 438
diff changeset
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
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
100 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
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
64fd686197d4 Fix a Doxygen comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 617
diff changeset
104 /** @brief
64fd686197d4 Fix a Doxygen comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 617
diff changeset
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
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
108 typedef th_char_t * (*th_vprintf_altfmt_func)(
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
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
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
111 #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
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
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
141 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
142 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
143 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
144 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
145
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
146 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
147 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
148
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
149 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
150 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
151 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
152
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
153 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
154 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
155 TH_ATTR_PRINTF_FMT(3, 4);
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
156 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
157 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
158 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
159
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
160
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
161 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
162 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
163 TH_ATTR_PRINTF_FMT(1, 2);
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
164
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
165 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
166 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
167 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
168
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
169 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
170 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
171
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
172 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
173 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
174 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
175 int th_join_string(th_char_t **str, th_char_t **elems, const size_t nelems, const th_char_t *sep);
682
527a4d29d384 Typofix :S
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
176 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
177
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
179 /* 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
180 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
181 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
182 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
183
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
184 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
185 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
186
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
187 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
188 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
189 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
190
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
191 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
192 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
193 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
194
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
195
661
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
196 #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
197 #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
198 #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
199 #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
200 #include "th_printf1.c"
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
201
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
202
661
7f1efa37288b Rename TH_PFUNC_* macros to TH_VPRINTF_INTFMT_*
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
203 #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
204 #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
205 #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
206 #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
207 #include "th_printf1.c"
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
208
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
209
525
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
210 #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
211 extern BOOL th_printf_debug;
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 525
diff changeset
212 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
213 #endif
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
214
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
215
78
2579250f2a84 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
216 /* Parsing, matching
2579250f2a84 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
217 */
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
218 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
219 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
220 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
221
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
222 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
223 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
224
663
284d5b789b7c Add th_char_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 661
diff changeset
225 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
226 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
227 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
228
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
229
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 #ifdef __cplusplus
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 #endif
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
233 #endif // TH_STRING_H