Anope IRC Services  Version 2.0
hashcomp.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2002-2011 InspIRCd Development Team
4  * Copyright (C) 2009-2014 Anope Team <team@anope.org>
5  *
6  * Please read COPYING and README for further details.
7  *
8  */
9 
10 #ifndef HASHCOMP_H
11 #define HASHCOMP_H
12 
13 #include <string>
14 #include <locale>
15 
16 #if defined _LIBCPP_VERSION || defined _WIN32
17 #include <unordered_map>
18 #define TR1NS std
19 #else
20 #include <tr1/unordered_map>
21 #define TR1NS std::tr1
22 #endif
23 
24 #include "services.h"
25 
26 namespace Anope
27 {
28  class string;
29 
30  /* Casemap in use by Anope. ci::string's comparation functions use this (and thus Anope::string) */
31  extern std::locale casemap;
32 
33  extern void CaseMapRebuild();
34  extern unsigned char tolower(unsigned char);
35  extern unsigned char toupper(unsigned char);
36 
37  /* ASCII case insensitive ctype. */
38  template<typename char_type>
39  class ascii_ctype : public std::ctype<char_type>
40  {
41  public:
42  char_type do_toupper(char_type c) const anope_override
43  {
44  if (c >= 'a' && c <= 'z')
45  return c - 32;
46  else
47  return c;
48  }
49 
50  char_type do_tolower(char_type c) const anope_override
51  {
52  if (c >= 'A' && c <= 'Z')
53  return c + 32;
54  else
55  return c;
56  }
57  };
58 
59  /* rfc1459 case insensitive ctype, { = [, } = ], and | = \ */
60  template<typename char_type>
61  class rfc1459_ctype : public ascii_ctype<char_type>
62  {
63  public:
64  char_type do_toupper(char_type c) const anope_override
65  {
66  if (c == '{' || c == '}' || c == '|')
67  return c - 32;
68  else
70  }
71 
72  char_type do_tolower(char_type c) const anope_override
73  {
74  if (c == '[' || c == ']' || c == '\\')
75  return c + 32;
76  else
78  }
79  };
80 }
81 
84 namespace ci
85 {
90  struct CoreExport ci_char_traits : std::char_traits<char>
91  {
97  static bool eq(char c1st, char c2nd);
98 
104  static bool ne(char c1st, char c2nd);
105 
111  static bool lt(char c1st, char c2nd);
112 
120  static int compare(const char *str1, const char *str2, size_t n);
121 
128  static const char *find(const char *s1, int n, char c);
129  };
130 
133  typedef std::basic_string<char, ci_char_traits, std::allocator<char> > string;
134 
136  {
142  bool operator()(const Anope::string &s1, const Anope::string &s2) const;
143  };
144 }
145 
146 /* Define operators for + and == with ci::string to std::string for easy assignment
147  * and comparison
148  *
149  * Operator +
150  */
151 inline std::string operator+(std::string &leftval, ci::string &rightval)
152 {
153  return leftval + std::string(rightval.c_str());
154 }
155 
156 /* Define operators for + and == with ci::string to std::string for easy assignment
157  * and comparison
158  *
159  * Operator +
160  */
161 inline ci::string operator+(ci::string &leftval, std::string &rightval)
162 {
163  return leftval + ci::string(rightval.c_str());
164 }
165 
166 /* Define operators for + and == with ci::string to std::string for easy assignment
167  * and comparison
168  *
169  * Operator ==
170  */
171 inline bool operator==(const std::string &leftval, const ci::string &rightval)
172 {
173  return leftval.c_str() == rightval;
174 }
175 
176 /* Define operators for + and == with ci::string to std::string for easy assignment
177  * and comparison
178  *
179  * Operator ==
180  */
181 inline bool operator==(const ci::string &leftval, const std::string &rightval)
182 {
183  return leftval == rightval.c_str();
184 }
185 
186 /* Define operators != for ci::string to std::string for easy comparison
187  */
188 inline bool operator!=(const ci::string &leftval, const std::string &rightval)
189 {
190  return !(leftval == rightval.c_str());
191 }
192 
193 /* Define operators != for std::string to ci::string for easy comparison
194  */
195 inline bool operator!=(const std::string &leftval, const ci::string &rightval)
196 {
197  return !(leftval.c_str() == rightval);
198 }
199 
200 #endif // HASHCOMP_H
void CaseMapRebuild()
Definition: hashcomp.cpp:20
bool operator!=(const ci::string &leftval, const std::string &rightval)
Definition: hashcomp.h:188
Definition: hashcomp.h:84
std::string operator+(std::string &leftval, ci::string &rightval)
Definition: hashcomp.h:151
char_type do_tolower(char_type c) const anope_override
Definition: hashcomp.h:50
char_type do_toupper(char_type c) const anope_override
Definition: hashcomp.h:64
char_type do_tolower(char_type c) const anope_override
Definition: hashcomp.h:72
unsigned char tolower(unsigned char)
Definition: hashcomp.cpp:31
bool operator==(const std::string &leftval, const ci::string &rightval)
Definition: hashcomp.h:171
std::locale casemap
Definition: hashcomp.cpp:15
unsigned char toupper(unsigned char)
Definition: hashcomp.cpp:36
#define anope_override
Definition: services.h:56
std::basic_string< char, ci_char_traits, std::allocator< char > > string
Definition: hashcomp.h:133
#define CoreExport
Definition: services.h:62
char_type do_toupper(char_type c) const anope_override
Definition: hashcomp.h:42
Definition: anope.h:20