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.25 by root, Wed Dec 31 18:07:41 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 {
94 103
95 // this is used for informational messages and the like 104 // this is used for informational messages and the like
96 const char *operator &() const { return s; } 105 const char *operator &() const { return s; }
97 106
98 operator const char *() const { return s == null () ? 0 : s; } 107 operator const char *() const { return s == null () ? 0 : s; }
108
109protected:
110 // dummy is there so it isn't used as type converter accidentally
111 shstr_tmp (int dummy, const char *s)
112 : s(s)
113 {
114 }
99}; 115};
100 116
101inline bool operator ==(const shstr_tmp &a, const shstr_tmp &b) 117inline bool operator ==(const shstr_tmp &a, const shstr_tmp &b)
102{ 118{
103 return a.s == b.s; 119 return a.s == b.s;
106inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b) 122inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b)
107{ 123{
108 return a.s != b.s; 124 return a.s != b.s;
109} 125}
110 126
111inline int strlen (const shstr_tmp &sh) 127inline int strlen (shstr_tmp sh)
112{ 128{
113 return sh.length (); 129 return sh.length ();
114} 130}
115
116// undefined external reference to catch people using strcmp when they shouldn't
117int strcmp (const shstr_tmp &a, const shstr_tmp &b);
118 131
119static std::ostream &operator <<(std::ostream &o, shstr_tmp sh) 132static std::ostream &operator <<(std::ostream &o, shstr_tmp sh)
120{ 133{
121 o.write (sh.s, sh.length ()); 134 o.write (sh.s, sh.length ());
122 135
155 { 168 {
156 ++refcnt (); 169 ++refcnt ();
157 } 170 }
158 171
159 explicit shstr (const char *str) 172 explicit shstr (const char *str)
160 {
161 s = is_constant (str) && !str ? null () : intern (str); 173 : shstr_tmp (0, is_constant (str) && !str ? null () : intern (str))
174 {
162 } 175 }
163 176
164 ~shstr () 177 ~shstr ()
165 { 178 {
166 --refcnt (); 179 --refcnt ();
199// temporary passing, basically a non-refcounted shstr 212// temporary passing, basically a non-refcounted shstr
200struct shstr_cmp 213struct shstr_cmp
201{ 214{
202 const char *s; 215 const char *s;
203 216
217 // initialies to the non-matching string (as opposed to the null string)
218 shstr_cmp ()
219 {
220 s = 0;
221 }
222
204 explicit shstr_cmp (const char *str) 223 shstr_cmp (const char *str)
205 : s (shstr::find (str)) 224 : s (shstr::find (str))
206 { 225 {
207 } 226 }
208 227
209 shstr_cmp (shstr_tmp sh) 228 shstr_cmp (shstr_tmp sh)
225inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b) 244inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b)
226{ 245{
227 return a.s == b.s; 246 return a.s == b.s;
228} 247}
229 248
230#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)
231# include "shstrinc.h" 251# include "shstrinc.h"
232#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);
233 258
234#endif 259#endif
235 260

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines