1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/*
* Copyright (C) 2002-2011 InspIRCd Development Team
* Copyright (C) 2008-2011 Anope Team <team@anope.org>
*
* Please read COPYING and README for further details.
*
* These classes have been copied from InspIRCd and modified
* for use in Anope.
*/
#include "services.h"
/*
*
* This is an implementation of two special string classes:
*
* irc::string which is a case-insensitive equivalent to
* std::string which is not only case-insensitive but
* can also do scandanavian comparisons, e.g. { = [, etc.
*
* ci::string which is a case-insensitive equivalent to
* std::string.
*
* These classes depend on rfc_case_insensitive_map and
* ascii_case_insensitive_map
*
*/
/* VS 2008 specific function */
bool Anope::hash::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.str().compare(s2.str()) < 0;
}
/** Hash an Anope::string for unordered_map
* @param s The string
* @return A hash value for the string
*/
bool Anope::hash::operator()(const Anope::string &s) const
{
register size_t t = 0;
for (Anope::string::const_iterator it = s.begin(), it_end = s.end(); it != it_end; ++it)
t = 5 * t + *it;
return t;
}
bool irc::irc_char_traits::eq(char c1st, char c2nd)
{
return rfc_case_insensitive_map[static_cast<unsigned char>(c1st)] == rfc_case_insensitive_map[static_cast<unsigned char>(c2nd)];
}
bool irc::irc_char_traits::ne(char c1st, char c2nd)
{
return rfc_case_insensitive_map[static_cast<unsigned char>(c1st)] != rfc_case_insensitive_map[static_cast<unsigned char>(c2nd)];
}
bool irc::irc_char_traits::lt(char c1st, char c2nd)
{
return rfc_case_insensitive_map[static_cast<unsigned char>(c1st)] < rfc_case_insensitive_map[static_cast<unsigned char>(c2nd)];
}
int irc::irc_char_traits::compare(const char *str1, const char *str2, size_t n)
{
for (unsigned i = 0; i < n; ++i)
{
if (rfc_case_insensitive_map[static_cast<unsigned char>(*str1)] > rfc_case_insensitive_map[static_cast<unsigned char>(*str2)])
return 1;
if (rfc_case_insensitive_map[static_cast<unsigned char>(*str1)] < rfc_case_insensitive_map[static_cast<unsigned char>(*str2)])
return -1;
if (!*str1 || !*str2)
return 0;
++str1;
++str2;
}
return 0;
}
const char *irc::irc_char_traits::find(const char *s1, int n, char c)
{
while (n-- > 0 && rfc_case_insensitive_map[static_cast<unsigned char>(*s1)] != rfc_case_insensitive_map[static_cast<unsigned char>(c)])
++s1;
return n >= 0 ? s1 : NULL;
}
/* VS 2008 specific function */
bool irc::hash::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.irc_str().compare(s2.irc_str()) < 0;
}
/** Hash an irc::string for unordered_map
* @param s The string
* @return A hash value for the string
*/
size_t irc::hash::operator()(const irc::string &s) const
{
register size_t t = 0;
for (irc::string::const_iterator it = s.begin(), it_end = s.end(); it != it_end; ++it)
t = 5 * t + rfc_case_insensitive_map[static_cast<const unsigned char>(*it)];
return t;
}
size_t irc::hash::operator()(const Anope::string &s) const
{
return operator()(s.irc_str());
}
bool ci::ci_char_traits::eq(char c1st, char c2nd)
{
return ascii_case_insensitive_map[static_cast<unsigned char>(c1st)] == ascii_case_insensitive_map[static_cast<unsigned char>(c2nd)];
}
bool ci::ci_char_traits::ne(char c1st, char c2nd)
{
return ascii_case_insensitive_map[static_cast<unsigned char>(c1st)] != ascii_case_insensitive_map[static_cast<unsigned char>(c2nd)];
}
bool ci::ci_char_traits::lt(char c1st, char c2nd)
{
return ascii_case_insensitive_map[static_cast<unsigned char>(c1st)] < ascii_case_insensitive_map[static_cast<unsigned char>(c2nd)];
}
int ci::ci_char_traits::compare(const char *str1, const char *str2, size_t n)
{
for (unsigned i = 0; i < n; ++i)
{
if (ascii_case_insensitive_map[static_cast<unsigned char>(*str1)] > ascii_case_insensitive_map[static_cast<unsigned char>(*str2)])
return 1;
if (ascii_case_insensitive_map[static_cast<unsigned char>(*str1)] < ascii_case_insensitive_map[static_cast<unsigned char>(*str2)])
return -1;
if (!*str1 || !*str2)
return 0;
++str1;
++str2;
}
return 0;
}
const char *ci::ci_char_traits::find(const char *s1, int n, char c)
{
while (n-- > 0 && ascii_case_insensitive_map[static_cast<unsigned char>(*s1)] != ascii_case_insensitive_map[static_cast<unsigned char>(c)])
++s1;
return n >= 0 ? s1 : NULL;
}
/* VS 2008 specific function */
bool ci::hash::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.ci_str().compare(s2.ci_str()) < 0;
}
/** Hash a ci::string for unordered_map
* @param s The string
* @return A hash value for the string
*/
size_t ci::hash::operator()(const ci::string &s) const
{
register size_t t = 0;
for (ci::string::const_iterator it = s.begin(), it_end = s.end(); it != it_end; ++it)
t = 5 * t + ascii_case_insensitive_map[static_cast<const unsigned char>(*it)];
return t;
}
size_t ci::hash::operator()(const Anope::string &s) const
{
return operator()(s.ci_str());
}
/** Compare two Anope::strings as ci::strings
* @param s1 The first string
* @param s2 The second string
* @return true if they are equal
*/
bool std::equal_to<ci::string>::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.ci_str() == s2.ci_str();
}
/** Compare two Anope::strings as irc::strings
* @param s1 The first string
* @param s2 The second string
* @return true if they are equal
*/
bool std::equal_to<irc::string>::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.irc_str() == s2.irc_str();
}
/** Compare two Anope::strings as ci::strings and find which one is less
* @param s1 The first string
* @param s2 The second string
* @return true if s1 < s2, else false
*/
bool std::less<ci::string>::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.ci_str().compare(s2.ci_str()) < 0;
}
/** Compare two Anope::strings as irc::strings and find which one is les
* @param s1 The first string
* @param s2 The second string
* @return true if s1 < s2, else false
*/
bool std::less<irc::string>::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.irc_str().compare(s2.irc_str()) < 0;
}
sepstream::sepstream(const Anope::string &source, char seperator) : tokens(source), sep(seperator)
{
last_starting_position = n = tokens.begin();
}
bool sepstream::GetToken(Anope::string &token)
{
Anope::string::iterator lsp = last_starting_position;
while (n != tokens.end())
{
if (*n == sep || n + 1 == tokens.end())
{
last_starting_position = n + 1;
token = Anope::string(lsp, n + 1 == tokens.end() ? n + 1 : n);
while (token.length() && token.rfind(sep) == token.length() - 1)
token.erase(token.end() - 1);
++n;
return true;
}
++n;
}
token.clear();
return false;
}
const Anope::string sepstream::GetRemaining()
{
return Anope::string(n, tokens.end());
}
bool sepstream::StreamEnd()
{
return n == tokens.end();
}
|