]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_regex_stdlib.cpp
Fix an oversight in mkversions that caused it to not update extras.
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_stdlib.cpp
index 5d2294c871ac2311cb11c10893b0cbdf866ea79d..aecb37dd673985d12eeb97f382dc9cd87ab4440c 100644 (file)
@@ -1,7 +1,10 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2012 ChrisTX <chris@rev-crew.info>
+ *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2013, 2016, 2018 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
  *
  * 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
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/// $CompilerFlags: -std=c++11
+
+
 #include "inspircd.h"
 #include "modules/regex.h"
 #include <regex>
 
-/* $CompileFlags: -std=c++11 */
-/* $ModDep: modules/regex.h */
-
-class StdRegexException : public ModuleException
-{
- public:
-       StdRegexException(const std::string& rx, const std::string& error)
-               : ModuleException(std::string("Error in regex ") + rx + ": " + error)
-       {
-       }
-};
-
 class StdRegex : public Regex
 {
        std::regex regexcl;
@@ -44,11 +38,11 @@ class StdRegex : public Regex
                }
                catch(std::regex_error rxerr)
                {
-                       throw StdRegexException(rx, rxerr.what());
+                       throw RegexException(rx, rxerr.what());
                }
        }
 
-       bool Matches(const std::string& text)
+       bool Matches(const std::string& text) CXX11_OVERRIDE
        {
                return std::regex_search(text, regexcl);
        }
@@ -59,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);
        }
@@ -71,36 +65,32 @@ public:
        StdRegexFactory ref;
        ModuleRegexStd() : ref(this)
        {
-               ServerInstance->Modules->AddService(ref);
-               Implementation eventlist[] = { I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-               OnRehash(NULL);
        }
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Regex Provider Module for std::regex", VF_VENDOR);
+               return Version("Provides a regular expression engine which uses the C++11 std::regex regular expression matching system.", VF_VENDOR);
        }
 
-       void OnRehash(User* u) CXX11_OVERRIDE
+       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;
                }
        }