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.10 by root, Tue Sep 12 18:15:34 2006 UTC vs.
Revision 1.13 by root, Mon Apr 23 15:27:46 2007 UTC

1#ifndef SHSTR_H__ 1#ifndef SHSTR_H__
2#define SHSTR_H__ 2#define SHSTR_H__
3
4#include <sstream>
3 5
4#include "util.h" 6#include "util.h"
5 7
6extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); 8extern int buf_overflow (const char *buf1, const char *buf2, int bufsize);
7 9
99inline int strlen (const shstr &sh) 101inline int strlen (const shstr &sh)
100{ 102{
101 return sh.length (); 103 return sh.length ();
102} 104}
103 105
106inline int strcmp (const shstr &a, const shstr &b)
107{
108 // TODO: use this to find all the occurences of people using strcmp
109 // all uses should be bogus, as we should be never interested in
110 // comparing shstr's alphabetically
111#if 0
112 extern void do_not_use_strcmp_to_compare_shstr_values ();
113 do_not_use_strcmp_to_compare_shstr_values ();
114#endif
115 return a != b;
116}
117
118std::ostream &operator <<(std::ostream &o, const shstr &sh)
119{
120 o.write (sh.s, sh.length ());
121 return o;
122}
123
104// only good for mass comparisons to shstr objects 124// only good for mass comparisons to shstr objects
105struct shstr_cmp 125struct shstr_cmp
106{ 126{
107 const char *s; 127 const char *s;
108 128
109 explicit shstr_cmp (const char *s) 129 explicit shstr_cmp (const char *s)
110 : s (shstr::find (s)) 130 : s (shstr::find (s))
111 { 131 {
112 } 132 }
113 133
134 shstr_cmp (const shstr_cmp &sh)
135 : s (sh.s)
136 {
137 }
138
139 shstr_cmp &operator =(const shstr_cmp sh) { s = sh.s; return *this; }
114 operator const char *() const { return s; } 140 operator const char *() const { return s; }
115}; 141};
116 142
117inline bool operator ==(const shstr_cmp &a, const shstr &b) 143inline bool operator ==(const shstr_cmp &a, const shstr &b)
118{ 144{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines