1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
20 #include "inspircd_config.h"
22 /*******************************************************
23 * This file contains classes and templates that deal
24 * with the comparison and hashing of 'irc strings'.
25 * An 'irc string' is a string which compares in a
26 * case insensitive manner, and as per RFC 1459 will
27 * treat [ identical to {, ] identical to }, and \
30 * Our hashing functions are designed to accept
31 * std::string and compare/hash them as type irc::string
32 * by converting them internally. This makes them
33 * backwards compatible with other code which is not
34 * aware of irc::string.
35 *******************************************************/
38 #include <ext/hash_map>
44 #define nspace __gnu_cxx
54 template<> struct hash<in_addr>
56 template<> struct nspace::hash<in_addr>
59 size_t operator()(const struct in_addr &a) const;
62 template<> struct hash<string>
64 template<> struct nspace::hash<string>
67 size_t operator()(const string &s) const;
71 /** The irc namespace contains a number of helper classes.
76 /** This class returns true if two strings match.
77 * Case sensitivity is ignored, and the RFC 'character set'
82 /** The operator () does the actual comparison in hash_map
84 bool operator()(const std::string& s1, const std::string& s2) const;
88 /** This class returns true if two in_addr structs match.
89 * Checking is done by copying both into a size_t then doing a
90 * numeric comparison of the two.
92 struct InAddr_HashComp
94 /** The operator () does the actual comparison in hash_map
96 bool operator()(const in_addr &s1, const in_addr &s2) const;
100 /** The irc_char_traits class is used for RFC-style comparison of strings.
101 * This class is used to implement irc::string, a case-insensitive, RFC-
102 * comparing string class.
104 struct irc_char_traits : std::char_traits<char> {
106 /** Check if two chars match
108 static bool eq(char c1st, char c2nd);
110 /** Check if two chars do NOT match
112 static bool ne(char c1st, char c2nd);
114 /** Check if one char is less than another
116 static bool lt(char c1st, char c2nd);
118 /** Compare two strings of size n
120 static int compare(const char* str1, const char* str2, size_t n);
122 /** Find a char within a string up to position n
124 static const char* find(const char* s1, int n, char c);
127 /** This typedef declares irc::string based upon irc_char_traits
129 typedef basic_string<char, irc_char_traits, allocator<char> > string;