diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index 2b71c9e16..7b27b2d7d 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -100,6 +100,27 @@ QString OracleImporter::getMainCardType(const QStringList &typeList) return typeList.first(); } +/** + * Sorts and deduplicates the color chars in the string by WUBRG order. + * + * @param colors The string containing the color chars. Will be modified in-place + */ +static void sortAndReduceColors(QString &colors) +{ + // sort + static const QHash colorOrder{{'W', 0}, {'U', 1}, {'B', 2}, {'R', 3}, {'G', 4}}; + std::sort(colors.begin(), colors.end(), + [](const QChar a, const QChar b) { return colorOrder.value(a, INT_MAX) < colorOrder.value(b, INT_MAX); }); + // reduce + QChar lastChar = '\0'; + for (int i = 0; i < colors.size(); ++i) { + if (colors.at(i) == lastChar) + colors.remove(i, 1); + else + lastChar = colors.at(i); + } +} + CardInfoPtr OracleImporter::addCard(QString name, QString text, bool isToken, @@ -189,7 +210,7 @@ CardInfoPtr OracleImporter::addCard(QString name, return newCard; } -QString OracleImporter::getStringPropertyFromMap(const QVariantMap &card, const QString &propertyName) +static QString getStringPropertyFromMap(const QVariantMap &card, const QString &propertyName) { return card.contains(propertyName) ? card.value(propertyName).toString() : QString(""); } @@ -434,23 +455,6 @@ int OracleImporter::importCardsFromSet(const CardSetPtr ¤tSet, const QList return numCards; } -void OracleImporter::sortAndReduceColors(QString &colors) -{ - // sort - const QHash colorOrder{{'W', 0}, {'U', 1}, {'B', 2}, {'R', 3}, {'G', 4}}; - std::sort(colors.begin(), colors.end(), [&colorOrder](const QChar a, const QChar b) { - return colorOrder.value(a, INT_MAX) < colorOrder.value(b, INT_MAX); - }); - // reduce - QChar lastChar = '\0'; - for (int i = 0; i < colors.size(); ++i) { - if (colors.at(i) == lastChar) - colors.remove(i, 1); - else - lastChar = colors.at(i); - } -} - int OracleImporter::startImport() { int setCards = 0, setIndex = 0; diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index 21a5d4405..02a797115 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -164,10 +164,6 @@ public: return allSets; } void clear(); - -protected: - inline QString getStringPropertyFromMap(const QVariantMap &card, const QString &propertyName); - void sortAndReduceColors(QString &colors); }; #endif