annotate th_string.h @ 0:728243125263

Import.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Mar 2008 00:15:03 +0000
parents
children 707e35b03f89
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
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2002-2008 Tecnic Software productions (TNSP)
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>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 * Macros
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 /* TODO - Remove usage of libc functions for increased portability.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 * Possible issues are locales, impossible to implement them...
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #define th_isalnum(c) isalnum((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #define th_isalpha(c) isalpha((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #define th_isascii(c) isascii((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #define th_isblank(c) isblank((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #define th_iscntrl(c) iscntrl((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #define th_isdigit(c) isdigit((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #define th_isgraph(c) isgraph((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #define th_islower(c) islower((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #define th_isprint(c) isprint((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #define th_ispunct(c) ispunct((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #define th_isspace(c) isspace((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #define th_isupper(c) isupper((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #define th_isxdigit(c) isxdigit((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 #define th_iscrlf(c) ((c=='\r')||(c=='\n'))
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 #define th_isspecial(q) (((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d)))
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 #define th_tolower(c) tolower((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 #define th_toupper(c) toupper((int)(unsigned char) c)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 * Typedefs and structures
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 typedef struct tstrnode {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 char_t *pcStr; /* String */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 ulint_t nUsed; /* Times this string has been referenced */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 void *pData; /* Extra data */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 struct tstrnode *pPrev, *pNext;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 } t_str_node;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 #define SET_HASH_MAXINDEX (256)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 typedef t_str_node *t_str_hash[SET_HASH_MAXINDEX];
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 typedef struct tstrindex {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 t_str_node **ppIndex;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 ulint_t n;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 } t_str_index;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 * Normal NUL-terminated string functions
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 char_t *th_stralloc(size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 char_t *th_strrealloc(char_t *, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 size_t th_strlen(char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 char_t *th_strdup(char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 char_t *th_strcat(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 char_t *th_strcpy(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 char_t *th_strncpy(char_t *, char_t *, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 int th_strcmp(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 int th_strncmp(char_t *, char_t *, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 int th_strcasecmp(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 int th_strncasecmp(char_t *, char_t *, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 void th_strip_ctrlchars(char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 char_t *th_strstr(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 int th_pstrcpy(char_t **, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 int th_pstrcat(char_t **, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 char_t *th_findnext(char_t *, size_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 char_t *th_findsep(char_t *, size_t *, char_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 char_t *th_findseporspace(char_t *, size_t *, char_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 BOOL th_strmatch(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 BOOL th_strcasematch(char_t *, char_t *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 * Handling of string-lists and hashes
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 t_str_node * th_strnode_new(char_t *, ulint_t, void *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 void th_strnode_free(t_str_node *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 void th_strlist_free(t_str_node *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 void th_strlist_insert(t_str_node **, t_str_node *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 int th_strhash_insert(t_str_node **, t_str_node *, BOOL);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 void th_strhash_free(t_str_node **);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 void th_strhash_change_pdata(t_str_hash, void *, void *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 t_str_node * th_strhash_search(t_str_node **, char_t *, BOOL);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 t_str_index * th_strhash_makeindex(t_str_node **);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 t_str_index * th_strlist_makeindex(t_str_node *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 void th_strindex_free(t_str_index *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 void th_strindex_sort_nused(t_str_index *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 void th_strindex_sort_alpha(t_str_index *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 #ifdef __cplusplus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 #endif /* _TH_STRING_H */