diff options
Diffstat (limited to 'src/misc.cpp')
| -rw-r--r-- | src/misc.cpp | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/misc.cpp b/src/misc.cpp index 57314c53b..b6891d669 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -17,8 +17,8 @@ #include "config.h" #include "bots.h" #include "language.h" -#include "regexpr.h" #include "sockets.h" +#include "event.h" #include <errno.h> #include <sys/types.h> @@ -121,7 +121,7 @@ bool NumberList::InvalidRange(const Anope::string &) return true; } -ListFormatter::ListFormatter(NickCore *acc) : nc(acc) +ListFormatter::ListFormatter(NickServ::Account *acc) : nc(acc) { } @@ -215,7 +215,7 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) } } -InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc), longest(0) +InfoFormatter::InfoFormatter(NickServ::Account *acc) : nc(acc), longest(0) { } @@ -312,7 +312,7 @@ time_t Anope::DoTime(const Anope::string &s) return amount; } -Anope::string Anope::Duration(time_t t, const NickCore *nc) +Anope::string Anope::Duration(time_t t, const NickServ::Account *nc) { /* We first calculate everything */ time_t years = t / 31536000; @@ -353,7 +353,7 @@ Anope::string Anope::Duration(time_t t, const NickCore *nc) } } -Anope::string Anope::strftime(time_t t, const NickCore *nc, bool short_output) +Anope::string Anope::strftime(time_t t, const NickServ::Account *nc, bool short_output) { tm tm = *localtime(&t); char buf[BUFSIZE]; @@ -368,10 +368,10 @@ Anope::string Anope::strftime(time_t t, const NickCore *nc, bool short_output) return Anope::string(buf) + " " + Language::Translate(nc, _("(now)")); } -Anope::string Anope::Expires(time_t expires, const NickCore *nc) +Anope::string Anope::Expires(time_t expires, const NickServ::Account *nc) { if (!expires) - return Language::Translate(nc, NO_EXPIRE); + return Language::Translate(nc, _("does not expire")); else if (expires <= Anope::CurTime) return Language::Translate(nc, _("expires momentarily")); else @@ -408,38 +408,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 } @@ -511,7 +502,7 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case void Anope::Encrypt(const Anope::string &src, Anope::string &dest) { EventReturn MOD_RESULT; - FOREACH_RESULT(OnEncrypt, MOD_RESULT, (src, dest)); + MOD_RESULT = Event::OnEncrypt(&Event::Encrypt::OnEncrypt, src, dest); static_cast<void>(MOD_RESULT); } @@ -526,7 +517,7 @@ bool Anope::Decrypt(const Anope::string &src, Anope::string &dest) Anope::string hashm(src.begin(), src.begin() + pos); EventReturn MOD_RESULT; - FOREACH_RESULT(OnDecrypt, MOD_RESULT, (hashm, src, dest)); + MOD_RESULT = Event::OnDecrypt(&Event::Decrypt::OnDecrypt, hashm, src, dest); if (MOD_RESULT == EVENT_ALLOW) return true; @@ -653,7 +644,7 @@ Anope::string Anope::VersionBuildString() if (!flags.empty()) s += ", flags " + flags; - + return s; } |
