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.31 by root, Thu Jan 1 19:42:43 2009 UTC

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 {
94 100
95 // this is used for informational messages and the like 101 // this is used for informational messages and the like
96 const char *operator &() const { return s; } 102 const char *operator &() const { return s; }
97 103
98 operator const char *() const { return s == null () ? 0 : s; } 104 operator const char *() const { return s == null () ? 0 : s; }
105
106protected:
107 // dummy is there so it isn't used as type converter accidentally
108 shstr_tmp (int dummy, const char *s)
109 : s(s)
110 {
111 }
99}; 112};
100 113
101inline bool operator ==(const shstr_tmp &a, const shstr_tmp &b) 114inline bool operator ==(const shstr_tmp &a, const shstr_tmp &b)
102{ 115{
103 return a.s == b.s; 116 return a.s == b.s;
106inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b) 119inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b)
107{ 120{
108 return a.s != b.s; 121 return a.s != b.s;
109} 122}
110 123
111inline int strlen (const shstr_tmp &sh) 124inline int strlen (shstr_tmp sh)
112{ 125{
113 return sh.length (); 126 return sh.length ();
114} 127}
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 128
119static std::ostream &operator <<(std::ostream &o, shstr_tmp sh) 129static std::ostream &operator <<(std::ostream &o, shstr_tmp sh)
120{ 130{
121 o.write (sh.s, sh.length ()); 131 o.write (sh.s, sh.length ());
122 132
155 { 165 {
156 ++refcnt (); 166 ++refcnt ();
157 } 167 }
158 168
159 explicit shstr (const char *str) 169 explicit shstr (const char *str)
160 {
161 s = is_constant (str) && !str ? null () : intern (str); 170 : shstr_tmp (0, is_constant (str) && !str ? null () : intern (str))
171 {
162 } 172 }
163 173
164 ~shstr () 174 ~shstr ()
165 { 175 {
166 --refcnt (); 176 --refcnt ();
199// temporary passing, basically a non-refcounted shstr 209// temporary passing, basically a non-refcounted shstr
200struct shstr_cmp 210struct shstr_cmp
201{ 211{
202 const char *s; 212 const char *s;
203 213
214 // initialies to the non-matching string (as opposed to the null string)
215 shstr_cmp ()
216 {
217 s = 0;
218 }
219
204 explicit shstr_cmp (const char *str) 220 shstr_cmp (const char *str)
205 : s (shstr::find (str)) 221 : s (shstr::find (str))
206 { 222 {
207 } 223 }
208 224
209 shstr_cmp (shstr_tmp sh) 225 shstr_cmp (shstr_tmp sh)
225inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b) 241inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b)
226{ 242{
227 return a.s == b.s; 243 return a.s == b.s;
228} 244}
229 245
230#define def(str) extern const shstr shstr_ ## str; 246#define def2(id,str) extern const shstr id;
247#define def(id) def2(shstr_ ## id, # id)
231# include "shstrinc.h" 248# include "shstrinc.h"
232#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);
254template<class any> void strstr (const shstr_tmp &a, any b);
233 255
234#endif 256#endif
235 257

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines