… | |
… | |
70 | return length () >= plen && !strncasecmp (s, prefix, plen); |
70 | return length () >= plen && !strncasecmp (s, prefix, plen); |
71 | } |
71 | } |
72 | |
72 | |
73 | bool contains (const char *substring) const |
73 | bool contains (const char *substring) const |
74 | { |
74 | { |
75 | return strstr (s, substring); |
75 | return s != null () && strstr (s, substring); |
|
|
76 | } |
|
|
77 | |
|
|
78 | //TODO: case sensitive should be eradicated |
|
|
79 | bool eq_nc (const char *otherstring) const |
|
|
80 | { |
|
|
81 | return !strcasecmp (s, otherstring); |
76 | } |
82 | } |
77 | |
83 | |
78 | shstr_tmp () |
84 | shstr_tmp () |
79 | : s (null ()) |
85 | : s (null ()) |
80 | { |
86 | { |
… | |
… | |
113 | inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b) |
119 | inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b) |
114 | { |
120 | { |
115 | return a.s != b.s; |
121 | return a.s != b.s; |
116 | } |
122 | } |
117 | |
123 | |
118 | inline int strlen (const shstr_tmp &sh) |
124 | inline int strlen (shstr_tmp sh) |
119 | { |
125 | { |
120 | return sh.length (); |
126 | return sh.length (); |
121 | } |
127 | } |
122 | |
|
|
123 | // undefined external reference to catch people using strcmp when they shouldn't |
|
|
124 | int strcmp (const shstr_tmp &a, const shstr_tmp &b); |
|
|
125 | |
128 | |
126 | static std::ostream &operator <<(std::ostream &o, shstr_tmp sh) |
129 | static std::ostream &operator <<(std::ostream &o, shstr_tmp sh) |
127 | { |
130 | { |
128 | o.write (sh.s, sh.length ()); |
131 | o.write (sh.s, sh.length ()); |
129 | |
132 | |
… | |
… | |
206 | // temporary passing, basically a non-refcounted shstr |
209 | // temporary passing, basically a non-refcounted shstr |
207 | struct shstr_cmp |
210 | struct shstr_cmp |
208 | { |
211 | { |
209 | const char *s; |
212 | const char *s; |
210 | |
213 | |
|
|
214 | // initialies to the non-matching string (as opposed to the null string) |
|
|
215 | shstr_cmp () |
|
|
216 | { |
|
|
217 | s = 0; |
|
|
218 | } |
|
|
219 | |
211 | explicit shstr_cmp (const char *str) |
220 | shstr_cmp (const char *str) |
212 | : s (shstr::find (str)) |
221 | : s (shstr::find (str)) |
213 | { |
222 | { |
214 | } |
223 | } |
215 | |
224 | |
216 | shstr_cmp (shstr_tmp sh) |
225 | shstr_cmp (shstr_tmp sh) |
… | |
… | |
232 | inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b) |
241 | inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b) |
233 | { |
242 | { |
234 | return a.s == b.s; |
243 | return a.s == b.s; |
235 | } |
244 | } |
236 | |
245 | |
237 | struct shstr_const : shstr_tmp |
246 | #define def2(id,str) extern const shstr id; |
238 | { |
247 | #define def(id) def2(shstr_ ## id, # id) |
239 | shstr_const (const char *s) |
|
|
240 | : shstr_tmp (0, s) |
|
|
241 | { |
|
|
242 | } |
|
|
243 | }; |
|
|
244 | |
|
|
245 | #define def(str) extern const shstr_const shstr_ ## str; |
|
|
246 | # include "shstrinc.h" |
248 | # include "shstrinc.h" |
247 | #undef def |
249 | #undef def |
|
|
250 | #undef def2 |
|
|
251 | |
|
|
252 | // undefined external reference to catch people using str* functions when they shouldn't |
|
|
253 | //template<class any> void strcmp (const shstr_tmp &a, any b); |
|
|
254 | template<class any> void strstr (const shstr_tmp &a, any b); |
248 | |
255 | |
249 | #endif |
256 | #endif |
250 | |
257 | |