mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Implement support for regex
This commit is contained in:
parent
7c2b6cd3d3
commit
0416868f3a
1 changed files with 17 additions and 2 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
|
@ -55,7 +56,11 @@ StringListString <- UnescapedStringListPart+
|
||||||
GenericQuery <- MatcherString
|
GenericQuery <- MatcherString
|
||||||
|
|
||||||
# A String that can either be a normal string or a regex search string
|
# A String that can either be a normal string or a regex search string
|
||||||
MatcherString <- String
|
MatcherString <- RegexMatcher / NormalMatcher
|
||||||
|
|
||||||
|
NormalMatcher <- String
|
||||||
|
RegexMatcher <- '/' RegexMatcherString '/'
|
||||||
|
RegexMatcherString <- ('\\/' / !'/' .)+
|
||||||
|
|
||||||
FlexStringValue <- CompactStringSet / String / [(] StringList [)]
|
FlexStringValue <- CompactStringSet / String / [(] StringList [)]
|
||||||
CompactStringSet <- StringListString ([,+] StringListString)+
|
CompactStringSet <- StringListString ([,+] StringListString)+
|
||||||
|
|
@ -263,7 +268,7 @@ static void setupParserRules()
|
||||||
return QString::fromStdString(std::string(sv.sv()));
|
return QString::fromStdString(std::string(sv.sv()));
|
||||||
};
|
};
|
||||||
|
|
||||||
search["MatcherString"] = [](const peg::SemanticValues &sv) -> StringMatcher {
|
search["NormalMatcher"] = [](const peg::SemanticValues &sv) -> StringMatcher {
|
||||||
auto target = std::any_cast<QString>(sv[0]);
|
auto target = std::any_cast<QString>(sv[0]);
|
||||||
auto sanitizedTarget = QString(target);
|
auto sanitizedTarget = QString(target);
|
||||||
sanitizedTarget.replace("\\\"", "\"");
|
sanitizedTarget.replace("\\\"", "\"");
|
||||||
|
|
@ -271,6 +276,16 @@ static void setupParserRules()
|
||||||
return [=](const QString &s) { return s.contains(sanitizedTarget, Qt::CaseInsensitive); };
|
return [=](const QString &s) { return s.contains(sanitizedTarget, Qt::CaseInsensitive); };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
search["RegexMatcher"] = [](const peg::SemanticValues &sv) -> StringMatcher {
|
||||||
|
auto target = std::any_cast<QString>(sv[0]);
|
||||||
|
auto regex = QRegularExpression(target, QRegularExpression::CaseInsensitiveOption);
|
||||||
|
return [=](const QString &s) { return regex.match(s).hasMatch(); };
|
||||||
|
};
|
||||||
|
|
||||||
|
search["RegexMatcherString"] = [](const peg::SemanticValues &sv) -> QString {
|
||||||
|
return QString::fromStdString(sv.token_to_string());
|
||||||
|
};
|
||||||
|
|
||||||
search["OracleQuery"] = [](const peg::SemanticValues &sv) -> Filter {
|
search["OracleQuery"] = [](const peg::SemanticValues &sv) -> Filter {
|
||||||
const auto matcher = std::any_cast<StringMatcher>(sv[0]);
|
const auto matcher = std::any_cast<StringMatcher>(sv[0]);
|
||||||
return [=](const CardData &x) { return matcher(x->getText()); };
|
return [=](const CardData &x) { return matcher(x->getText()); };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue