InspIRCd  3.0
hashcomp.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2011 Adam <[email protected]>
5  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
6  * Copyright (C) 2007, 2009 Dennis Friis <[email protected]>
7  * Copyright (C) 2005-2009 Craig Edwards <[email protected]>
8  * Copyright (C) 2007-2008 Robin Burchell <[email protected]>
9  * Copyright (C) 2008 Pippijn van Steenhoven <[email protected]>
10  *
11  * This file is part of InspIRCd. InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 
25 #pragma once
26 
27 #include <cstring>
28 #include <string>
29 #include <vector>
30 #include <deque>
31 #include <map>
32 #include <set>
33 #include "inspircd.h"
34 
35 /*******************************************************
36  * This file contains classes and templates that deal
37  * with the comparison and hashing of 'irc strings'.
38  * An 'irc string' is a string which compares in a
39  * case insensitive manner, and as per RFC 1459 will
40  * treat [ identical to {, ] identical to }, and \
41  * as identical to |.
42  *
43  * There are functors that accept std::string and
44  * compare/hash them as type irc::string by using
45  * mapping arrays internally.
46  *******************************************************/
47 
54 CoreExport extern unsigned const char *national_case_insensitive_map;
55 
59 CoreExport extern unsigned const char rfc_case_insensitive_map[256];
60 
65 CoreExport extern unsigned const char ascii_case_insensitive_map[256];
66 
69 namespace irc
70 {
78  CoreExport bool equals(const std::string& s1, const std::string& s2);
79 
85  CoreExport size_t find(const std::string& haystack, const std::string& needle);
86 
91  struct StrHashComp
92  {
95  bool operator()(const std::string& s1, const std::string& s2) const
96  {
97  return equals(s1, s2);
98  }
99  };
100 
101  struct insensitive
102  {
103  size_t CoreExport operator()(const std::string &s) const;
104  };
105 
107  {
108  bool CoreExport operator()(const std::string& a, const std::string& b) const;
109  };
110 
116  std::string CoreExport stringjoiner(const std::vector<std::string>& sequence, char separator = ' ');
117 
123  class CoreExport sepstream
124  {
125  protected:
128  std::string tokens;
131  char sep;
134  size_t pos;
138  public:
141  sepstream(const std::string &source, char separator, bool allowempty = false);
142 
147  bool GetToken(std::string& token);
148 
152  const std::string GetRemaining();
153 
157  bool StreamEnd();
158  };
159 
162  class CoreExport commasepstream : public sepstream
163  {
164  public:
167  commasepstream(const std::string &source, bool allowempty = false) : sepstream(source, ',', allowempty)
168  {
169  }
170  };
171 
174  class CoreExport spacesepstream : public sepstream
175  {
176  public:
179  spacesepstream(const std::string &source, bool allowempty = false) : sepstream(source, ' ', allowempty)
180  {
181  }
182  };
183 
196  class CoreExport tokenstream : private spacesepstream
197  {
198  public:
201  tokenstream(const std::string &source);
202 
207  bool GetToken(std::string &token);
208 
213  bool GetToken(int &token);
214 
219  bool GetToken(long &token);
220  };
221 
230  class CoreExport portparser
231  {
232  private:
233 
236  commasepstream sep;
237 
240  long in_range;
241 
244  long range_begin;
245 
248  long range_end;
249 
252  bool overlapped;
253 
257  std::set<long> overlap_set;
258 
261  bool Overlaps(long val);
262  public:
263 
268  portparser(const std::string &source, bool allow_overlapped = true);
269 
273  long GetToken();
274  };
275 }
bool allow_empty
Definition: hashcomp.h:137
bool operator()(const std::string &s1, const std::string &s2) const
Definition: hashcomp.h:95
Definition: hashcomp.h:69
Definition: hashcomp.h:101
Definition: hashcomp.h:106
bool equals(const std::string &s1, const std::string &s2)
Definition: hashcomp.cpp:121
std::string stringjoiner(const std::vector< std::string > &sequence, char separator=' ')
Definition: hashcomp.cpp:282
Definition: hashcomp.h:196
commasepstream(const std::string &source, bool allowempty=false)
Definition: hashcomp.h:167
Definition: hashcomp.h:123
Definition: hashcomp.h:174
std::string tokens
Definition: hashcomp.h:128
char sep
Definition: hashcomp.h:131
Definition: hashcomp.h:91
Definition: hashcomp.h:230
size_t find(const std::string &haystack, const std::string &needle)
Definition: hashcomp.cpp:131
spacesepstream(const std::string &source, bool allowempty=false)
Definition: hashcomp.h:179
size_t pos
Definition: hashcomp.h:134
Definition: hashcomp.h:162