]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_regex_re2.cpp
sslinfo: use the SSL certificate API to get user SSL certificates.
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_re2.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
5  *   Copyright (C) 2012 ChrisTX <chris@rev-crew.info>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /// $CompilerFlags: find_compiler_flags("re2" "")
21 /// $LinkerFlags: find_linker_flags("re2" "-lre2")
22
23 /// $PackageInfo: require_system("darwin") pkg-config re2
24 /// $PackageInfo: require_system("debian" "8.0") libre2-dev pkg-config
25 /// $PackageInfo: require_system("ubuntu" "15.10") libre2-dev pkg-config
26
27
28 #include "inspircd.h"
29 #include "modules/regex.h"
30
31 #ifdef __GNUC__
32 # pragma GCC diagnostic push
33 #endif
34
35 // Fix warnings about the use of `long long` on C++03 and
36 // shadowing on GCC.
37 #if defined __clang__
38 # pragma clang diagnostic ignored "-Wc++11-long-long"
39 #elif defined __GNUC__
40 # pragma GCC diagnostic ignored "-Wlong-long"
41 # pragma GCC diagnostic ignored "-Wshadow"
42 #endif
43
44 #include <re2/re2.h>
45
46 #ifdef __GNUC__
47 # pragma GCC diagnostic pop
48 #endif
49
50 class RE2Regex : public Regex
51 {
52         RE2 regexcl;
53
54  public:
55         RE2Regex(const std::string& rx) : Regex(rx), regexcl(rx, RE2::Quiet)
56         {
57                 if (!regexcl.ok())
58                 {
59                         throw RegexException(rx, regexcl.error());
60                 }
61         }
62
63         bool Matches(const std::string& text) CXX11_OVERRIDE
64         {
65                 return RE2::FullMatch(text, regexcl);
66         }
67 };
68
69 class RE2Factory : public RegexFactory
70 {
71  public:
72         RE2Factory(Module* m) : RegexFactory(m, "regex/re2") { }
73         Regex* Create(const std::string& expr) CXX11_OVERRIDE
74         {
75                 return new RE2Regex(expr);
76         }
77 };
78
79 class ModuleRegexRE2 : public Module
80 {
81         RE2Factory ref;
82
83  public:
84         ModuleRegexRE2() : ref(this)
85         {
86         }
87
88         Version GetVersion() CXX11_OVERRIDE
89         {
90                 return Version("Regex Provider Module for RE2", VF_VENDOR);
91         }
92 };
93
94 MODULE_INIT(ModuleRegexRE2)