annotate th_string.h @ 282:3dc86d8eb0a9

Added helper functions for easier string manipulation.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Jun 2011 20:48:17 +0300
parents 51319822ae92
children eb74097b73f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Miscellaneous string-handling related utility-functions
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
249
51319822ae92 Update copyright year.
Matti Hamalainen <ccr@tnsp.org>
parents: 241
diff changeset
4 * (C) Copyright 2002-2011 Tecnic Software productions (TNSP)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #ifndef _TH_STRING_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define _TH_STRING_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #ifdef __cplusplus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 extern "C" {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include "th_util.h"
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #include <stdlib.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #include <ctype.h>
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
18 #include <stdarg.h>
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
20 /* Macros
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 */
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
22 #define th_isalnum(c) isalnum((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
23 #define th_isalpha(c) isalpha((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
24 #define th_isascii(c) isascii((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
25 #define th_isblank(c) isblank((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
26 #define th_iscntrl(c) iscntrl((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
27 #define th_isdigit(c) isdigit((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
28 #define th_isgraph(c) isgraph((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
29 #define th_islower(c) islower((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
30 #define th_isprint(c) isprint((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
31 #define th_ispunct(c) ispunct((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
32 #define th_isspace(c) isspace((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
33 #define th_isupper(c) isupper((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
34 #define th_isxdigit(c) isxdigit((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
35 #define th_iscrlf(c) ((c=='\r')||(c=='\n'))
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
37 #define th_isspecial(q) (((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d)))
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
39 #define th_tolower(c) tolower((int)(unsigned char) c)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
40 #define th_toupper(c) toupper((int)(unsigned char) c)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43 /* Normal NUL-terminated string functions
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 */
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
45 char *th_strncpy(char *, const char *, size_t);
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
46 int th_strcasecmp(const char *, const char *);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
47 int th_strncasecmp(const char *, const char *, size_t);
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
48 void th_strip_ctrlchars(char *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
50 char *th_strdup_vprintf(const char *, va_list);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
51 char *th_strdup_printf(const char *, ...);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
52
282
3dc86d8eb0a9 Added helper functions for easier string manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
53 void th_pstr_vprintf(char **, const char *, va_list);
3dc86d8eb0a9 Added helper functions for easier string manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
54 void th_pstr_printf(char **, const char *, ...);
3dc86d8eb0a9 Added helper functions for easier string manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
55
79
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
56 char *th_strdup(const char *);
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
57 int th_pstrcpy(char **, const char *);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
58 int th_pstrcat(char **, const char *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
60 const char *th_findnext(const char *, size_t *);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
61 const char *th_findsep(const char *, size_t *, char);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
62 const char *th_findseporspace(const char *, size_t *, char);
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
63
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
64 BOOL th_strmatch(const char *, const char *);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
65 BOOL th_strcasematch(const char *, const char *);
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66
131
3896861974ac Added th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
67 int th_get_hex_triplet(const char *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
241
a1ee6c76ca1c Functions for growing a string buffer when needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
69
a1ee6c76ca1c Functions for growing a string buffer when needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
70 void th_vputch(char **buf, size_t *bufsize, size_t *len, const char ch);
a1ee6c76ca1c Functions for growing a string buffer when needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
71 void th_vputs(char **buf, size_t *bufsize, size_t *len, const char *str);
a1ee6c76ca1c Functions for growing a string buffer when needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
72
a1ee6c76ca1c Functions for growing a string buffer when needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
73 #define TH_BUFGROW (32)
a1ee6c76ca1c Functions for growing a string buffer when needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
74
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 #ifdef __cplusplus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 #endif /* _TH_STRING_H */