Mercurial > hg > nnchat
comparison th_string.h @ 11:707e35b03f89
Synced th-libs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 22 Mar 2008 02:52:01 +0000 |
parents | 728243125263 |
children | 4e3616709752 |
comparison
equal
deleted
inserted
replaced
10:53e127854dca | 11:707e35b03f89 |
---|---|
14 | 14 |
15 #include "th_util.h" | 15 #include "th_util.h" |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 #include <ctype.h> | 17 #include <ctype.h> |
18 | 18 |
19 /* | 19 /* Macros |
20 * Macros | |
21 */ | |
22 /* TODO - Remove usage of libc functions for increased portability. | |
23 * Possible issues are locales, impossible to implement them... | |
24 */ | 20 */ |
25 #define th_isalnum(c) isalnum((int)(unsigned char) c) | 21 #define th_isalnum(c) isalnum((int)(unsigned char) c) |
26 #define th_isalpha(c) isalpha((int)(unsigned char) c) | 22 #define th_isalpha(c) isalpha((int)(unsigned char) c) |
27 #define th_isascii(c) isascii((int)(unsigned char) c) | 23 #define th_isascii(c) isascii((int)(unsigned char) c) |
28 #define th_isblank(c) isblank((int)(unsigned char) c) | 24 #define th_isblank(c) isblank((int)(unsigned char) c) |
40 #define th_isspecial(q) (((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d))) | 36 #define th_isspecial(q) (((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d))) |
41 | 37 |
42 #define th_tolower(c) tolower((int)(unsigned char) c) | 38 #define th_tolower(c) tolower((int)(unsigned char) c) |
43 #define th_toupper(c) toupper((int)(unsigned char) c) | 39 #define th_toupper(c) toupper((int)(unsigned char) c) |
44 | 40 |
45 /* | 41 |
46 * Typedefs and structures | 42 /* Normal NUL-terminated string functions |
47 */ | 43 */ |
48 typedef struct tstrnode { | 44 char *th_stralloc(size_t); |
49 char_t *pcStr; /* String */ | 45 char *th_strrealloc(char *, size_t); |
50 ulint_t nUsed; /* Times this string has been referenced */ | 46 char *th_strdup(char *); |
51 void *pData; /* Extra data */ | 47 char *th_strncpy(char *, char *, size_t); |
52 | 48 int th_strcasecmp(char *, char *); |
53 struct tstrnode *pPrev, *pNext; | 49 int th_strncasecmp(char *, char *, size_t); |
54 } t_str_node; | 50 void th_strip_ctrlchars(char *); |
55 | 51 |
52 int th_pstrcpy(char **, char *); | |
53 int th_pstrcat(char **, char *); | |
56 | 54 |
57 #define SET_HASH_MAXINDEX (256) | 55 char *th_findnext(char *, size_t *); |
56 char *th_findsep(char *, size_t *, char); | |
57 char *th_findseporspace(char *, size_t *, char); | |
58 | 58 |
59 typedef t_str_node *t_str_hash[SET_HASH_MAXINDEX]; | 59 BOOL th_strmatch(char *, char *); |
60 BOOL th_strcasematch(char *, char *); | |
60 | 61 |
61 | |
62 typedef struct tstrindex { | |
63 t_str_node **ppIndex; | |
64 ulint_t n; | |
65 } t_str_index; | |
66 | |
67 | |
68 /* | |
69 * Normal NUL-terminated string functions | |
70 */ | |
71 char_t *th_stralloc(size_t); | |
72 char_t *th_strrealloc(char_t *, size_t); | |
73 size_t th_strlen(char_t *); | |
74 char_t *th_strdup(char_t *); | |
75 char_t *th_strcat(char_t *, char_t *); | |
76 char_t *th_strcpy(char_t *, char_t *); | |
77 char_t *th_strncpy(char_t *, char_t *, size_t); | |
78 int th_strcmp(char_t *, char_t *); | |
79 int th_strncmp(char_t *, char_t *, size_t); | |
80 int th_strcasecmp(char_t *, char_t *); | |
81 int th_strncasecmp(char_t *, char_t *, size_t); | |
82 void th_strip_ctrlchars(char_t *); | |
83 char_t *th_strstr(char_t *, char_t *); | |
84 | |
85 int th_pstrcpy(char_t **, char_t *); | |
86 int th_pstrcat(char_t **, char_t *); | |
87 | |
88 char_t *th_findnext(char_t *, size_t *); | |
89 char_t *th_findsep(char_t *, size_t *, char_t); | |
90 char_t *th_findseporspace(char_t *, size_t *, char_t); | |
91 | |
92 BOOL th_strmatch(char_t *, char_t *); | |
93 BOOL th_strcasematch(char_t *, char_t *); | |
94 | |
95 | |
96 /* | |
97 * Handling of string-lists and hashes | |
98 */ | |
99 t_str_node * th_strnode_new(char_t *, ulint_t, void *); | |
100 void th_strnode_free(t_str_node *); | |
101 void th_strlist_free(t_str_node *); | |
102 void th_strlist_insert(t_str_node **, t_str_node *); | |
103 int th_strhash_insert(t_str_node **, t_str_node *, BOOL); | |
104 void th_strhash_free(t_str_node **); | |
105 void th_strhash_change_pdata(t_str_hash, void *, void *); | |
106 t_str_node * th_strhash_search(t_str_node **, char_t *, BOOL); | |
107 t_str_index * th_strhash_makeindex(t_str_node **); | |
108 t_str_index * th_strlist_makeindex(t_str_node *); | |
109 void th_strindex_free(t_str_index *); | |
110 void th_strindex_sort_nused(t_str_index *); | |
111 void th_strindex_sort_alpha(t_str_index *); | |
112 | 62 |
113 #ifdef __cplusplus | 63 #ifdef __cplusplus |
114 } | 64 } |
115 #endif | 65 #endif |
116 #endif /* _TH_STRING_H */ | 66 #endif /* _TH_STRING_H */ |