2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
5 * Copyright (C) 2012 ChrisTX <chris@rev-crew.info>
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.
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
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/>.
22 # pragma GCC diagnostic ignored "-Wshadow"
26 #include "modules/regex.h"
30 /* $CompileFlags: -std=c++11 */
31 /* $LinkerFlags: -lre2 */
32 /* $ModDep: modules/regex.h */
34 class RE2Exception : public ModuleException
37 RE2Exception(const std::string& rx, const std::string& error)
38 : ModuleException(std::string("Error in regex ") + rx + ": " + error)
43 class RE2Regex : public Regex
48 RE2Regex(const std::string& rx) : Regex(rx), regexcl(rx, RE2::Quiet)
52 throw RE2Exception(rx, regexcl.error());
56 bool Matches(const std::string& text)
58 return RE2::FullMatch(text, regexcl);
62 class RE2Factory : public RegexFactory
65 RE2Factory(Module* m) : RegexFactory(m, "regex/re2") { }
66 Regex* Create(const std::string& expr)
68 return new RE2Regex(expr);
72 class ModuleRegexRE2 : public Module
77 ModuleRegexRE2() : ref(this)
79 ServerInstance->Modules->AddService(ref);
82 Version GetVersion() CXX11_OVERRIDE
84 return Version("Regex Provider Module for RE2", VF_VENDOR);
88 MODULE_INIT(ModuleRegexRE2)