Skip to content

Commit 15b769c

Browse files
committed
feat(confilter): Regex Support
1 parent c7ad2f0 commit 15b769c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/filters/ConsoleFilter.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,18 @@ void ConsoleFilter::LoadFilters()
9797
continue;
9898
}
9999

100-
this->filter.insert(std::make_pair(key, it->value.GetString()));
100+
try
101+
{
102+
std::regex tmp(it->value.GetString(), std::regex_constants::ECMAScript);
103+
}
104+
catch (const std::regex_error &err)
105+
{
106+
ConFilterError(string_format("The regex for \"%s\" is not valid.", key.c_str()));
107+
ConFilterError(string_format("Error: %s", err.what()));
108+
continue;
109+
}
110+
111+
this->filter.insert({key, std::regex(it->value.GetString(), std::regex_constants::ECMAScript)});
101112
this->counter.insert(std::make_pair(key, 0));
102113
}
103114
}
@@ -108,12 +119,12 @@ bool ConsoleFilter::NeedFiltering(std::string message)
108119
return false;
109120

110121
PERF_RECORD("Console Filter", "core")
111-
for (std::map<std::string, std::string>::iterator it = this->filter.begin(); it != this->filter.end(); ++it)
122+
for (auto it = this->filter.begin(); it != this->filter.end(); ++it)
112123
{
113124
std::string key = it->first;
114-
std::string val = it->second;
125+
std::regex val = it->second;
115126

116-
if (message.find(val) != std::string::npos)
127+
if (std::regex_search(message, val))
117128
{
118129
if (this->counter.find(key) != this->counter.end())
119130
this->counter[key]++;

src/filters/ConsoleFilter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <map>
55
#include <string>
6+
#include <regex>
67
#include "../entrypoint.h"
78
#include "../common.h"
89

@@ -16,7 +17,7 @@ class ConsoleFilter
1617
{
1718
private:
1819
bool m_status = false;
19-
std::map<std::string, std::string> filter;
20+
std::map<std::string, std::regex> filter;
2021
std::map<std::string, uint64> counter;
2122

2223
public:

0 commit comments

Comments
 (0)