]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_regex_stdlib.cpp
Fix incorrect ModResult for noctcp user target.
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_stdlib.cpp
index 64d479cbc1795e82f6d4f10d31e8e2fa2390e4c4..42e5c8bf12106ec09984e4582e39d2a339ef2138 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "inspircd.h"
-#include "m_regex.h"
-#include <regex>
+/// $CompilerFlags: -std=c++11
 
-/* $ModDesc: Regex Provider Module for std::regex Regular Expressions */
-/* $ModConfig: <stdregex type="ecmascript">
- *  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 */
 
-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 <regex>
 
 class StdRegex : public Regex
 {
@@ -48,11 +35,11 @@ class StdRegex : public Regex
                }
                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 +50,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);
        }
@@ -75,35 +62,31 @@ 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()
+       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")
+               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")
+                       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;
                }