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"
24 /*******************************************************
25 * This file contains classes and templates that deal
26 * with the comparison and hashing of 'irc strings'.
27 * An 'irc string' is a string which compares in a
28 * case insensitive manner, and as per RFC 1459 will
29 * treat [ identical to {, ] identical to }, and \
32 * Our hashing functions are designed to accept
33 * std::string and compare/hash them as type irc::string
34 * by converting them internally. This makes them
35 * backwards compatible with other code which is not
36 * aware of irc::string.
37 *******************************************************/
43 template<> struct hash<in_addr>
45 size_t operator()(const struct in_addr &a) const;
48 template<> struct hash<std::string>
50 size_t operator()(const string &s) const;
54 /** The irc namespace contains a number of helper classes.
59 /** This class returns true if two strings match.
60 * Case sensitivity is ignored, and the RFC 'character set'
65 /** The operator () does the actual comparison in hash_map
67 bool operator()(const std::string& s1, const std::string& s2) const;
71 /** This class returns true if two in_addr structs match.
72 * Checking is done by copying both into a size_t then doing a
73 * numeric comparison of the two.
75 struct InAddr_HashComp
77 /** The operator () does the actual comparison in hash_map
79 bool operator()(const in_addr &s1, const in_addr &s2) const;
86 std::string::iterator last_starting_position;
87 std::string::iterator n;
90 tokenstream(const std::string &source);
93 const std::string GetToken();
97 /** The irc_char_traits class is used for RFC-style comparison of strings.
98 * This class is used to implement irc::string, a case-insensitive, RFC-
99 * comparing string class.
101 struct irc_char_traits : std::char_traits<char> {
103 /** Check if two chars match
105 static bool eq(char c1st, char c2nd);
107 /** Check if two chars do NOT match
109 static bool ne(char c1st, char c2nd);
111 /** Check if one char is less than another
113 static bool lt(char c1st, char c2nd);
115 /** Compare two strings of size n
117 static int compare(const char* str1, const char* str2, size_t n);
119 /** Find a char within a string up to position n
121 static const char* find(const char* s1, int n, char c);
124 /** This typedef declares irc::string based upon irc_char_traits
126 typedef basic_string<char, irc_char_traits, allocator<char> > string;
129 /* Define operators for using >> and << with irc::string to an ostream on an istream. */
130 /* This was endless fun. No. Really. */
131 /* It was also the first core change Ommeh made, if anyone cares */
133 std::ostream& operator<<(std::ostream &os, const irc::string &str);
134 std::istream& operator>>(std::istream &is, irc::string &str);
136 /* Define operators for + and == with irc::string to std::string for easy assignment
137 * and comparison - Brain
140 std::string operator+ (std::string& leftval, irc::string& rightval);
141 irc::string operator+ (irc::string& leftval, std::string& rightval);
142 bool operator== (std::string& leftval, irc::string& rightval);
143 bool operator== (irc::string& leftval, std::string& rightval);