]> andersk Git - splint.git/blob - src/Headers/cstring.h
336007297d237afe2f6364b3e0155e2430759f1a
[splint.git] / src / Headers / cstring.h
1 /*
2 ** Copyright (C) University of Virginia, Massachusetts Institue of Technology 1994-2003.
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
23 extern /*@notnull@*/ cstring cstring_create (size_t p_n) /*@*/ /*@ensures maxSet(result) == p_n @*/ ;
24 extern /*@only@*/ /*@notnull@*/  cstring cstring_newEmpty (void) ;
25 extern /*@notnull@*/ cstring cstring_appendChar (/*@only@*/ cstring p_s1, char p_c);
26
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) @*/ ;
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) /*@*/ ;
34 extern cstring cstring_copy (cstring p_s) /*@*/  /*@ensures maxSet(result) == maxRead(p_s) /\ maxRead(result) == maxRead(p_s) @*/ ;
35 extern cstring cstring_copyLength (char *p_s, size_t p_len) /*@*/  /*@requires maxSet(p_s) >= (p_len - 1) @*/;
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 */
44 } cmpcode;
45
46 extern cmpcode cstring_genericEqual (cstring p_s, cstring p_t,
47                                      size_t p_nchars,
48                                      bool p_caseinsensitive,
49                                      bool p_lookalike) /*@*/ 
50   /*@requires maxRead(p_s) >= p_nchars /\ maxRead(p_t) >= p_nchars @*/ ;
51
52 /* evans 2001-09-09 - removed conditional compilation on this (for WIN32, OS2) */
53 extern void cstring_replaceAll (cstring p_s, char p_old, char p_snew) /*@modifies p_s@*/ ;
54
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
59 extern char cstring_firstChar (cstring p_s) /*@*/ ;
60 extern char cstring_secondChar (cstring p_s) /*@*/ ;
61 extern char cstring_lastChar (cstring p_s) /*@*/ ;
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) @*/ ;
66
67 # define cstring_secondChar(s) cstring_getChar (s, 2)
68
69 extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/ char *
70   cstring_toCharsSafe (/*@temp@*/ /*@exposed@*/ /*@returned@*/ cstring p_s)
71      /*@*/ ;
72
73 extern size_t cstring_length (cstring p_s) /*@*/ /*@ensures result == maxRead(p_s) @*/;
74
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) /*@*/ ;
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) /*@*/ ;
81 extern bool cstring_equalPrefix (cstring p_c1, cstring p_c2) /*@*/ ;
82 extern bool cstring_equalPrefixLit (cstring p_c1, /*@observer@*/ const char *p_c2) /*@*/ ;
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
87 extern bool cstring_hasNonAlphaNumBar (cstring p_s) /*@*/ ;
88
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) 
92    /*@modifies p_s@*/ ;
93
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! */
110
111 /*
112 ** Don't allow tainted cstring's
113 */
114
115 extern /*@untained@*/ cstring 
116   cstring_fromChars (/*@returned@*/ /*@null@*/ 
117                      const /*:untainted@*/ /*@exposed@*/ /*@temp@*/ char *p_cp) /*@*/ ;
118
119 extern cstring
120    cstring_fromCharsO (/*@null@*/ /*:untainted@*/ /*@only@*/ char *p_cp) /*@*/ ;
121 /*@-mustfree@*/
122 # define cstring_fromCharsO(s) cstring_fromChars(s)
123 /*@=mustfree@*/
124
125 extern cstring cstring_fromCharsNew (/*:untainted@*/ /*@null@*/ char *p_s) /*@*/ ;
126 # define cstring_fromCharsNew(s) cstring_copy(cstring_fromChars(s))
127
128 extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/
129   char *cstring_toCharsSafeO (/*@only@*/ /*@exposed@*/ /*@returned@*/ cstring p_s);
130 /*@-mustfree@*/
131 # define cstring_toCharsSafeO(s) cstring_toCharsSafe(s)
132 /*@=mustfree@*/
133
134 extern void cstring_free (/*@only@*/ cstring p_s);
135
136 /*@constant null cstring cstring_undefined;@*/
137 # define cstring_undefined     ((cstring)NULL)
138
139 extern /*@falsewhennull@*/ bool cstring_isDefined (cstring p_s) /*@*/ ;
140 extern /*@nullwhentrue@*/ bool cstring_isUndefined (cstring p_s) /*@*/ ;
141
142 extern /*@nullwhentrue@*/ bool cstring_isEmpty (cstring p_s) /*@*/ ;
143 extern /*@falsewhennull@*/ bool cstring_isNonEmpty (cstring p_s) /*@*/ ;
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
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 @*/ ;
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) /*@*/ ;
169 extern cstring cstring_concat (cstring p_s, cstring p_t) /*@*/ /*@requires maxSet(p_s) >= 0 @*/;
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
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) /*@*/ ;
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) /*@*/ ;
188 extern /*@exposed@*/ cstring cstring_afterChar (cstring p_s, char p_c) /*@*/ ;
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
200 extern /*@only@*/ /*@notnull@*/ cstring
201 cstring_copySegment (cstring p_s, size_t p_findex, size_t p_tindex) /*@*/ ;
202
203 /*drl added 01/22/2001  Expands the escape squences i.e "\\n\\t\\000"
204  becomes "\n\t0"  */
205 extern /*@notnull@*/ cstring  cstring_expandEscapes (cstring p_s);
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.  */
210 extern size_t cstring_lengthExpandEscapes (cstring p_s);
211
212
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
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
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
228 # else
229 # error "Multiple include"
230 # endif
231
232
233
This page took 0.046922 seconds and 3 git commands to generate.