cb21075d |
1 | // Utils.H -*- C++ -*- |
2 | // Copyright (c) 1997, 1998 Etienne BERNARD |
643f62be |
3 | // Copyright (c) 2002,2005,2008 Clinton Ebadi |
cb21075d |
4 | |
5 | // This program is free software; you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation; either version 2 of the License, or |
8 | // any later version. |
9 | |
10 | // This program is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with this program; if not, write to the Free Software |
c6e7af05 |
17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | // 02110-1301, USA. |
cb21075d |
19 | |
20 | #ifndef UTILS_H |
21 | #define UTILS_H |
22 | |
23 | #ifndef HAVE_CONFIG_H |
24 | #include "config.h" |
25 | #endif |
26 | |
27 | #include <ctime> |
a6339323 |
28 | #include <string> |
29 | |
cb21075d |
30 | #include "Bot.H" |
31 | |
32 | #ifdef USESCRIPTS |
33 | #include <libguile.h> |
34 | #endif |
35 | |
f2b83452 |
36 | namespace Utils { |
37 | std::string get_nick (std::string); |
38 | std::string get_userhost (std::string); |
39 | std::string get_key(); |
40 | |
41 | int get_level (Bot *, std::string); |
42 | int get_level (Bot *, std::string, std::string); |
43 | |
44 | std::string make_wildcard (std::string); |
45 | |
a6339323 |
46 | // predicates |
f2b83452 |
47 | bool channel_p (std::string); |
48 | bool wildcard_p (std::string); |
49 | bool valid_channel_name_p (std::string); |
6b7614a8 |
50 | bool valid_nickname_p (const Bot *, std::string); |
f2b83452 |
51 | bool IP_p (std::string); |
52 | |
53 | std::string level2str (int); |
54 | std::string prot2str (int); |
55 | std::string bool2str (bool); |
56 | std::string long2str (long); |
57 | |
58 | std::time_t str2time(std::string); |
59 | |
a6339323 |
60 | // string case conversion |
f2b83452 |
61 | std::string to_lower (std::string); |
62 | std::string to_upper (std::string); |
63 | |
64 | std::string trim_str (std::string); |
cb21075d |
65 | |
66 | #ifdef USESCRIPTS |
f2b83452 |
67 | std::string scm2str (SCM); |
68 | SCM str2scm (std::string); |
cb21075d |
69 | #endif |
643f62be |
70 | |
71 | // Class to compare *i1 / *i2 in heaps etc. |
72 | template<typename T, typename C> class IndirectPred |
73 | { |
74 | C compare; |
75 | public: |
76 | bool operator() (const T * i1, const T * i2) const |
77 | { return compare (*i1, *i2); } |
78 | |
79 | typedef T* first_argument_type; |
80 | typedef T* second_argument_type; |
81 | typedef bool result_type; |
82 | }; |
f2b83452 |
83 | } |
cb21075d |
84 | |
85 | #endif |