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.34 by root, Tue Nov 3 23:44:21 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * it under the terms of the GNU General Public License as published by 7 * the terms of the Affero GNU General Public License as published by the
8 * the Free Software Foundation, either version 3 of the License, or 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * (at your option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
18 * 19 *
19 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
20 */ 21 */
21 22
22#ifndef SHSTR_H__ 23#ifndef SHSTR_H__
68 int plen = strlen (prefix); 69 int plen = strlen (prefix);
69 70
70 return length () >= plen && !strncasecmp (s, prefix, plen); 71 return length () >= plen && !strncasecmp (s, prefix, plen);
71 } 72 }
72 73
74 // returns true if the substring is contained in the shstr
75 // if the shstr is 0, then this always returns false.
76 // the shstr is (theoretically) treated as a comma/colon/space etc. separated list.
73 bool contains (const char *substring) const 77 bool contains (const char *substring) const
74 { 78 {
75 return strstr (s, substring); 79 return s != null () && strstr (s, substring);
80 }
81
82 //TODO: case sensitive should be eradicated
83 bool eq_nc (const char *otherstring) const
84 {
85 return !strcasecmp (s, otherstring);
76 } 86 }
77 87
78 shstr_tmp () 88 shstr_tmp ()
79 : s (null ()) 89 : s (null ())
80 { 90 {
113inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b) 123inline bool operator !=(const shstr_tmp &a, const shstr_tmp &b)
114{ 124{
115 return a.s != b.s; 125 return a.s != b.s;
116} 126}
117 127
118inline int strlen (const shstr_tmp &sh) 128inline int strlen (shstr_tmp sh)
119{ 129{
120 return sh.length (); 130 return sh.length ();
121} 131}
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 132
126static std::ostream &operator <<(std::ostream &o, shstr_tmp sh) 133static std::ostream &operator <<(std::ostream &o, shstr_tmp sh)
127{ 134{
128 o.write (sh.s, sh.length ()); 135 o.write (sh.s, sh.length ());
129 136
206// temporary passing, basically a non-refcounted shstr 213// temporary passing, basically a non-refcounted shstr
207struct shstr_cmp 214struct shstr_cmp
208{ 215{
209 const char *s; 216 const char *s;
210 217
218 // initialies to the non-matching string (as opposed to the null string)
219 shstr_cmp ()
220 {
221 s = 0;
222 }
223
211 explicit shstr_cmp (const char *str) 224 shstr_cmp (const char *str)
212 : s (shstr::find (str)) 225 : s (shstr::find (str))
213 { 226 {
214 } 227 }
215 228
216 shstr_cmp (shstr_tmp sh) 229 shstr_cmp (shstr_tmp sh)
232inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b) 245inline bool operator ==(const shstr_tmp &a, const shstr_cmp &b)
233{ 246{
234 return a.s == b.s; 247 return a.s == b.s;
235} 248}
236 249
237#define def(str) extern const shstr shstr_ ## str; 250#define def2(id,str) extern const shstr id;
251#define def(id) def2(shstr_ ## id, # id)
238# include "shstrinc.h" 252# include "shstrinc.h"
239#undef def 253#undef def
254#undef def2
255
256// undefined external reference to catch people using str* functions when they shouldn't
257//template<class any> void strcmp (const shstr_tmp &a, any b);
258template<class any> void strstr (const shstr_tmp &a, any b);
240 259
241#endif 260#endif
242 261

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines