comparison th_string.h @ 680:39c82d877251

Add new th_strelems_t structure for and join/split functions using them to make certain operations nicer.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Mar 2020 19:47:11 +0200
parents 83a48de05fe9
children 527a4d29d384
comparison
equal deleted inserted replaced
679:83a48de05fe9 680:39c82d877251
48 TH_TRIM_END = 2, ///< Trim whitespace from end of the string 48 TH_TRIM_END = 2, ///< Trim whitespace from end of the string
49 TH_TRIM_BOTH = 3, ///< Trim whitespace from start and end of the string 49 TH_TRIM_BOTH = 3, ///< Trim whitespace from start and end of the string
50 }; 50 };
51 51
52 52
53 typedef struct
54 {
55 size_t nelems;
56 th_char_t **elems;
57 } th_strelems_t;
58
59
53 /** @brief 60 /** @brief
54 * Internal *printf() implementation flags 61 * Internal *printf() implementation flags
55 */ 62 */
56 enum 63 enum
57 { 64 {
160 TH_ATTR_PRINTF_FMT(2, 3); 167 TH_ATTR_PRINTF_FMT(2, 3);
161 168
162 int th_pstr_cpy(th_char_t **pdst, const th_char_t *src); 169 int th_pstr_cpy(th_char_t **pdst, const th_char_t *src);
163 int th_pstr_cat(th_char_t **pdst, const th_char_t *src); 170 int th_pstr_cat(th_char_t **pdst, const th_char_t *src);
164 171
165 int th_split_string(const char *str, char ***elems, size_t *nelems, const char *sep); 172 int th_split_string_elems(const th_char_t *str, th_strelems_t *ctx, const th_char_t *sep);
166 int th_join_string(char **str, char **elems, const size_t nelems, const char *sep); 173 int th_split_string(const th_char_t *str, th_char_t ***elems, size_t *nelems, const th_char_t *sep);
174 int th_join_string_elems(th_char_t **str, const th_strelems_t *ctx, const th_char_t *sep);
175 int th_join_string(th_char_t **str, th_char_t **elems, const size_t nelems, const th_char_t *sep);
176 void th_strlems_free(th_strelems_t *ctx);
167 177
168 178
169 /* Internal printf() implementation. NOTICE! This API may be unstable. 179 /* Internal printf() implementation. NOTICE! This API may be unstable.
170 */ 180 */
171 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, 181 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch,