From 97aba4f8a57877ab68ddd618b96f52342970f998 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 31 Jul 2018 03:14:09 +0100 Subject: Move m_regex_stdlib out of extras now it can always be built. --- src/modules/extra/m_regex_stdlib.cpp | 96 ------------------------------------ src/modules/m_regex_stdlib.cpp | 94 +++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 96 deletions(-) delete mode 100644 src/modules/extra/m_regex_stdlib.cpp create mode 100644 src/modules/m_regex_stdlib.cpp (limited to 'src') diff --git a/src/modules/extra/m_regex_stdlib.cpp b/src/modules/extra/m_regex_stdlib.cpp deleted file mode 100644 index 4065ec014..000000000 --- a/src/modules/extra/m_regex_stdlib.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * 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 - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/// $CompilerFlags: -std=c++11 - - -#include "inspircd.h" -#include "modules/regex.h" -#include - -class StdRegex : public Regex -{ - std::regex regexcl; - - public: - StdRegex(const std::string& rx, std::regex::flag_type fltype) : Regex(rx) - { - try{ - regexcl.assign(rx, fltype | std::regex::optimize); - } - catch(std::regex_error rxerr) - { - throw RegexException(rx, rxerr.what()); - } - } - - bool Matches(const std::string& text) override - { - return std::regex_search(text, regexcl); - } -}; - -class StdRegexFactory : public RegexFactory -{ - public: - std::regex::flag_type regextype; - StdRegexFactory(Module* m) : RegexFactory(m, "regex/stdregex") {} - Regex* Create(const std::string& expr) override - { - return new StdRegex(expr, regextype); - } -}; - -class ModuleRegexStd : public Module -{ -public: - StdRegexFactory ref; - ModuleRegexStd() : ref(this) - { - } - - Version GetVersion() override - { - return Version("Regex Provider Module for std::regex", VF_VENDOR); - } - - void ReadConfig(ConfigStatus& status) override - { - ConfigTag* Conf = ServerInstance->Config->ConfValue("stdregex"); - std::string regextype = Conf->getString("type", "ecmascript"); - - if (stdalgo::string::equalsci(regextype, "bre")) - ref.regextype = std::regex::basic; - else if (stdalgo::string::equalsci(regextype, "ere")) - ref.regextype = std::regex::extended; - else if (stdalgo::string::equalsci(regextype, "awk")) - ref.regextype = std::regex::awk; - else if (stdalgo::string::equalsci(regextype, "grep")) - ref.regextype = std::regex::grep; - else if (stdalgo::string::equalsci(regextype, "egrep")) - ref.regextype = std::regex::egrep; - else - { - if (!stdalgo::string::equalsci(regextype, "ecmascript")) - ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Non-existent regex engine '%s' specified. Falling back to ECMAScript.", regextype.c_str()); - ref.regextype = std::regex::ECMAScript; - } - } -}; - -MODULE_INIT(ModuleRegexStd) diff --git a/src/modules/m_regex_stdlib.cpp b/src/modules/m_regex_stdlib.cpp new file mode 100644 index 000000000..269e64c75 --- /dev/null +++ b/src/modules/m_regex_stdlib.cpp @@ -0,0 +1,94 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * 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 + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "inspircd.h" +#include "modules/regex.h" +#include + +class StdRegex : public Regex +{ + std::regex regexcl; + + public: + StdRegex(const std::string& rx, std::regex::flag_type fltype) : Regex(rx) + { + try{ + regexcl.assign(rx, fltype | std::regex::optimize); + } + catch(std::regex_error rxerr) + { + throw RegexException(rx, rxerr.what()); + } + } + + bool Matches(const std::string& text) override + { + return std::regex_search(text, regexcl); + } +}; + +class StdRegexFactory : public RegexFactory +{ + public: + std::regex::flag_type regextype; + StdRegexFactory(Module* m) : RegexFactory(m, "regex/stdregex") {} + Regex* Create(const std::string& expr) override + { + return new StdRegex(expr, regextype); + } +}; + +class ModuleRegexStd : public Module +{ +public: + StdRegexFactory ref; + ModuleRegexStd() : ref(this) + { + } + + Version GetVersion() override + { + return Version("Regex Provider Module for std::regex", VF_VENDOR); + } + + void ReadConfig(ConfigStatus& status) override + { + ConfigTag* Conf = ServerInstance->Config->ConfValue("stdregex"); + std::string regextype = Conf->getString("type", "ecmascript"); + + if (stdalgo::string::equalsci(regextype, "bre")) + ref.regextype = std::regex::basic; + else if (stdalgo::string::equalsci(regextype, "ere")) + ref.regextype = std::regex::extended; + else if (stdalgo::string::equalsci(regextype, "awk")) + ref.regextype = std::regex::awk; + else if (stdalgo::string::equalsci(regextype, "grep")) + ref.regextype = std::regex::grep; + else if (stdalgo::string::equalsci(regextype, "egrep")) + ref.regextype = std::regex::egrep; + else + { + if (!stdalgo::string::equalsci(regextype, "ecmascript")) + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Non-existent regex engine '%s' specified. Falling back to ECMAScript.", regextype.c_str()); + ref.regextype = std::regex::ECMAScript; + } + } +}; + +MODULE_INIT(ModuleRegexStd) -- cgit v1.3.1-10-gc9f91