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 | |
6 | extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); |
8 | extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); |
7 | |
9 | |
… | |
… | |
27 | } |
29 | } |
28 | |
30 | |
29 | int length () const |
31 | int length () const |
30 | { |
32 | { |
31 | return length (s); |
33 | return length (s); |
|
|
34 | } |
|
|
35 | |
|
|
36 | // returns wether this shared string begins with the given prefix, |
|
|
37 | // used mainly for searched when users give only the start of a name. |
|
|
38 | bool begins_with (const char *prefix) const |
|
|
39 | { |
|
|
40 | int plen = strlen (prefix); |
|
|
41 | return !strncasecmp (s, prefix, plen) && length () >= plen; |
32 | } |
42 | } |
33 | |
43 | |
34 | static const char *find (const char *s); |
44 | static const char *find (const char *s); |
35 | static const char *intern (const char *s); |
45 | static const char *intern (const char *s); |
36 | |
46 | |
… | |
… | |
111 | do_not_use_strcmp_to_compare_shstr_values (); |
121 | do_not_use_strcmp_to_compare_shstr_values (); |
112 | #endif |
122 | #endif |
113 | return a != b; |
123 | return a != b; |
114 | } |
124 | } |
115 | |
125 | |
|
|
126 | static std::ostream &operator <<(std::ostream &o, const shstr &sh) |
|
|
127 | { |
|
|
128 | o.write (sh.s, sh.length ()); |
|
|
129 | return o; |
|
|
130 | } |
|
|
131 | |
116 | // only good for mass comparisons to shstr objects |
132 | // only good for mass comparisons to shstr objects |
117 | struct shstr_cmp |
133 | struct shstr_cmp |
118 | { |
134 | { |
119 | const char *s; |
135 | const char *s; |
120 | |
136 | |