summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2013-08-27 05:28:15 -0700
committerAttila Molnar <attilamolnar@hush.com>2013-08-27 05:28:15 -0700
commit620e818578a5e0dbebd07fb27a571d5392c66c24 (patch)
tree6d20eef5fd9b98fecd93df2caf197ad08c168562 /src/modules
parentd9d9cbe025f94523265daa72de7596467d71f5c8 (diff)
parenteaf658de3d1ef984c9a0b4273a9cfbd3029f8b5b (diff)
Merge pull request #619 from SaberUK/master+regex-dedupe
Various regex module improvements.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_regex_pcre.cpp22
-rw-r--r--src/modules/extra/m_regex_posix.cpp22
-rw-r--r--src/modules/extra/m_regex_re2.cpp15
-rw-r--r--src/modules/extra/m_regex_stdlib.cpp15
-rw-r--r--src/modules/extra/m_regex_tre.cpp22
-rw-r--r--src/modules/m_regex_glob.cpp4
6 files changed, 20 insertions, 80 deletions
diff --git a/src/modules/extra/m_regex_pcre.cpp b/src/modules/extra/m_regex_pcre.cpp
index 04b9da0ab..91c2d1404 100644
--- a/src/modules/extra/m_regex_pcre.cpp
+++ b/src/modules/extra/m_regex_pcre.cpp
@@ -29,15 +29,6 @@
# 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,7 +42,7 @@ class PCRERegex : public Regex
if (!regex)
{
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
- throw PCREException(rx, error, erroffset);
+ throw RegexException(rx, error, erroffset);
}
}
@@ -60,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);
}
};
@@ -75,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);
}
diff --git a/src/modules/extra/m_regex_posix.cpp b/src/modules/extra/m_regex_posix.cpp
index ab9fe68ff..935cdbf92 100644
--- a/src/modules/extra/m_regex_posix.cpp
+++ b/src/modules/extra/m_regex_posix.cpp
@@ -23,15 +23,6 @@
#include <sys/types.h>
#include <regex.h>
-class POSIXRegexException : public ModuleException
-{
- public:
- POSIXRegexException(const std::string& rx, const std::string& error)
- : ModuleException("Error in regex " + rx + ": " + error)
- {
- }
-};
-
class POSIXRegex : public Regex
{
regex_t regbuf;
@@ -54,7 +45,7 @@ class POSIXRegex : public Regex
error = errbuf;
delete[] errbuf;
regfree(&regbuf);
- throw POSIXRegexException(rx, error);
+ throw RegexException(rx, error);
}
}
@@ -63,14 +54,9 @@ class POSIXRegex : public Regex
regfree(&regbuf);
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
- if (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0)
- {
- // Bang. :D
- return true;
- }
- return false;
+ return (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0);
}
};
@@ -79,7 +65,7 @@ class PosixFactory : public RegexFactory
public:
bool extended;
PosixFactory(Module* m) : RegexFactory(m, "regex/posix") {}
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new POSIXRegex(expr, extended);
}
diff --git a/src/modules/extra/m_regex_re2.cpp b/src/modules/extra/m_regex_re2.cpp
index 56d80cd68..2525b70ab 100644
--- a/src/modules/extra/m_regex_re2.cpp
+++ b/src/modules/extra/m_regex_re2.cpp
@@ -30,15 +30,6 @@
/* $CompileFlags: -std=c++11 */
/* $LinkerFlags: -lre2 */
-class RE2Exception : public ModuleException
-{
- public:
- RE2Exception(const std::string& rx, const std::string& error)
- : ModuleException(std::string("Error in regex ") + rx + ": " + error)
- {
- }
-};
-
class RE2Regex : public Regex
{
RE2 regexcl;
@@ -48,11 +39,11 @@ class RE2Regex : public Regex
{
if (!regexcl.ok())
{
- throw RE2Exception(rx, regexcl.error());
+ throw RegexException(rx, regexcl.error());
}
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
return RE2::FullMatch(text, regexcl);
}
@@ -62,7 +53,7 @@ class RE2Factory : public RegexFactory
{
public:
RE2Factory(Module* m) : RegexFactory(m, "regex/re2") { }
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new RE2Regex(expr);
}
diff --git a/src/modules/extra/m_regex_stdlib.cpp b/src/modules/extra/m_regex_stdlib.cpp
index d69f739ec..5ec358d58 100644
--- a/src/modules/extra/m_regex_stdlib.cpp
+++ b/src/modules/extra/m_regex_stdlib.cpp
@@ -22,15 +22,6 @@
/* $CompileFlags: -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)
- {
- }
-};
-
class StdRegex : public Regex
{
std::regex regexcl;
@@ -43,11 +34,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);
}
@@ -58,7 +49,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);
}
diff --git a/src/modules/extra/m_regex_tre.cpp b/src/modules/extra/m_regex_tre.cpp
index cc70f187d..92f2ad990 100644
--- a/src/modules/extra/m_regex_tre.cpp
+++ b/src/modules/extra/m_regex_tre.cpp
@@ -26,15 +26,6 @@
/* $CompileFlags: pkgconfincludes("tre","tre/regex.h","") */
/* $LinkerFlags: pkgconflibs("tre","/libtre.so","-ltre") rpath("pkg-config --libs tre") */
-class TRERegexException : public ModuleException
-{
- public:
- TRERegexException(const std::string& rx, const std::string& error)
- : ModuleException("Error in regex " + rx + ": " + error)
- {
- }
-};
-
class TRERegex : public Regex
{
regex_t regbuf;
@@ -57,7 +48,7 @@ public:
error = errbuf;
delete[] errbuf;
regfree(&regbuf);
- throw TRERegexException(rx, error);
+ throw RegexException(rx, error);
}
}
@@ -66,14 +57,9 @@ public:
regfree(&regbuf);
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
- if (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0)
- {
- // Bang. :D
- return true;
- }
- return false;
+ return (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0);
}
};
@@ -81,7 +67,7 @@ class TREFactory : public RegexFactory
{
public:
TREFactory(Module* m) : RegexFactory(m, "regex/tre") {}
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new TRERegex(expr);
}
diff --git a/src/modules/m_regex_glob.cpp b/src/modules/m_regex_glob.cpp
index 887b1cd79..eb7cf4ece 100644
--- a/src/modules/m_regex_glob.cpp
+++ b/src/modules/m_regex_glob.cpp
@@ -28,7 +28,7 @@ public:
{
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
return InspIRCd::Match(text, this->regex_string);
}
@@ -37,7 +37,7 @@ public:
class GlobFactory : public RegexFactory
{
public:
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new GlobRegex(expr);
}