ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/shstr.h
(Generate patch)

Comparing deliantra/server/include/shstr.h (file contents):
Revision 1.27 by root, Wed Dec 31 18:29:44 2008 UTC vs.
Revision 1.32 by root, Thu Jan 1 20:49:48 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines