summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-04-02 13:06:48 -0400
committerAdam <Adam@anope.org>2014-04-02 13:08:14 -0400
commit52bc8e4bc799d38e92d38d497a2bd055950841bb (patch)
treeb80ea985f1adffa43ca046c014e3b81f9404db8d /src
parentee133c03f206a7fab78a700b183fbc8684b9d6bf (diff)
Remove regex mods, use std::regex instead
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp20
-rw-r--r--src/misc.cpp34
-rw-r--r--src/xline.cpp19
3 files changed, 39 insertions, 34 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 0275cb7f8..6473cf830 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -115,6 +115,7 @@ Conf::Conf() : Block("")
{
ReadTimeout = 0;
UsePrivmsg = DefPrivmsg = false;
+ regex_flags = 0;
this->LoadConf(ServicesConf);
@@ -526,6 +527,25 @@ Conf::Conf() : Block("")
if (!options->Get<unsigned>("seed"))
Log() << "Configuration option options:seed should be set. It's for YOUR safety! Remember that!";
+ /* check regexengine */
+ const Anope::string &regex_engine = options->Get<Anope::string>("regexengine");
+ if (regex_engine == "ecmascript")
+ regex_flags = std::regex::ECMAScript;
+ else if (regex_engine == "basic")
+ regex_flags = std::regex::basic;
+ else if (regex_engine == "extended")
+ regex_flags = std::regex::extended;
+ else if (regex_engine == "awk")
+ regex_flags = std::regex::awk;
+ else if (regex_engine == "grep")
+ regex_flags = std::regex::grep;
+ else if (regex_engine == "egrep")
+ regex_flags = std::regex::egrep;
+ /* always enable icase and optimize */
+ if (regex_flags)
+ regex_flags |= std::regex::icase | std::regex::optimize;
+
+ /* apply changes from an older config? */
if (Config)
{
/* Apply module chnages */
diff --git a/src/misc.cpp b/src/misc.cpp
index 57314c53b..ee7724941 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -17,7 +17,6 @@
#include "config.h"
#include "bots.h"
#include "language.h"
-#include "regexpr.h"
#include "sockets.h"
#include <errno.h>
@@ -408,38 +407,29 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case
{
size_t s = 0, m = 0, str_len = str.length(), mask_len = mask.length();
- if (use_regex && mask_len >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
+ if (use_regex && Config->regex_flags && mask_len >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
{
Anope::string stripped_mask = mask.substr(1, mask_len - 2);
// This is often called with the same mask multiple times in a row, so cache it
- static Regex *r = NULL;
+ static Anope::string pattern;
+ static std::regex r;
- if (r == NULL || r->GetExpression() != stripped_mask)
+ if (pattern != stripped_mask)
{
- ServiceReference<RegexProvider> provider("Regex", Config->GetBlock("options")->Get<const Anope::string>("regexengine"));
- if (provider)
+ try
{
- try
- {
- delete r;
- r = NULL;
- // This may throw
- r = provider->Compile(stripped_mask);
- }
- catch (const RegexException &ex)
- {
- Log(LOG_DEBUG) << ex.GetReason();
- }
+ r.assign(stripped_mask.str(), Config->regex_flags);
+ pattern = stripped_mask;
}
- else
+ catch (const std::regex_error &error)
{
- delete r;
- r = NULL;
+ Log(LOG_DEBUG) << error.what();
}
}
- if (r != NULL && r->Matches(str))
- return true;
+ if (pattern == stripped_mask)
+ if (std::regex_search(str.str(), r))
+ return true;
// Fall through to non regex match
}
diff --git a/src/xline.cpp b/src/xline.cpp
index ea74ba8c7..8c8f6034c 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -15,7 +15,6 @@
#include "xline.h"
#include "users.h"
#include "sockets.h"
-#include "regexpr.h"
#include "config.h"
#include "commands.h"
#include "servers.h"
@@ -26,21 +25,17 @@ Serialize::Checker<std::multimap<Anope::string, XLine *, ci::less> > XLineManage
void XLine::InitRegex()
{
- if (this->mask.length() >= 2 && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/' && !Config->GetBlock("options")->Get<const Anope::string>("regexengine").empty())
+ if (this->mask.length() >= 2 && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/' && Config->regex_flags)
{
Anope::string stripped_mask = this->mask.substr(1, this->mask.length() - 2);
- ServiceReference<RegexProvider> provider("Regex", Config->GetBlock("options")->Get<const Anope::string>("regexengine"));
- if (provider)
+ try
{
- try
- {
- this->regex = provider->Compile(stripped_mask);
- }
- catch (const RegexException &ex)
- {
- Log(LOG_DEBUG) << ex.GetReason();
- }
+ this->regex = new std::regex(stripped_mask.str(), Config->regex_flags);
+ }
+ catch (const std::regex_error &ex)
+ {
+ Log(LOG_DEBUG) << ex.what();
}
}
}