2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
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/>.
20 /// $CompilerFlags: find_compiler_flags("tre")
21 /// $LinkerFlags: find_linker_flags("tre" "-ltre")
23 /// $PackageInfo: require_system("darwin") pkg-config tre
24 /// $PackageInfo: require_system("ubuntu") libtre-dev pkg-config
27 #include "modules/regex.h"
28 #include <sys/types.h>
29 #include <tre/regex.h>
31 class TRERegex : public Regex
36 TRERegex(const std::string& rx) : Regex(rx)
38 int flags = REG_EXTENDED | REG_NOSUB;
40 errcode = regcomp(®buf, rx.c_str(), flags);
43 // Get the error string into a std::string. YUCK this involves at least 2 string copies.
46 size_t sz = regerror(errcode, ®buf, NULL, 0);
47 errbuf = new char[sz + 1];
48 memset(errbuf, 0, sz + 1);
49 regerror(errcode, ®buf, errbuf, sz + 1);
53 throw RegexException(rx, error);
62 bool Matches(const std::string& text) CXX11_OVERRIDE
64 return (regexec(®buf, text.c_str(), 0, NULL, 0) == 0);
68 class TREFactory : public RegexFactory
71 TREFactory(Module* m) : RegexFactory(m, "regex/tre") {}
72 Regex* Create(const std::string& expr) CXX11_OVERRIDE
74 return new TRERegex(expr);
78 class ModuleRegexTRE : public Module
83 ModuleRegexTRE() : trf(this)
87 Version GetVersion() CXX11_OVERRIDE
89 return Version("Regex Provider Module for TRE Regular Expressions", VF_VENDOR);
93 MODULE_INIT(ModuleRegexTRE)