From bdf75d162176afa3bc88c3bf675300b5fc7fef1a Mon Sep 17 00:00:00 2001 From: ZeldaZach Date: Sun, 15 Dec 2024 02:18:11 -0500 Subject: [PATCH] Formatter --- cockatrice/src/game/filters/filter_string.cpp | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/cockatrice/src/game/filters/filter_string.cpp b/cockatrice/src/game/filters/filter_string.cpp index ce187329c..2a5e41e92 100644 --- a/cockatrice/src/game/filters/filter_string.cpp +++ b/cockatrice/src/game/filters/filter_string.cpp @@ -65,12 +65,14 @@ std::once_flag init; static void setupParserRules() { - auto passthru = [](const peg::SemanticValues &sv) -> Filter { return !sv.empty() ? std::any_cast(sv[0]) : nullptr; }; + auto passthru = [](const peg::SemanticValues &sv) -> Filter { + return !sv.empty() ? std::any_cast(sv[0]) : nullptr; + }; search["Start"] = passthru; search["QueryPartList"] = [](const peg::SemanticValues &sv) -> Filter { - return [=](const CardData& x) { - for (const auto & i : sv) { + return [=](const CardData &x) { + for (const auto &i : sv) { if (!std::any_cast(i)(x)) return false; } @@ -78,8 +80,8 @@ static void setupParserRules() }; }; search["ComplexQueryPart"] = [](const peg::SemanticValues &sv) -> Filter { - return [=](const CardData& x) { - for (const auto & i : sv) { + return [=](const CardData &x) { + for (const auto &i : sv) { if (std::any_cast(i)(x)) return true; } @@ -90,15 +92,15 @@ static void setupParserRules() search["QueryPart"] = passthru; search["NotQuery"] = [](const peg::SemanticValues &sv) -> Filter { Filter dependent = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { return !dependent(x); }; + return [=](const CardData &x) -> bool { return !dependent(x); }; }; search["TypeQuery"] = [](const peg::SemanticValues &sv) -> Filter { StringMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { return matcher(x->getCardType()); }; + return [=](const CardData &x) -> bool { return matcher(x->getCardType()); }; }; search["SetQuery"] = [](const peg::SemanticValues &sv) -> Filter { StringMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { + return [=](const CardData &x) -> bool { for (const auto &set : x->getSets().keys()) { if (matcher(set)) return true; @@ -108,7 +110,7 @@ static void setupParserRules() }; search["RarityQuery"] = [](const peg::SemanticValues &sv) -> Filter { StringMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { + return [=](const CardData &x) -> bool { for (const auto &set : x->getSets().values()) { if (matcher(set.getProperty("rarity"))) return true; @@ -119,11 +121,13 @@ static void setupParserRules() search["FormatQuery"] = [](const peg::SemanticValues &sv) -> Filter { if (sv.choice() == 0) { QString format = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { return x->getProperty(QString("format-%1").arg(format)) == "legal"; }; + return + [=](const CardData &x) -> bool { return x->getProperty(QString("format-%1").arg(format)) == "legal"; }; } else { QString format = std::any_cast(sv[1]); QString legality = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { return x->getProperty(QString("format-%1").arg(format)) == legality; }; + return + [=](const CardData &x) -> bool { return x->getProperty(QString("format-%1").arg(format)) == legality; }; } }; search["Legality"] = [](const peg::SemanticValues &sv) -> QString { @@ -203,14 +207,14 @@ static void setupParserRules() }; search["CompactStringSet"] = [](const peg::SemanticValues &sv) -> QStringList { QStringList result; - for (const auto & i : sv) { + for (const auto &i : sv) { result.append(std::any_cast(i)); } return result; }; search["StringList"] = [](const peg::SemanticValues &sv) -> QStringList { QStringList result; - for (const auto & i : sv) { + for (const auto &i : sv) { result.append(std::any_cast(i)); } return result; @@ -260,17 +264,17 @@ static void setupParserRules() search["OracleQuery"] = [](const peg::SemanticValues &sv) -> Filter { StringMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) { return matcher(x->getText()); }; + return [=](const CardData &x) { return matcher(x->getText()); }; }; search["ColorQuery"] = [](const peg::SemanticValues &sv) -> Filter { QString parts; - for (const auto & i : sv) { + for (const auto &i : sv) { parts += std::any_cast(i); } bool identity = sv.tokens[0][0] != 'i'; if (sv.tokens[1][0] == ':') { - return [=](const CardData& x) { + return [=](const CardData &x) { QString match = identity ? x->getColors() : x->getProperty("coloridentity"); if (parts.contains("m") && match.length() < 2) { return false; @@ -288,7 +292,7 @@ static void setupParserRules() return false; }; } else { - return [=](const CardData& x) { + return [=](const CardData &x) { QString match = identity ? x->getColors() : x->getProperty("colorIdentity"); if (parts.contains("m") && match.length() < 2) return false; @@ -312,15 +316,15 @@ static void setupParserRules() search["CMCQuery"] = [](const peg::SemanticValues &sv) -> Filter { NumberMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { return matcher(x->getProperty("cmc").toInt()); }; + return [=](const CardData &x) -> bool { return matcher(x->getProperty("cmc").toInt()); }; }; search["PowerQuery"] = [](const peg::SemanticValues &sv) -> Filter { NumberMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { return matcher(x->getPowTough().split("/")[0].toInt()); }; + return [=](const CardData &x) -> bool { return matcher(x->getPowTough().split("/")[0].toInt()); }; }; search["ToughnessQuery"] = [](const peg::SemanticValues &sv) -> Filter { NumberMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) -> bool { + return [=](const CardData &x) -> bool { auto parts = x->getPowTough().split("/"); return matcher(parts.length() == 2 ? parts[1].toInt() : 0); }; @@ -329,17 +333,17 @@ static void setupParserRules() QString field = std::any_cast(sv[0]); if (sv.choice() == 0) { StringMatcher matcher = std::any_cast(sv[1]); - return [=](const CardData& x) -> bool { return x->hasProperty(field) && matcher(x->getProperty(field)); }; + return [=](const CardData &x) -> bool { return x->hasProperty(field) && matcher(x->getProperty(field)); }; } else { NumberMatcher matcher = std::any_cast(sv[1]); - return [=](const CardData& x) -> bool { + return [=](const CardData &x) -> bool { return x->hasProperty(field) && matcher(x->getProperty(field).toInt()); }; } }; search["GenericQuery"] = [](const peg::SemanticValues &sv) -> Filter { StringMatcher matcher = std::any_cast(sv[0]); - return [=](const CardData& x) { return matcher(x->getName()); }; + return [=](const CardData &x) { return matcher(x->getName()); }; }; search["Color"] = [](const peg::SemanticValues &sv) -> char { return "WUBRGU"[sv.choice()]; }; @@ -350,7 +354,7 @@ static void setupParserRules() FilterString::FilterString() { - result = [](const CardData&) -> bool { return false; }; + result = [](const CardData &) -> bool { return false; }; _error = "Not initialized"; } @@ -363,7 +367,7 @@ FilterString::FilterString(const QString &expr) _error = QString(); if (ba.isEmpty()) { - result = [](const CardData&) -> bool { return true; }; + result = [](const CardData &) -> bool { return true; }; return; } @@ -373,6 +377,6 @@ FilterString::FilterString(const QString &expr) if (!search.parse(ba.data(), result)) { qDebug().nospace() << "FilterString error for " << expr << "; " << qPrintable(_error); - result = [](const CardData&) -> bool { return false; }; + result = [](const CardData &) -> bool { return false; }; } }