]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/hashcomp.h
Add ascii_case_insensitive_map, thanks MacGyver.
[user/henk/code/inspircd.git] / include / hashcomp.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef _HASHCOMP_H_
15 #define _HASHCOMP_H_
16
17 #include <cstring>
18 #include "hash_map.h"
19
20 /*******************************************************
21  * This file contains classes and templates that deal
22  * with the comparison and hashing of 'irc strings'.
23  * An 'irc string' is a string which compares in a
24  * case insensitive manner, and as per RFC 1459 will
25  * treat [ identical to {, ] identical to }, and \
26  * as identical to |.
27  *
28  * Our hashing functions are designed  to accept
29  * std::string and compare/hash them as type irc::string
30  * by converting them internally. This makes them
31  * backwards compatible with other code which is not
32  * aware of irc::string.
33  *******************************************************/
34
35 #ifndef LOWERMAP
36 #define LOWERMAP
37
38 /** A mapping of uppercase to lowercase, including scandinavian
39  * 'oddities' as specified by RFC1459, e.g. { -> [, and | -> \
40  */
41 unsigned const char rfc_case_insensitive_map[256] = {
42         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,                                   /* 0-19 */
43         20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,                         /* 20-39 */
44         40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,                         /* 40-59 */
45         60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,             /* 60-79 */
46         112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 94, 95, 96, 97, 98, 99,           /* 80-99 */
47         100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,     /* 100-119 */
48         120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,     /* 120-139 */
49         140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,     /* 140-159 */
50         160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,     /* 160-179 */
51         180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,     /* 180-199 */
52         200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,     /* 200-219 */
53         220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,     /* 220-239 */
54         240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255                          /* 240-255 */
55 };
56
57 /** Case insensitive map, ASCII rules.
58  * That is;
59  * [ != {, but A == a.
60  */
61 unsigned const char ascii_case_insensitive_map[256] = {
62         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,                                   /* 0-19 */
63         20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,                         /* 20-39 */
64         40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,                         /* 40-59 */
65         60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,             /* 60-79 */
66         112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,              /* 80-99 */
67         100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,     /* 100-119 */
68         120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,     /* 120-139 */
69         140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,     /* 140-159 */
70         160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,     /* 160-179 */
71         180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,     /* 180-199 */
72         200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,     /* 200-219 */
73         220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,     /* 220-239 */
74         240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255                          /* 240-255 */
75 };
76
77 /** Case sensitive map.
78  * Can technically also be used for ASCII case sensitive comparisons, as [ != {, etc.
79  */
80 unsigned const char rfc_case_sensitive_map[256] = {
81         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
82         21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
83         41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
84         61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
85         81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
86         101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
87         121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
88         141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
89         161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
90         181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
91         201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
92         221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
93         241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
94 };
95
96 #endif
97
98 /** The irc namespace contains a number of helper classes.
99  */
100 namespace irc
101 {
102
103         /** This class returns true if two strings match.
104          * Case sensitivity is ignored, and the RFC 'character set'
105          * is adhered to
106          */
107         struct StrHashComp
108         {
109                 /** The operator () does the actual comparison in hash_map
110                  */
111                 bool operator()(const std::string& s1, const std::string& s2) const;
112         };
113
114         /** The irc_char_traits class is used for RFC-style comparison of strings.
115          * This class is used to implement irc::string, a case-insensitive, RFC-
116          * comparing string class.
117          */
118         struct irc_char_traits : std::char_traits<char> {
119
120                 /** Check if two chars match.
121                  * @param c1st First character
122                  * @param c2nd Second character
123                  * @return true if the characters are equal
124                  */
125                 static bool eq(char c1st, char c2nd);
126
127                 /** Check if two chars do NOT match.
128                  * @param c1st First character
129                  * @param c2nd Second character
130                  * @return true if the characters are unequal
131                  */
132                 static bool ne(char c1st, char c2nd);
133
134                 /** Check if one char is less than another.
135                  * @param c1st First character
136                  * @param c2nd Second character
137                  * @return true if c1st is less than c2nd
138                  */
139                 static bool lt(char c1st, char c2nd);
140
141                 /** Compare two strings of size n.
142                  * @param str1 First string
143                  * @param str2 Second string
144                  * @param n Length to compare to
145                  * @return similar to strcmp, zero for equal, less than zero for str1
146                  * being less and greater than zero for str1 being greater than str2.
147                  */
148                 static CoreExport int compare(const char* str1, const char* str2, size_t n);
149
150                 /** Find a char within a string up to position n.
151                  * @param s1 String to find in
152                  * @param n Position to search up to
153                  * @param c Character to search for
154                  * @return Pointer to the first occurance of c in s1
155                  */
156                 static CoreExport const char* find(const char* s1, int  n, char c);
157         };
158
159         /** Compose a hex string from raw data.
160          * @param raw The raw data to compose hex from
161          * @pram rawsz The size of the raw data buffer
162          * @return The hex string.
163          */
164         CoreExport std::string hex(const unsigned char *raw, size_t rawsz);
165
166         /** This typedef declares irc::string based upon irc_char_traits.
167          */
168         typedef std::basic_string<char, irc_char_traits, std::allocator<char> > string;
169
170         /** irc::stringjoiner joins string lists into a string, using
171          * the given seperator string.
172          * This class can join a vector of std::string, a deque of
173          * std::string, or a const char* const* array, using overloaded
174          * constructors.
175          */
176         class CoreExport stringjoiner : public classbase
177         {
178          private:
179
180                 /** Output string
181                  */
182                 std::string joined;
183
184          public:
185
186                 /** Join elements of a vector, between (and including) begin and end
187                  * @param seperator The string to seperate values with
188                  * @param sequence One or more items to seperate
189                  * @param begin The starting element in the sequence to be joined
190                  * @param end The ending element in the sequence to be joined
191                  */
192                 stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end);
193
194                 /** Join elements of a deque, between (and including) begin and end
195                  * @param seperator The string to seperate values with
196                  * @param sequence One or more items to seperate
197                  * @param begin The starting element in the sequence to be joined
198                  * @param end The ending element in the sequence to be joined
199                  */
200                 stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end);
201
202                 /** Join elements of an array of char arrays, between (and including) begin and end
203                  * @param seperator The string to seperate values with
204                  * @param sequence One or more items to seperate
205                  * @param begin The starting element in the sequence to be joined
206                  * @param end The ending element in the sequence to be joined
207                  */
208                 stringjoiner(const std::string &seperator, const char* const* sequence, int begin, int end);
209
210                 /** Get the joined sequence
211                  * @return A reference to the joined string
212                  */
213                 std::string& GetJoined();
214         };
215
216         /** irc::modestacker stacks mode sequences into a list.
217          * It can then reproduce this list, clamped to a maximum of MAXMODES
218          * values per line.
219          */
220         class CoreExport modestacker : public classbase
221         {
222          private:
223                 InspIRCd* ServerInstance;
224
225                 /** The mode sequence and its parameters
226                  */
227                 std::deque<std::string> sequence;
228
229                 /** True if the mode sequence is initially adding
230                  * characters, false if it is initially removing
231                  * them
232                  */
233                 bool adding;
234          public:
235
236                 /** Construct a new modestacker.
237                  * @param add True if the stack is adding modes,
238                  * false if it is removing them
239                  */
240                 modestacker(InspIRCd* Instance, bool add);
241
242                 /** Push a modeletter and its parameter onto the stack.
243                  * No checking is performed as to if this mode actually
244                  * requires a parameter. If you stack invalid mode
245                  * sequences, they will be tidied if and when they are
246                  * passed to a mode parser.
247                  * @param modeletter The mode letter to insert
248                  * @param parameter The parameter for the mode
249                  */
250                 void Push(char modeletter, const std::string &parameter);
251
252                 /** Push a modeletter without parameter onto the stack.
253                  * No checking is performed as to if this mode actually
254                  * requires a parameter. If you stack invalid mode
255                  * sequences, they will be tidied if and when they are
256                  * passed to a mode parser.
257                  * @param modeletter The mode letter to insert
258                  */
259                 void Push(char modeletter);
260         
261                 /** Push a '+' symbol onto the stack.
262                  */
263                 void PushPlus();
264         
265                 /** Push a '-' symbol onto the stack.
266                  */
267                 void PushMinus();
268                 
269                 /** Return zero or more elements which form the
270                  * mode line. This will be clamped to a max of
271                  * MAXMODES items (MAXMODES-1 mode parameters and
272                  * one mode sequence string), and max_line_size
273                  * characters. As specified below, this function
274                  * should be called in a loop until it returns zero,
275                  * indicating there are no more modes to return.
276                  * @param result The deque to populate. This will
277                  * be cleared before it is used.
278                  * @param max_line_size The maximum size of the line
279                  * to build, in characters, seperate to MAXMODES.
280                  * @return The number of elements in the deque.
281                  * The function should be called repeatedly until it
282                  * returns 0, in case there are multiple lines of
283                  * mode changes to be obtained.
284                  */
285                 int GetStackedLine(std::deque<std::string> &result, int max_line_size = 360);
286         };
287
288         /** irc::tokenstream reads a string formatted as per RFC1459 and RFC2812.
289          * It will split the string into 'tokens' each containing one parameter
290          * from the string.
291          * For instance, if it is instantiated with the string:
292          * "PRIVMSG #test :foo bar baz qux"
293          * then each successive call to tokenstream::GetToken() will return
294          * "PRIVMSG", "#test", "foo bar baz qux", "".
295          * Note that if the whole string starts with a colon this is not taken
296          * to mean the string is all one parameter, and the first item in the
297          * list will be ":item". This is to allow for parsing 'source' fields
298          * from data.
299          */
300         class CoreExport tokenstream : public classbase
301         {
302          private:
303         
304                 /** Original string
305                  */
306                 std::string tokens;
307
308                 /** Last position of a seperator token
309                  */
310                 std::string::iterator last_starting_position;
311
312                 /** Current string position
313                  */
314                 std::string::iterator n;
315
316                 /** True if the last value was an ending value
317                  */
318                 bool last_pushed;
319          public:
320
321                 /** Create a tokenstream and fill it with the provided data
322                  */
323                 tokenstream(const std::string &source);
324
325                 /** Destructor
326                  */
327                 ~tokenstream();
328
329                 /** Fetch the next token from the stream as a std::string
330                  * @param token The next token available, or an empty string if none remain
331                  * @return True if tokens are left to be read, false if the last token was just retrieved.
332                  */
333                 bool GetToken(std::string &token);
334
335                 /** Fetch the next token from the stream as an irc::string
336                  * @param token The next token available, or an empty string if none remain
337                  * @return True if tokens are left to be read, false if the last token was just retrieved.
338                  */
339                 bool GetToken(irc::string &token);
340
341                 /** Fetch the next token from the stream as an integer
342                  * @param token The next token available, or undefined if none remain
343                  * @return True if tokens are left to be read, false if the last token was just retrieved.
344                  */
345                 bool GetToken(int &token);
346
347                 /** Fetch the next token from the stream as a long integer
348                  * @param token The next token available, or undefined if none remain
349                  * @return True if tokens are left to be read, false if the last token was just retrieved.
350                  */
351                 bool GetToken(long &token);
352         };
353
354         /** irc::sepstream allows for splitting token seperated lists.
355          * Each successive call to sepstream::GetToken() returns
356          * the next token, until none remain, at which point the method returns
357          * an empty string.
358          */
359         class CoreExport sepstream : public classbase
360         {
361          private:
362                 /** Original string.
363                  */
364                 std::string tokens;
365                 /** Last position of a seperator token
366                  */
367                 std::string::iterator last_starting_position;
368                 /** Current string position
369                  */
370                 std::string::iterator n;
371                 /** Seperator value
372                  */
373                 char sep;
374          public:
375                 /** Create a sepstream and fill it with the provided data
376                  */
377                 sepstream(const std::string &source, char seperator);
378
379                 /** Destructor
380                  */
381                 virtual ~sepstream();
382
383                 /** Fetch the next token from the stream
384                  * @param token The next token from the stream is placed here
385                  * @return True if tokens still remain, false if there are none left
386                  */
387                 virtual bool GetToken(std::string &token);
388
389                 /** Fetch the entire remaining stream, without tokenizing
390                  * @return The remaining part of the stream
391                  */
392                 virtual const std::string GetRemaining();
393
394                 /** Returns true if the end of the stream has been reached
395                  * @return True if the end of the stream has been reached, otherwise false
396                  */
397                 virtual bool StreamEnd();
398         };
399
400         /** A derived form of sepstream, which seperates on commas
401          */
402         class CoreExport commasepstream : public sepstream
403         {
404          public:
405                 /** Initialize with comma seperator
406                  */
407                 commasepstream(const std::string &source) : sepstream(source, ',')
408                 {
409                 }
410         };
411
412         /** A derived form of sepstream, which seperates on spaces
413          */
414         class CoreExport spacesepstream : public sepstream
415         {
416          public:
417                 /** Initialize with space seperator
418                  */
419                 spacesepstream(const std::string &source) : sepstream(source, ' ')
420                 {
421                 }
422         };
423
424         /** The portparser class seperates out a port range into integers.
425          * A port range may be specified in the input string in the form
426          * "6660,6661,6662-6669,7020". The end of the stream is indicated by
427          * a return value of 0 from portparser::GetToken(). If you attempt
428          * to specify an illegal range (e.g. one where start >= end, or
429          * start or end < 0) then GetToken() will return the first element
430          * of the pair of numbers.
431          */
432         class CoreExport portparser : public classbase
433         {
434          private:
435
436                 /** Used to split on commas
437                  */
438                 commasepstream* sep;
439         
440                 /** Current position in a range of ports
441                  */
442                 long in_range;
443         
444                 /** Starting port in a range of ports
445                  */
446                 long range_begin;
447         
448                 /** Ending port in a range of ports
449                  */
450                 long range_end;
451         
452                 /** Allow overlapped port ranges
453                  */
454                 bool overlapped;
455         
456                 /** Used to determine overlapping of ports
457                  * without O(n) algorithm being used
458                  */
459                 std::map<long, bool> overlap_set;
460         
461                 /** Returns true if val overlaps an existing range
462                  */
463                 bool Overlaps(long val);
464          public:
465         
466                 /** Create a portparser and fill it with the provided data
467                  * @param source The source text to parse from
468                  * @param allow_overlapped Allow overlapped ranges
469                  */
470                 portparser(const std::string &source, bool allow_overlapped = true);
471         
472                 /** Frees the internal commasepstream object
473                  */
474                 ~portparser();
475         
476                 /** Fetch the next token from the stream
477                  * @return The next port number is returned, or 0 if none remain
478                  */
479                 long GetToken();
480         };
481
482         /** Turn _ characters in a string into spaces
483          * @param n String to translate
484          * @return The new value with _ translated to space.
485          */
486         CoreExport const char* Spacify(const char* n);
487 }
488
489 /* Define operators for using >> and << with irc::string to an ostream on an istream. */
490 /* This was endless fun. No. Really. */
491 /* It was also the first core change Ommeh made, if anyone cares */
492
493 /** Operator << for irc::string
494  */
495 inline std::ostream& operator<<(std::ostream &os, const irc::string &str) { return os << str.c_str(); }
496
497 /** Operator >> for irc::string
498  */
499 inline std::istream& operator>>(std::istream &is, irc::string &str)
500 {
501         std::string tmp;
502         is >> tmp;
503         str = tmp.c_str();
504         return is;
505 }
506
507 /* Define operators for + and == with irc::string to std::string for easy assignment
508  * and comparison
509  *
510  * Operator +
511  */
512 inline std::string operator+ (std::string& leftval, irc::string& rightval)
513 {
514         return leftval + std::string(rightval.c_str());
515 }
516
517 /* Define operators for + and == with irc::string to std::string for easy assignment
518  * and comparison
519  *
520  * Operator +
521  */
522 inline irc::string operator+ (irc::string& leftval, std::string& rightval)
523 {
524         return leftval + irc::string(rightval.c_str());
525 }
526
527 /* Define operators for + and == with irc::string to std::string for easy assignment
528  * and comparison
529  *
530  * Operator ==
531  */
532 inline bool operator== (const std::string& leftval, const irc::string& rightval)
533 {
534         return (leftval.c_str() == rightval);
535 }
536
537 /* Define operators for + and == with irc::string to std::string for easy assignment
538  * and comparison
539  *
540  * Operator ==
541  */
542 inline bool operator== (const irc::string& leftval, const std::string& rightval)
543 {
544         return (leftval == rightval.c_str());
545 }
546
547 /* Define operators != for irc::string to std::string for easy comparison
548  */
549 inline bool operator!= (const irc::string& leftval, const std::string& rightval)
550 {
551         return !(leftval == rightval.c_str());
552 }
553
554 /* Define operators != for std::string to irc::string for easy comparison
555  */
556 inline bool operator!= (const std::string& leftval, const irc::string& rightval)
557 {
558         return !(leftval.c_str() == rightval);
559 }
560
561 // FIXME MAXBUF messes up these
562 #if 0
563 template<std::size_t N>
564 static inline bool operator == (std::string const &lhs, char const (&rhs)[N])
565 {
566         return lhs.length() == N - 1 && !std::memcmp(lhs.data(), rhs, N - 1);
567 }
568
569 template<std::size_t N>
570 static inline bool operator != (std::string const &lhs, char const (&rhs)[N])
571 {
572         return !(lhs == rhs);
573 }
574 #endif
575
576 /** Assign an irc::string to a std::string.
577  */
578 inline std::string assign(const irc::string &other) { return other.c_str(); }
579
580 /** Assign a std::string to an irc::string.
581  */
582 inline irc::string assign(const std::string &other) { return other.c_str(); }
583
584 /** Trim the leading and trailing spaces from a std::string.
585  */
586 inline std::string& trim(std::string &str)
587 {
588         std::string::size_type start = str.find_first_not_of(" ");
589         std::string::size_type end = str.find_last_not_of(" ");
590         if (start == std::string::npos || end == std::string::npos)
591                 str = "";
592         else
593                 str = str.substr(start, end-start+1);
594
595         return str;
596 }
597
598 /** Hashing stuff is totally different on vc++'s hash_map implementation, so to save a buttload of
599  * #ifdefs we'll just do it all at once
600  */
601 BEGIN_HASHMAP_NAMESPACE
602
603         /** Hashing function to hash irc::string
604          */
605 #ifdef WINDOWS
606         template<> class CoreExport hash_compare<irc::string, std::less<irc::string> >
607         {
608         public:
609                 enum { bucket_size = 4, min_buckets = 8 }; /* Got these numbers from the CRT source, if anyone wants to change them feel free. */
610
611                 /** Compare two irc::string values for hashing in hash_map
612                  */
613                 bool operator()(const irc::string & s1, const irc::string & s2) const
614                 {
615                         if(s1.length() != s2.length()) return true;
616                         return (irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), (size_t)s1.length()) < 0);
617                 }
618
619                 /** Hash an irc::string value for hash_map
620                  */
621                 size_t operator()(const irc::string & s) const;
622         };
623
624         template<> class CoreExport hash_compare<std::string, std::less<std::string> >
625         {
626         public:
627                 enum { bucket_size = 4, min_buckets = 8 }; /* Again, from the CRT source */
628
629                 /** Compare two std::string values for hashing in hash_map
630                  */
631                 bool operator()(const std::string & s1, const std::string & s2) const
632                 {
633                         if(s1.length() != s2.length()) return true;
634                         return (irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), (size_t)s1.length()) < 0);
635                 }
636
637                 /** Hash a std::string using RFC1459 case sensitivity rules
638                 * @param s A string to hash
639                 * @return The hash value
640                 */
641                 size_t operator()(const std::string & s) const;
642         };
643 #else
644
645         template<> struct hash<irc::string>
646         {
647                 /** Hash an irc::string using RFC1459 case sensitivity rules
648                  * @param s A string to hash
649                  * @return The hash value
650                  */
651                 size_t operator()(const irc::string &s) const;
652         };
653
654         /* XXX FIXME: Implement a hash function overriding std::string's that works with TR1! */
655
656 #ifdef HASHMAP_DEPRECATED
657         struct insensitive
658 #else
659         template<> struct hash<std::string>
660 #endif
661         {
662                 size_t operator()(const std::string &s) const;
663         };
664
665 #endif
666
667         /** Convert a string to lower case respecting RFC1459
668         * @param n A string to lowercase
669         */
670         void strlower(char *n);
671
672 END_HASHMAP_NAMESPACE
673
674 #endif
675