]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_regex_re2.cpp
Update the module descriptions.
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_re2.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2013-2014, 2016-2017, 2019 Sadie Powell <sadie@witchery.services>
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("arch") pkgconf re2
24 /// $PackageInfo: require_system("darwin") pkg-config re2
25 /// $PackageInfo: require_system("debian" "8.0") libre2-dev pkg-config
26 /// $PackageInfo: require_system("ubuntu" "15.10") libre2-dev pkg-config
27
28
29 #include "inspircd.h"
30 #include "modules/regex.h"
31
32 #ifdef __GNUC__
33 # pragma GCC diagnostic push
34 #endif
35
36 // Fix warnings about the use of `long long` on C++03 and
37 // shadowing on GCC.
38 #if defined __clang__
39 # pragma clang diagnostic ignored "-Wc++11-long-long"
40 #elif defined __GNUC__
41 # pragma GCC diagnostic ignored "-Wlong-long"
42 # pragma GCC diagnostic ignored "-Wshadow"
43 #endif
44
45 #include <re2/re2.h>
46
47 #ifdef __GNUC__
48 # pragma GCC diagnostic pop
49 #endif
50
51 class RE2Regex : public Regex
52 {
53         RE2 regexcl;
54
55  public:
56         RE2Regex(const std::string& rx) : Regex(rx), regexcl(rx, RE2::Quiet)
57         {
58                 if (!regexcl.ok())
59                 {
60                         throw RegexException(rx, regexcl.error());
61                 }
62         }
63
64         bool Matches(const std::string& text) CXX11_OVERRIDE
65         {
66                 return RE2::FullMatch(text, regexcl);
67         }
68 };
69
70 class RE2Factory : public RegexFactory
71 {
72  public:
73         RE2Factory(Module* m) : RegexFactory(m, "regex/re2") { }
74         Regex* Create(const std::string& expr) CXX11_OVERRIDE
75         {
76                 return new RE2Regex(expr);
77         }
78 };
79
80 class ModuleRegexRE2 : public Module
81 {
82         RE2Factory ref;
83
84  public:
85         ModuleRegexRE2() : ref(this)
86         {
87         }
88
89         Version GetVersion() CXX11_OVERRIDE
90         {
91                 return Version("Provides the re2 regular expression engine which uses the RE2 library.", VF_VENDOR);
92         }
93 };
94
95 MODULE_INIT(ModuleRegexRE2)