Add Matches() helper function

This commit is contained in:
WarmUpTill 2023-12-13 17:03:49 +01:00
parent a7cf5769dd
commit 51d121bda2
2 changed files with 20 additions and 0 deletions

View File

@ -51,6 +51,23 @@ RegexConfig::GetRegularExpression(const std::string &expr) const
return GetRegularExpression(QString::fromStdString(expr));
}
bool RegexConfig::Matches(const QString &text, const QString &expression) const
{
auto regex = GetRegularExpression(expression);
if (!regex.isValid()) {
return false;
}
auto match = regex.match(text);
return match.hasMatch();
}
bool RegexConfig::Matches(const std::string &text,
const std::string &expression) const
{
return Matches(QString::fromStdString(text),
QString::fromStdString(expression));
}
RegexConfig RegexConfig::PartialMatchRegexConfig()
{
RegexConfig conf;

View File

@ -29,6 +29,9 @@ public:
};
QRegularExpression GetRegularExpression(const QString &) const;
QRegularExpression GetRegularExpression(const std::string &) const;
bool Matches(const QString &text, const QString &expression) const;
bool Matches(const std::string &text,
const std::string &expression) const;
static RegexConfig PartialMatchRegexConfig();