]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_regex_pcre.cpp
Change allocation of InspIRCd::Timers to be physically part of the object containing it
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_pcre.cpp
index b43d2bc9f5236ca95730465d5eaa696ccb711acf..9ae6719ba96a89d35adc9d67ca7d5c5f7bd6932f 100644 (file)
@@ -22,7 +22,6 @@
 #include <pcre.h>
 #include "modules/regex.h"
 
-/* $ModDep: modules/regex.h */
 /* $CompileFlags: exec("pcre-config --cflags") */
 /* $LinkerFlags: exec("pcre-config --libs") rpath("pcre-config --libs") -lpcre */
 
 # pragma comment(lib, "libpcre.lib")
 #endif
 
-class PCREException : public ModuleException
-{
- public:
-       PCREException(const std::string& rx, const std::string& error, int erroffset)
-               : ModuleException("Error in regex " + rx + " at offset " + ConvToStr(erroffset) + ": " + error)
-       {
-       }
-};
-
 class PCRERegex : public Regex
 {
        pcre* regex;
@@ -51,8 +41,8 @@ class PCRERegex : public Regex
                regex = pcre_compile(rx.c_str(), 0, &error, &erroffset, NULL);
                if (!regex)
                {
-                       ServerInstance->Logs->Log("REGEX", LOG_DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
-                       throw PCREException(rx, error, erroffset);
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
+                       throw RegexException(rx, error, erroffset);
                }
        }
 
@@ -61,14 +51,9 @@ class PCRERegex : public Regex
                pcre_free(regex);
        }
 
-       bool Matches(const std::string& text)
+       bool Matches(const std::string& text) CXX11_OVERRIDE
        {
-               if (pcre_exec(regex, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) > -1)
-               {
-                       // Bang. :D
-                       return true;
-               }
-               return false;
+               return (pcre_exec(regex, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) >= 0);
        }
 };
 
@@ -76,7 +61,7 @@ class PCREFactory : public RegexFactory
 {
  public:
        PCREFactory(Module* m) : RegexFactory(m, "regex/pcre") {}
-       Regex* Create(const std::string& expr)
+       Regex* Create(const std::string& expr) CXX11_OVERRIDE
        {
                return new PCRERegex(expr);
        }
@@ -88,7 +73,6 @@ class ModuleRegexPCRE : public Module
        PCREFactory ref;
        ModuleRegexPCRE() : ref(this)
        {
-               ServerInstance->Modules->AddService(ref);
        }
 
        Version GetVersion() CXX11_OVERRIDE