Mercurial > hg > nnchat
comparison th_string.h @ 0:728243125263
Import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 20 Mar 2008 00:15:03 +0000 |
parents | |
children | 707e35b03f89 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:728243125263 |
---|---|
1 /* | |
2 * Miscellaneous string-handling related utility-functions | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2002-2008 Tecnic Software productions (TNSP) | |
5 * | |
6 * Please read file 'COPYING' for information on license and distribution. | |
7 */ | |
8 #ifndef _TH_STRING_H | |
9 #define _TH_STRING_H | |
10 | |
11 #ifdef __cplusplus | |
12 extern "C" { | |
13 #endif | |
14 | |
15 #include "th_util.h" | |
16 #include <stdlib.h> | |
17 #include <ctype.h> | |
18 | |
19 /* | |
20 * Macros | |
21 */ | |
22 /* TODO - Remove usage of libc functions for increased portability. | |
23 * Possible issues are locales, impossible to implement them... | |
24 */ | |
25 #define th_isalnum(c) isalnum((int)(unsigned char) c) | |
26 #define th_isalpha(c) isalpha((int)(unsigned char) c) | |
27 #define th_isascii(c) isascii((int)(unsigned char) c) | |
28 #define th_isblank(c) isblank((int)(unsigned char) c) | |
29 #define th_iscntrl(c) iscntrl((int)(unsigned char) c) | |
30 #define th_isdigit(c) isdigit((int)(unsigned char) c) | |
31 #define th_isgraph(c) isgraph((int)(unsigned char) c) | |
32 #define th_islower(c) islower((int)(unsigned char) c) | |
33 #define th_isprint(c) isprint((int)(unsigned char) c) | |
34 #define th_ispunct(c) ispunct((int)(unsigned char) c) | |
35 #define th_isspace(c) isspace((int)(unsigned char) c) | |
36 #define th_isupper(c) isupper((int)(unsigned char) c) | |
37 #define th_isxdigit(c) isxdigit((int)(unsigned char) c) | |
38 #define th_iscrlf(c) ((c=='\r')||(c=='\n')) | |
39 | |
40 #define th_isspecial(q) (((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d))) | |
41 | |
42 #define th_tolower(c) tolower((int)(unsigned char) c) | |
43 #define th_toupper(c) toupper((int)(unsigned char) c) | |
44 | |
45 /* | |
46 * Typedefs and structures | |
47 */ | |
48 typedef struct tstrnode { | |
49 char_t *pcStr; /* String */ | |
50 ulint_t nUsed; /* Times this string has been referenced */ | |
51 void *pData; /* Extra data */ | |
52 | |
53 struct tstrnode *pPrev, *pNext; | |
54 } t_str_node; | |
55 | |
56 | |
57 #define SET_HASH_MAXINDEX (256) | |
58 | |
59 typedef t_str_node *t_str_hash[SET_HASH_MAXINDEX]; | |
60 | |
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 | |
113 #ifdef __cplusplus | |
114 } | |
115 #endif | |
116 #endif /* _TH_STRING_H */ |