]>
Commit | Line | Data |
---|---|---|
885824d3 | 1 | /* |
c0de361f | 2 | ** Copyright (C) University of Virginia, Massachusetts Institue of Technology 1994-2003. |
885824d3 | 3 | ** See ../LICENSE for license information. |
4 | ** | |
5 | */ | |
6 | /* | |
7 | ** cstring.h | |
8 | */ | |
9 | ||
10 | # ifndef CSTRING_H | |
11 | # define CSTRING_H | |
12 | ||
13 | /* does this cause problems on Solaris? linux? */ | |
14 | /* sgi's don't like it */ | |
15 | # ifndef IRIX | |
16 | # ifdef NULL /* hack so <strings.h> works */ | |
17 | # undef NULL | |
18 | # endif | |
19 | # endif | |
20 | ||
21 | /* typedefs in forwardTypes */ | |
22 | ||
abd7f895 | 23 | extern /*@notnull@*/ cstring cstring_create (size_t p_n) /*@*/ /*@ensures maxSet(result) == p_n @*/ ; |
2934b455 | 24 | extern /*@only@*/ /*@notnull@*/ cstring cstring_newEmpty (void) ; |
885824d3 | 25 | extern /*@notnull@*/ cstring cstring_appendChar (/*@only@*/ cstring p_s1, char p_c); |
26 | ||
abd7f895 | 27 | extern cstring cstring_concatLength (/*@only@*/ cstring p_s1, char *p_s2, size_t p_len) |
28 | /*@*/ | |
29 | /*@requires maxSet(p_s2) >= (p_len - 1) @*/ ; | |
885824d3 | 30 | |
31 | extern /*@notnull@*/ cstring cstring_prependChar (char p_c, /*@temp@*/ cstring p_s1); | |
32 | extern /*@notnull@*/ cstring cstring_prependCharO (char p_c, /*@only@*/ cstring p_s1); | |
33 | extern cstring cstring_downcase (cstring p_s) /*@*/ ; | |
86d93ed3 | 34 | extern cstring cstring_copy (cstring p_s) /*@*/ /*@ensures maxSet(result) == maxRead(p_s) /\ maxRead(result) == maxRead(p_s) @*/ ; |
abd7f895 | 35 | extern cstring cstring_copyLength (char *p_s, size_t p_len) /*@*/ /*@requires maxSet(p_s) >= (p_len - 1) @*/; |
885824d3 | 36 | |
37 | extern int cstring_toPosInt (cstring p_s) /*@*/ ; | |
38 | ||
39 | typedef enum { | |
40 | CGE_SAME, /* no differences */ | |
41 | CGE_DISTINCT, /* significant differences */ | |
42 | CGE_CASE, /* case differences */ | |
43 | CGE_LOOKALIKE /* lookalike differences */ | |
2934b455 | 44 | } cmpcode; |
885824d3 | 45 | |
46 | extern cmpcode cstring_genericEqual (cstring p_s, cstring p_t, | |
abd7f895 | 47 | size_t p_nchars, |
885824d3 | 48 | bool p_caseinsensitive, |
abd7f895 | 49 | bool p_lookalike) /*@*/ |
50 | /*@requires maxRead(p_s) >= p_nchars /\ maxRead(p_t) >= p_nchars @*/ ; | |
885824d3 | 51 | |
68de3f33 | 52 | /* evans 2001-09-09 - removed conditional compilation on this (for WIN32, OS2) */ |
885824d3 | 53 | extern void cstring_replaceAll (cstring p_s, char p_old, char p_snew) /*@modifies p_s@*/ ; |
885824d3 | 54 | |
92b2ba2c | 55 | extern void cstring_replaceLit (/*@unique@*/ cstring p_s, char *p_old, char *p_snew) |
56 | /*@modifies p_s@*/ | |
57 | /*@requires maxRead(p_snew) >= 0 /\ maxRead(p_old) >= 0 /\ maxRead(p_old) >= maxRead(p_snew) @*/; | |
58 | ||
990ec868 | 59 | extern char cstring_firstChar (cstring p_s) /*@*/ ; |
60 | extern char cstring_secondChar (cstring p_s) /*@*/ ; | |
885824d3 | 61 | extern char cstring_lastChar (cstring p_s) /*@*/ ; |
abd7f895 | 62 | extern char cstring_getChar (cstring p_s, size_t p_n); |
63 | ||
64 | extern void cstring_setChar (cstring p_s, size_t p_n, char p_c) | |
65 | /*@requires maxRead(p_s) >= (p_n - 1) /\ maxSet(p_s) >= (p_n - 1) @*/ ; | |
885824d3 | 66 | |
67 | # define cstring_secondChar(s) cstring_getChar (s, 2) | |
68 | ||
ccf0a4a8 | 69 | extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/ char * |
517a2db3 | 70 | cstring_toCharsSafe (/*@temp@*/ /*@exposed@*/ /*@returned@*/ cstring p_s) |
71 | /*@*/ ; | |
885824d3 | 72 | |
abd7f895 | 73 | extern size_t cstring_length (cstring p_s) /*@*/ /*@ensures result == maxRead(p_s) @*/; |
74 | ||
885824d3 | 75 | extern bool cstring_contains (/*@unique@*/ cstring p_c, cstring p_sub) /*@*/ ; |
76 | extern bool cstring_containsChar (cstring p_c, char p_ch) /*@*/ ; | |
77 | extern bool cstring_equal (cstring p_c1, cstring p_c2) /*@*/ ; | |
78 | extern bool cstring_equalCaseInsensitive (cstring p_c1, cstring p_c2) /*@*/ ; | |
abd7f895 | 79 | extern bool cstring_equalLen (cstring p_c1, cstring p_c2, size_t p_len) /*@*/ ; |
80 | extern bool cstring_equalLenCaseInsensitive (cstring p_c1, cstring p_c2, size_t p_len) /*@*/ ; | |
68de3f33 | 81 | extern bool cstring_equalPrefix (cstring p_c1, cstring p_c2) /*@*/ ; |
82 | extern bool cstring_equalPrefixLit (cstring p_c1, /*@observer@*/ const char *p_c2) /*@*/ ; | |
885824d3 | 83 | extern bool cstring_equalLit (cstring p_c1, char *p_c2) /*@*/ ; |
84 | extern int cstring_compare (cstring p_c1, cstring p_c2) /*@*/ ; | |
85 | extern int cstring_xcompare (cstring *p_c1, cstring *p_c2) /*@*/ ; | |
86 | ||
885824d3 | 87 | extern bool cstring_hasNonAlphaNumBar (cstring p_s) /*@*/ ; |
885824d3 | 88 | |
abd7f895 | 89 | extern cstring cstring_elide (cstring p_s, size_t p_len) /*@*/ ; |
90 | ||
91 | extern cstring cstring_clip (/*@returned@*/ cstring p_s, size_t p_len) | |
885824d3 | 92 | /*@modifies p_s@*/ ; |
abd7f895 | 93 | |
885824d3 | 94 | extern void cstring_stripChars (cstring p_s, const char *p_clist) /*@modifies p_s@*/ ; |
95 | ||
96 | extern /*@dependent@*/ cstring | |
97 | cstring_bsearch (cstring p_key, | |
98 | char **p_table, | |
99 | int p_nentries); | |
100 | ||
101 | extern bool cstring_lessthan (cstring p_s1, cstring p_s2) /*@*/ ; | |
102 | # define cstring_lessthan(s1, s2) (cstring_compare (s1, s2) < 0) | |
103 | ||
104 | # define cstring_equalLit(s, lit) \ | |
105 | (mstring_equal (cstring_toCharsSafe (s), lit)) | |
106 | ||
107 | extern bool cstring_equalFree (/*@only@*/ cstring p_c1, /*@only@*/ cstring p_c2); | |
108 | ||
109 | /* really exposed! */ | |
ccf0a4a8 | 110 | |
111 | /* | |
112 | ** Don't allow tainted cstring's | |
113 | */ | |
114 | ||
517a2db3 | 115 | extern cstring |
116 | cstring_fromChars (/*@returned@*/ /*@null@*/ | |
117 | const /*@exposed@*/ /*@temp@*/ char *p_cp) /*@*/ ; | |
885824d3 | 118 | |
119 | extern cstring | |
517a2db3 | 120 | cstring_fromCharsO (/*@null@*/ /*@only@*/ char *p_cp) /*@*/ ; |
885824d3 | 121 | /*@-mustfree@*/ |
122 | # define cstring_fromCharsO(s) cstring_fromChars(s) | |
123 | /*@=mustfree@*/ | |
124 | ||
517a2db3 | 125 | extern cstring cstring_fromCharsNew (/*@null@*/ char *p_s) /*@*/ ; |
885824d3 | 126 | # define cstring_fromCharsNew(s) cstring_copy(cstring_fromChars(s)) |
127 | ||
ccf0a4a8 | 128 | extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/ |
885824d3 | 129 | char *cstring_toCharsSafeO (/*@only@*/ /*@exposed@*/ /*@returned@*/ cstring p_s); |
130 | /*@-mustfree@*/ | |
131 | # define cstring_toCharsSafeO(s) cstring_toCharsSafe(s) | |
132 | /*@=mustfree@*/ | |
885824d3 | 133 | |
134 | extern void cstring_free (/*@only@*/ cstring p_s); | |
135 | ||
136 | /*@constant null cstring cstring_undefined;@*/ | |
137 | # define cstring_undefined ((cstring)NULL) | |
138 | ||
0e41eb0e | 139 | extern /*@falsewhennull@*/ bool cstring_isDefined (cstring p_s) /*@*/ ; |
140 | extern /*@nullwhentrue@*/ bool cstring_isUndefined (cstring p_s) /*@*/ ; | |
885824d3 | 141 | |
0e41eb0e | 142 | extern /*@nullwhentrue@*/ bool cstring_isEmpty (cstring p_s) /*@*/ ; |
143 | extern /*@falsewhennull@*/ bool cstring_isNonEmpty (cstring p_s) /*@*/ ; | |
885824d3 | 144 | |
145 | # define cstring_isDefined(s) ((s) != cstring_undefined) | |
146 | # define cstring_isUndefined(s) (!cstring_isDefined(s)) | |
147 | ||
148 | # define cstring_isEmpty(s) (cstring_length(s) == 0) | |
149 | # define cstring_isNonEmpty(s) (!cstring_isEmpty(s)) | |
150 | ||
151 | extern cstring cstring_makeLiteral (char *) /*@*/ ; | |
152 | extern /*@observer@*/ /*@dependent@*/ cstring | |
153 | cstring_makeLiteralTemp (char *) /*@*/ ; | |
154 | ||
155 | # define cstring_makeLiteral(s) (cstring_copy (cstring_fromChars (s))) | |
156 | # define cstring_makeLiteralTemp(s) (cstring_fromChars (s)) | |
157 | ||
86d93ed3 | 158 | extern cstring cstring_capitalize (cstring p_s) /*@*/ /*@requires maxSet(p_s) >= 0 @*/ ; |
159 | extern cstring cstring_capitalizeFree (/*@only@*/ cstring p_s) /*@modifies p_s@*/ /*@requires maxSet(p_s) >= 0 /\ maxRead(p_s) >= 0 @*/ ; | |
abd7f895 | 160 | |
161 | extern cstring cstring_fill (cstring p_s, size_t p_n) /*@*/ /*@requires p_n >= 0 @*/; | |
162 | ||
163 | extern cstring cstring_prefix (cstring p_s, size_t p_n) | |
164 | /*@*/ | |
165 | /*@requires maxRead(p_s) >= p_n /\ maxSet(p_s) >= p_n @*/ | |
166 | /*@ensures maxRead(result) == p_n /\ maxSet(result) == p_n @*/ ; | |
167 | ||
168 | extern /*@observer@*/ cstring cstring_suffix (cstring p_s, size_t p_n) /*@*/ ; | |
86d93ed3 | 169 | extern cstring cstring_concat (cstring p_s, cstring p_t) /*@*/ /*@requires maxSet(p_s) >= 0 @*/; |
885824d3 | 170 | |
171 | extern cstring | |
172 | cstring_concatFree (/*@only@*/ cstring p_s, /*@only@*/ cstring p_t) | |
173 | /*@modifies p_s, p_t@*/ ; | |
174 | ||
175 | extern cstring | |
176 | cstring_concatFree1 (/*@only@*/ cstring p_s, cstring p_t) | |
177 | /*@modifies p_s@*/ ; | |
178 | ||
885824d3 | 179 | extern cstring |
180 | cstring_concatChars (/*@only@*/ cstring p_s, char *p_t) | |
181 | /*@modifies p_s@*/ ; | |
182 | ||
183 | extern lsymbol cstring_toSymbol (/*@only@*/ cstring p_s) /*@*/ ; | |
885824d3 | 184 | |
185 | extern void cstring_markOwned (/*@owned@*/ cstring p_s) /*@modifies p_s@*/ ; | |
186 | ||
187 | extern cstring cstring_beforeChar (cstring p_s, char p_c) /*@*/ ; | |
68de3f33 | 188 | extern /*@exposed@*/ cstring cstring_afterChar (cstring p_s, char p_c) /*@*/ ; |
885824d3 | 189 | |
190 | /*@iter cstring_chars (sef cstring s, yield char c);@*/ | |
191 | # define cstring_chars(s, m_c) \ | |
192 | if (cstring_isDefined (s)) \ | |
193 | { char *m_current = (char *) (s); \ | |
194 | char m_c; \ | |
195 | for (; (m_c = *m_current) != '\0'; m_current++) { | |
196 | # define end_cstring_chars }} | |
197 | ||
198 | extern /*@observer@*/ cstring cstring_advanceWhiteSpace (cstring) /*@*/ ; | |
199 | ||
2934b455 | 200 | extern /*@only@*/ /*@notnull@*/ cstring |
abd7f895 | 201 | cstring_copySegment (cstring p_s, size_t p_findex, size_t p_tindex) /*@*/ ; |
2934b455 | 202 | |
1810fe2a | 203 | /*drl added 01/22/2001 Expands the escape squences i.e "\\n\\t\\000" |
204 | becomes "\n\t0" */ | |
abd7f895 | 205 | extern /*@notnull@*/ cstring cstring_expandEscapes (cstring p_s); |
1810fe2a | 206 | |
207 | /*drl added 01/23/2001 Gives you the number of characters in an | |
208 | expanded escape squences. This can be different from strlen bc/ of | |
209 | escaped nulls. */ | |
37ae0b5e | 210 | extern size_t cstring_lengthExpandEscapes (cstring p_s); |
1810fe2a | 211 | |
212 | ||
885824d3 | 213 | extern bool cstring_containsLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ; |
214 | # define cstring_containsLit(c,sub) \ | |
215 | (cstring_contains (c, cstring_fromChars (sub))) | |
216 | ||
28bf4b0b | 217 | /*drl added July 2, 001 */ |
218 | extern int cstring_compareLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ; | |
219 | # define cstring_compareLit(c,sub) \ | |
220 | (cstring_compare (c, cstring_fromChars (sub))) | |
221 | ||
9276a168 | 222 | /*drl added 2/4/2002*/ |
223 | /*replaces every instance of the character old with the character new | |
224 | old can not be '\0' | |
225 | */ | |
226 | cstring cstring_replaceChar(/*@returned@*/ cstring p_c, char p_oldChar, char p_newChar); | |
227 | ||
885824d3 | 228 | # else |
229 | # error "Multiple include" | |
230 | # endif | |
231 | ||
232 | ||
233 |