X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_regex_stdlib.cpp;h=80cf299f1cdb576b5e0d0cf61978b11956f30220;hb=bb39d78be61e45555cdd87985e26ea07b725fabf;hp=4942e973972bb06310436c55ee42c87ce55edfca;hpb=cff57f7ba780a5c4fc331ccbab489abdc572379c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_regex_stdlib.cpp b/src/modules/extra/m_regex_stdlib.cpp index 4942e9739..80cf299f1 100644 --- a/src/modules/extra/m_regex_stdlib.cpp +++ b/src/modules/extra/m_regex_stdlib.cpp @@ -1,7 +1,10 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2012 ChrisTX + * Copyright (C) 2019 Robby + * Copyright (C) 2013, 2016, 2018 Sadie Powell + * Copyright (C) 2013 Attila Molnar + * Copyright (C) 2012 ChrisTX * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -15,32 +18,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#include "inspircd.h" -#include "m_regex.h" -#include -/* $ModDesc: Regex Provider Module for std::regex Regular Expressions */ -/* $ModConfig: - * Specify the Regular Expression engine to use here. Valid settings are - * bre, ere, awk, grep, egrep, ecmascript (default if not specified)*/ -/* $CompileFlags: -std=c++11 */ -/* $ModDep: m_regex.h */ +/// $CompilerFlags: -std=c++11 -class StdRegexException : public ModuleException -{ -public: - StdRegexException(const std::string& rx, const std::string& error) - : ModuleException(std::string("Error in regex ") + rx + ": " + error) - { - } -}; + +#include "inspircd.h" +#include "modules/regex.h" +#include class StdRegex : public Regex { -private: std::regex regexcl; -public: + + public: StdRegex(const std::string& rx, std::regex::flag_type fltype) : Regex(rx) { try{ @@ -48,11 +38,11 @@ public: } catch(std::regex_error rxerr) { - throw StdRegexException(rx, rxerr.what()); + throw RegexException(rx, rxerr.what()); } } - - virtual bool Matches(const std::string& text) + + bool Matches(const std::string& text) CXX11_OVERRIDE { return std::regex_search(text, regexcl); } @@ -63,7 +53,7 @@ class StdRegexFactory : public RegexFactory public: std::regex::flag_type regextype; StdRegexFactory(Module* m) : RegexFactory(m, "regex/stdregex") {} - Regex* Create(const std::string& expr) + Regex* Create(const std::string& expr) CXX11_OVERRIDE { return new StdRegex(expr, regextype); } @@ -73,37 +63,34 @@ class ModuleRegexStd : public Module { public: StdRegexFactory ref; - ModuleRegexStd() : ref(this) { - ServerInstance->Modules->AddService(ref); - Implementation eventlist[] = { I_OnRehash }; - ServerInstance->Modules->Attach(eventlist, this, 1); - OnRehash(NULL); + ModuleRegexStd() : ref(this) + { } - Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { return Version("Regex Provider Module for std::regex", VF_VENDOR); } - - void OnRehash(User* u) + + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* Conf = ServerInstance->Config->ConfValue("stdregex"); - std::string regextype = Conf->getString("type", "ecmascript"); - - if(regextype == "bre") + + const std::string regextype = Conf->getString("type", "ecmascript", 1); + if (stdalgo::string::equalsci(regextype, "bre")) ref.regextype = std::regex::basic; - else if(regextype == "ere") + else if (stdalgo::string::equalsci(regextype, "ere")) ref.regextype = std::regex::extended; - else if(regextype == "awk") + else if (stdalgo::string::equalsci(regextype, "awk")) ref.regextype = std::regex::awk; - else if(regextype == "grep") + else if (stdalgo::string::equalsci(regextype, "grep")) ref.regextype = std::regex::grep; - else if(regextype == "egrep") + else if (stdalgo::string::equalsci(regextype, "egrep")) ref.regextype = std::regex::egrep; else { - if(regextype != "ecmascript") - ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Non-existent regex engine '%s' specified. Falling back to ECMAScript.", regextype.c_str()); + if (!stdalgo::string::equalsci(regextype, "ecmascript")) + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Nonexistent regex engine '%s' specified. Falling back to ECMAScript.", regextype.c_str()); ref.regextype = std::regex::ECMAScript; } }