… | |
… | |
74 | |
74 | |
75 | const shstr &operator =(const char *str) |
75 | const shstr &operator =(const char *str) |
76 | { |
76 | { |
77 | --refcnt (); |
77 | --refcnt (); |
78 | |
78 | |
79 | #if 0 |
|
|
80 | // this optimises the important case of str == constant 0 |
79 | // this optimises the important case of str == constant 0 |
81 | if (is_constant (str)) |
80 | if (is_constant (str)) |
82 | s = str ? intern (str) : null; |
81 | s = str ? intern (str) : null; |
83 | else |
82 | else |
84 | #endif |
|
|
85 | s = intern (str); |
83 | s = intern (str); |
86 | |
84 | |
87 | return *this; |
85 | return *this; |
|
|
86 | } |
|
|
87 | |
|
|
88 | bool operator ==(const shstr &b) |
|
|
89 | { |
|
|
90 | return s == b.s; |
|
|
91 | } |
|
|
92 | |
|
|
93 | bool operator !=(const shstr &b) |
|
|
94 | { |
|
|
95 | return !(*this == b); |
88 | } |
96 | } |
89 | }; |
97 | }; |
90 | |
98 | |
91 | inline int strlen (const shstr &sh) |
99 | inline int strlen (const shstr &sh) |
92 | { |
100 | { |
93 | return sh.length (); |
101 | return sh.length (); |
94 | } |
102 | } |
95 | |
103 | |
|
|
104 | inline int strcmp (const shstr &a, const shstr &b) |
|
|
105 | { |
|
|
106 | // TODO: use this to find all the occurences of people using strcmp |
|
|
107 | // all uses should be bogus, as we should be never interested in |
|
|
108 | // comparing shstr's alphabetically |
|
|
109 | #if 0 |
|
|
110 | extern void do_not_use_strcmp_to_compare_shstr_values (); |
|
|
111 | do_not_use_strcmp_to_compare_shstr_values (); |
|
|
112 | #endif |
|
|
113 | return a != b; |
|
|
114 | } |
|
|
115 | |
|
|
116 | // only good for mass comparisons to shstr objects |
|
|
117 | struct shstr_cmp |
|
|
118 | { |
|
|
119 | const char *s; |
|
|
120 | |
|
|
121 | explicit shstr_cmp (const char *s) |
|
|
122 | : s (shstr::find (s)) |
|
|
123 | { |
|
|
124 | } |
|
|
125 | |
|
|
126 | shstr_cmp (const shstr_cmp &sh) |
|
|
127 | : s (sh.s) |
|
|
128 | { |
|
|
129 | } |
|
|
130 | |
|
|
131 | shstr_cmp &operator =(const shstr_cmp sh) { s = sh.s; return *this; } |
|
|
132 | operator const char *() const { return s; } |
|
|
133 | }; |
|
|
134 | |
96 | inline bool operator ==(const shstr &a, const shstr &b) |
135 | inline bool operator ==(const shstr_cmp &a, const shstr &b) |
97 | { |
136 | { |
98 | return a.s == b.s; |
137 | return a.s == b.s; |
99 | } |
138 | } |
100 | |
139 | |
101 | inline bool operator !=(const shstr &a, const shstr &b) |
140 | inline bool operator ==(const shstr &a, const shstr_cmp &b) |
102 | { |
141 | { |
103 | return !(a == b); |
142 | return b == a; |
104 | } |
143 | } |
|
|
144 | |
|
|
145 | extern const shstr undead_name; /* Used in hit_player() in main.c */ |
105 | |
146 | |
106 | #endif |
147 | #endif |
107 | |
148 | |