]> andersk Git - splint.git/blame - src/Headers/cstring.h
Fixed line numbering when multi-line macro parameters are used.
[splint.git] / src / Headers / cstring.h
CommitLineData
885824d3 1/*
2934b455 2** Copyright (C) University of Virginia, Massachusetts Institue of Technology 1994-2001.
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 23extern /*@notnull@*/ cstring cstring_create (size_t p_n) /*@*/ /*@ensures maxSet(result) == p_n @*/ ;
2934b455 24extern /*@only@*/ /*@notnull@*/ cstring cstring_newEmpty (void) ;
885824d3 25extern /*@notnull@*/ cstring cstring_appendChar (/*@only@*/ cstring p_s1, char p_c);
26
abd7f895 27extern 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
31extern /*@notnull@*/ cstring cstring_prependChar (char p_c, /*@temp@*/ cstring p_s1);
32extern /*@notnull@*/ cstring cstring_prependCharO (char p_c, /*@only@*/ cstring p_s1);
33extern cstring cstring_downcase (cstring p_s) /*@*/ ;
86d93ed3 34extern cstring cstring_copy (cstring p_s) /*@*/ /*@ensures maxSet(result) == maxRead(p_s) /\ maxRead(result) == maxRead(p_s) @*/ ;
abd7f895 35extern cstring cstring_copyLength (char *p_s, size_t p_len) /*@*/ /*@requires maxSet(p_s) >= (p_len - 1) @*/;
885824d3 36
37extern int cstring_toPosInt (cstring p_s) /*@*/ ;
38
39typedef 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
46extern 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 53extern void cstring_replaceAll (cstring p_s, char p_old, char p_snew) /*@modifies p_s@*/ ;
885824d3 54
92b2ba2c 55extern 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 59extern char cstring_firstChar (cstring p_s) /*@*/ ;
60extern char cstring_secondChar (cstring p_s) /*@*/ ;
885824d3 61extern char cstring_lastChar (cstring p_s) /*@*/ ;
abd7f895 62extern char cstring_getChar (cstring p_s, size_t p_n);
63
64extern 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 69extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/ char *
885824d3 70 cstring_toCharsSafe (/*@temp@*/ /*@exposed@*/ /*@returned@*/ cstring p_s)
71 /*@*/ ;
72
abd7f895 73extern size_t cstring_length (cstring p_s) /*@*/ /*@ensures result == maxRead(p_s) @*/;
74
885824d3 75extern bool cstring_contains (/*@unique@*/ cstring p_c, cstring p_sub) /*@*/ ;
76extern bool cstring_containsChar (cstring p_c, char p_ch) /*@*/ ;
77extern bool cstring_equal (cstring p_c1, cstring p_c2) /*@*/ ;
78extern bool cstring_equalCaseInsensitive (cstring p_c1, cstring p_c2) /*@*/ ;
abd7f895 79extern bool cstring_equalLen (cstring p_c1, cstring p_c2, size_t p_len) /*@*/ ;
80extern bool cstring_equalLenCaseInsensitive (cstring p_c1, cstring p_c2, size_t p_len) /*@*/ ;
68de3f33 81extern bool cstring_equalPrefix (cstring p_c1, cstring p_c2) /*@*/ ;
82extern bool cstring_equalPrefixLit (cstring p_c1, /*@observer@*/ const char *p_c2) /*@*/ ;
885824d3 83extern bool cstring_equalLit (cstring p_c1, char *p_c2) /*@*/ ;
84extern int cstring_compare (cstring p_c1, cstring p_c2) /*@*/ ;
85extern int cstring_xcompare (cstring *p_c1, cstring *p_c2) /*@*/ ;
86
87# ifndef NOLCL
88extern bool cstring_hasNonAlphaNumBar (cstring p_s) /*@*/ ;
89# endif
90
abd7f895 91extern cstring cstring_elide (cstring p_s, size_t p_len) /*@*/ ;
92
93extern cstring cstring_clip (/*@returned@*/ cstring p_s, size_t p_len)
885824d3 94 /*@modifies p_s@*/ ;
abd7f895 95
885824d3 96extern void cstring_stripChars (cstring p_s, const char *p_clist) /*@modifies p_s@*/ ;
97
98extern /*@dependent@*/ cstring
99 cstring_bsearch (cstring p_key,
100 char **p_table,
101 int p_nentries);
102
103extern bool cstring_lessthan (cstring p_s1, cstring p_s2) /*@*/ ;
104# define cstring_lessthan(s1, s2) (cstring_compare (s1, s2) < 0)
105
106# define cstring_equalLit(s, lit) \
107 (mstring_equal (cstring_toCharsSafe (s), lit))
108
109extern bool cstring_equalFree (/*@only@*/ cstring p_c1, /*@only@*/ cstring p_c2);
110
111/* really exposed! */
ccf0a4a8 112
113/*
114** Don't allow tainted cstring's
115*/
116
117extern /*@untained@*/ cstring
885824d3 118 cstring_fromChars (/*@returned@*/ /*@null@*/
ccf0a4a8 119 const /*:untainted@*/ /*@exposed@*/ /*@temp@*/ char *p_cp) /*@*/ ;
885824d3 120
121extern cstring
ccf0a4a8 122 cstring_fromCharsO (/*@null@*/ /*:untainted@*/ /*@only@*/ char *p_cp) /*@*/ ;
885824d3 123/*@-mustfree@*/
124# define cstring_fromCharsO(s) cstring_fromChars(s)
125/*@=mustfree@*/
126
ccf0a4a8 127extern cstring cstring_fromCharsNew (/*:untainted@*/ /*@null@*/ char *p_s) /*@*/ ;
885824d3 128# define cstring_fromCharsNew(s) cstring_copy(cstring_fromChars(s))
129
130# ifndef NOLCL
ccf0a4a8 131extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/
885824d3 132 char *cstring_toCharsSafeO (/*@only@*/ /*@exposed@*/ /*@returned@*/ cstring p_s);
133/*@-mustfree@*/
134# define cstring_toCharsSafeO(s) cstring_toCharsSafe(s)
135/*@=mustfree@*/
136# endif
137
138extern void cstring_free (/*@only@*/ cstring p_s);
139
140/*@constant null cstring cstring_undefined;@*/
141# define cstring_undefined ((cstring)NULL)
142
0e41eb0e 143extern /*@falsewhennull@*/ bool cstring_isDefined (cstring p_s) /*@*/ ;
144extern /*@nullwhentrue@*/ bool cstring_isUndefined (cstring p_s) /*@*/ ;
885824d3 145
0e41eb0e 146extern /*@nullwhentrue@*/ bool cstring_isEmpty (cstring p_s) /*@*/ ;
147extern /*@falsewhennull@*/ bool cstring_isNonEmpty (cstring p_s) /*@*/ ;
885824d3 148
149# define cstring_isDefined(s) ((s) != cstring_undefined)
150# define cstring_isUndefined(s) (!cstring_isDefined(s))
151
152# define cstring_isEmpty(s) (cstring_length(s) == 0)
153# define cstring_isNonEmpty(s) (!cstring_isEmpty(s))
154
155extern cstring cstring_makeLiteral (char *) /*@*/ ;
156extern /*@observer@*/ /*@dependent@*/ cstring
157 cstring_makeLiteralTemp (char *) /*@*/ ;
158
159# define cstring_makeLiteral(s) (cstring_copy (cstring_fromChars (s)))
160# define cstring_makeLiteralTemp(s) (cstring_fromChars (s))
161
86d93ed3 162extern cstring cstring_capitalize (cstring p_s) /*@*/ /*@requires maxSet(p_s) >= 0 @*/ ;
163extern cstring cstring_capitalizeFree (/*@only@*/ cstring p_s) /*@modifies p_s@*/ /*@requires maxSet(p_s) >= 0 /\ maxRead(p_s) >= 0 @*/ ;
abd7f895 164
165extern cstring cstring_fill (cstring p_s, size_t p_n) /*@*/ /*@requires p_n >= 0 @*/;
166
167extern cstring cstring_prefix (cstring p_s, size_t p_n)
168 /*@*/
169 /*@requires maxRead(p_s) >= p_n /\ maxSet(p_s) >= p_n @*/
170 /*@ensures maxRead(result) == p_n /\ maxSet(result) == p_n @*/ ;
171
172extern /*@observer@*/ cstring cstring_suffix (cstring p_s, size_t p_n) /*@*/ ;
86d93ed3 173extern cstring cstring_concat (cstring p_s, cstring p_t) /*@*/ /*@requires maxSet(p_s) >= 0 @*/;
885824d3 174
175extern cstring
176 cstring_concatFree (/*@only@*/ cstring p_s, /*@only@*/ cstring p_t)
177 /*@modifies p_s, p_t@*/ ;
178
179extern cstring
180 cstring_concatFree1 (/*@only@*/ cstring p_s, cstring p_t)
181 /*@modifies p_s@*/ ;
182
183# ifndef NOLCL
184extern cstring
185 cstring_concatChars (/*@only@*/ cstring p_s, char *p_t)
186 /*@modifies p_s@*/ ;
187
188extern lsymbol cstring_toSymbol (/*@only@*/ cstring p_s) /*@*/ ;
189# endif
190
191extern void cstring_markOwned (/*@owned@*/ cstring p_s) /*@modifies p_s@*/ ;
192
193extern cstring cstring_beforeChar (cstring p_s, char p_c) /*@*/ ;
68de3f33 194extern /*@exposed@*/ cstring cstring_afterChar (cstring p_s, char p_c) /*@*/ ;
885824d3 195
196/*@iter cstring_chars (sef cstring s, yield char c);@*/
197# define cstring_chars(s, m_c) \
198 if (cstring_isDefined (s)) \
199 { char *m_current = (char *) (s); \
200 char m_c; \
201 for (; (m_c = *m_current) != '\0'; m_current++) {
202# define end_cstring_chars }}
203
204extern /*@observer@*/ cstring cstring_advanceWhiteSpace (cstring) /*@*/ ;
205
2934b455 206extern /*@only@*/ /*@notnull@*/ cstring
abd7f895 207cstring_copySegment (cstring p_s, size_t p_findex, size_t p_tindex) /*@*/ ;
2934b455 208
1810fe2a 209/*drl added 01/22/2001 Expands the escape squences i.e "\\n\\t\\000"
210 becomes "\n\t0" */
abd7f895 211extern /*@notnull@*/ cstring cstring_expandEscapes (cstring p_s);
1810fe2a 212
213/*drl added 01/23/2001 Gives you the number of characters in an
214 expanded escape squences. This can be different from strlen bc/ of
215 escaped nulls. */
216int cstring_lengthExpandEscapes (cstring p_s);
217
218
885824d3 219extern bool cstring_containsLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ;
220# define cstring_containsLit(c,sub) \
221 (cstring_contains (c, cstring_fromChars (sub)))
222
28bf4b0b 223/*drl added July 2, 001 */
224extern int cstring_compareLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ;
225# define cstring_compareLit(c,sub) \
226 (cstring_compare (c, cstring_fromChars (sub)))
227
9276a168 228/*drl added 2/4/2002*/
229/*replaces every instance of the character old with the character new
230 old can not be '\0'
231*/
232cstring cstring_replaceChar(/*@returned@*/ cstring p_c, char p_oldChar, char p_newChar);
233
885824d3 234# else
235# error "Multiple include"
236# endif
237
238
239
This page took 0.094826 seconds and 5 git commands to generate.