diff --git a/cockatrice/src/deck_loader.cpp b/cockatrice/src/deck_loader.cpp index 44ea3087..af5b7778 100644 --- a/cockatrice/src/deck_loader.cpp +++ b/cockatrice/src/deck_loader.cpp @@ -289,7 +289,7 @@ QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneNam return currentZoneName; } -QString DeckLoader::getCompleteCardName(const QString cardName) const +QString DeckLoader::getCompleteCardName(const QString &cardName) const { if (db) { CardInfoPtr temp = db->guessCard(cardName); diff --git a/cockatrice/src/deck_loader.h b/cockatrice/src/deck_loader.h index ac8926f2..721d1c78 100644 --- a/cockatrice/src/deck_loader.h +++ b/cockatrice/src/deck_loader.h @@ -58,7 +58,7 @@ protected: QList cards, bool addComments = true); virtual QString getCardZoneFromName(QString cardName, QString currentZoneName); - virtual QString getCompleteCardName(const QString cardName) const; + virtual QString getCompleteCardName(const QString &cardName) const; }; #endif diff --git a/common/decklist.cpp b/common/decklist.cpp index 09ceb2b7..cd1a4352 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -488,34 +488,33 @@ bool DeckList::saveToFile_Native(QIODevice *device) bool DeckList::loadFromStream_Plain(QTextStream &in) { - const QRegularExpression reCardLine("^\\s*[\\w\\[\\(\\{].*$", QRegularExpression::UseUnicodePropertiesOption); + const QRegularExpression reCardLine(R"(^\s*[\w\[\(\{].*$)", QRegularExpression::UseUnicodePropertiesOption); const QRegularExpression reEmpty("^\\s*$"); - const QRegularExpression reComment("[\\w\\[\\(\\{].*$", QRegularExpression::UseUnicodePropertiesOption); + const QRegularExpression reComment(R"([\w\[\(\{].*$)", QRegularExpression::UseUnicodePropertiesOption); const QRegularExpression reSBMark("^\\s*sb:\\s*(.+)", QRegularExpression::CaseInsensitiveOption); const QRegularExpression reSBComment("^sideboard\\b.*$", QRegularExpression::CaseInsensitiveOption); const QRegularExpression reDeckComment("^((main)?deck(list)?|mainboard)\\b", QRegularExpression::CaseInsensitiveOption); // simplified matches - const QRegularExpression reMultiplier("^[xX\\(\\[]*(\\d+)[xX\\*\\)\\]]* ?(.+)"); - const QRegularExpression reBrace(" ?[\\[\\{][^\\]\\}]*[\\]\\}] ?"); // not nested - const QRegularExpression reRoundBrace("^\\([^\\)]*\\) ?"); // () are only matched at start of string - const QRegularExpression reDigitBrace(" ?\\(\\d*\\) ?"); // () are matched if containing digits - const QRegularExpression reBraceDigit( - " ?\\([\\dA-Z]+\\) *\\d+$"); // () are matched if containing setcode then a number + const QRegularExpression reMultiplier(R"(^[xX\(\[]*(\d+)[xX\*\)\]]* ?(.+))"); + const QRegularExpression reBrace(R"( ?[\[\{][^\]\}]*[\]\}] ?)"); // not nested + const QRegularExpression reRoundBrace(R"(^\([^\)]*\) ?)"); // () are only matched at start of string + const QRegularExpression reDigitBrace(R"( ?\(\d*\) ?)"); // () are matched if containing digits + // () are matched if containing setcode then a number + const QRegularExpression reBraceDigit(R"( ?\([\dA-Z]+\) *\d+$)"); const QHash differences{{QRegularExpression("’"), QString("'")}, {QRegularExpression("Æ"), QString("Ae")}, {QRegularExpression("æ"), QString("ae")}, - {QRegularExpression(" ?[|/]+ ?"), QString(" // ")}, - {QRegularExpression("(?size(); i++) { auto *node = dynamic_cast(root->at(i)); diff --git a/common/decklist.h b/common/decklist.h index 3323dc99..4fe2d34a 100644 --- a/common/decklist.h +++ b/common/decklist.h @@ -178,14 +178,14 @@ private: QMap sideboardPlans; InnerDecklistNode *root; void getCardListHelper(InnerDecklistNode *node, QSet &result) const; - InnerDecklistNode *getZoneObjFromName(QString zoneName); + InnerDecklistNode *getZoneObjFromName(const QString &zoneName); protected: virtual QString getCardZoneFromName(const QString /*cardName*/, QString currentZoneName) { return currentZoneName; }; - virtual QString getCompleteCardName(const QString cardName) const + virtual QString getCompleteCardName(const QString &cardName) const { return cardName; }; diff --git a/tests/loading_from_clipboard/loading_from_clipboard_test.cpp b/tests/loading_from_clipboard/loading_from_clipboard_test.cpp index de5fb2e3..6f9762be 100644 --- a/tests/loading_from_clipboard/loading_from_clipboard_test.cpp +++ b/tests/loading_from_clipboard/loading_from_clipboard_test.cpp @@ -127,9 +127,10 @@ TEST(LoadingFromClipboardTest, EdgeCaseTesting) //(test) Æ ’ | / (3) -// Mainboard (10 cards) +// Mainboard (11 cards) Æther Adept -2x Fire & Ice +2x Fire // Ice +1 Minsc & Boo, Timeless Heroes 3 Pain/Suffering 4X [B] Forest (3) @@ -145,7 +146,11 @@ TEST(LoadingFromClipboardTest, EdgeCaseTesting) )"); Result result("DeckName", "Comment 1\n\nComment [two]\n(test) Æ ’ | / (3)", - {{"Aether Adept", 1}, {"Fire // Ice", 2}, {"Pain // Suffering", 3}, {"Forest", 4}}, + {{"Aether Adept", 1}, + {"Fire // Ice", 2}, + {"Minsc & Boo, Timeless Heroes", 1}, + {"Pain // Suffering", 3}, + {"Forest", 4}}, {{"Nature's Resurgence", 5}, {"Gaea's Skyfolk", 6}, {"B.F.M. (Big Furry Monster)", 7}}); testDeck(clipboard, result); }