1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 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"
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 \
28 * as identical to |. Our hashing functions are designed
29 * to accept std::string and compare/hash them in an irc
30 * type way, irc::string is a seperate class type currently.
34 #include <ext/hash_map>
40 #define nspace __gnu_cxx
50 template<> struct hash<in_addr>
52 template<> struct nspace::hash<in_addr>
55 size_t operator()(const struct in_addr &a) const;
58 template<> struct hash<string>
60 template<> struct nspace::hash<string>
63 size_t operator()(const string &s) const;
67 /** The irc namespace contains a number of helper classes.
72 /** This class returns true if two strings match.
73 * Case sensitivity is ignored, and the RFC 'character set'
78 /** The operator () does the actual comparison in hash_map
80 bool operator()(const std::string& s1, const std::string& s2) const;
84 /** This class returns true if two in_addr structs match.
85 * Checking is done by copying both into a size_t then doing a
86 * numeric comparison of the two.
88 struct InAddr_HashComp
90 /** The operator () does the actual comparison in hash_map
92 bool operator()(const in_addr &s1, const in_addr &s2) const;
96 /** The irc_char_traits class is used for RFC-style comparison of strings.
97 * This class is used to implement irc::string, a case-insensitive, RFC-
98 * comparing string class.
100 struct irc_char_traits : std::char_traits<char> {
102 /** Check if two chars match
104 static bool eq(char c1st, char c2nd);
106 /** Check if two chars do NOT match
108 static bool ne(char c1st, char c2nd);
110 /** Check if one char is less than another
112 static bool lt(char c1st, char c2nd);
114 /** Compare two strings of size n
116 static int compare(const char* str1, const char* str2, size_t n);
118 /** Find a char within a string up to position n
120 static const char* find(const char* s1, int n, char c);
123 /** This typedef declares irc::string based upon irc_char_traits
125 typedef basic_string<char, irc_char_traits, allocator<char> > string;