mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[DeckList] Harden plain-text parser regexes and move metadata clearing up
This commit is contained in:
parent
d71b614c44
commit
9e312a0ef4
3 changed files with 15 additions and 19 deletions
|
|
@ -250,7 +250,10 @@ bool DeckList::loadFromStream_Plain(QTextStream &in,
|
|||
bool preserveMetadata,
|
||||
const std::function<QString(const QString &)> &cardNameNormalizer)
|
||||
{
|
||||
bool ok = DeckListPlainText::parse(in, preserveMetadata, cardNameNormalizer, metadata, tree);
|
||||
if (!preserveMetadata) {
|
||||
metadata = {};
|
||||
}
|
||||
bool ok = DeckListPlainText::parse(in, cardNameNormalizer, metadata, tree);
|
||||
refreshDeckHash();
|
||||
return ok;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,30 +10,26 @@ namespace DeckListPlainText
|
|||
{
|
||||
|
||||
bool parse(QTextStream &in,
|
||||
bool preserveMetadata,
|
||||
const std::function<QString(const QString &)> &cardNameNormalizer,
|
||||
DeckList::Metadata &metadata,
|
||||
DecklistNodeTree &tree)
|
||||
{
|
||||
tree.clear();
|
||||
if (!preserveMetadata) {
|
||||
metadata = {};
|
||||
}
|
||||
|
||||
const QRegularExpression reCardLine(R"(^\s*[\w\[\(\{].*$)", QRegularExpression::UseUnicodePropertiesOption);
|
||||
const QRegularExpression reEmpty("^\\s*$");
|
||||
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);
|
||||
static const QRegularExpression reCardLine(R"(^\s*[\w\[\(\{].*$)", QRegularExpression::UseUnicodePropertiesOption);
|
||||
static const QRegularExpression reEmpty("^\\s*$");
|
||||
static const QRegularExpression reComment(R"([\w\[\(\{].*$)", QRegularExpression::UseUnicodePropertiesOption);
|
||||
static const QRegularExpression reSBMark("^\\s*sb:\\s*(.+)", QRegularExpression::CaseInsensitiveOption);
|
||||
static const QRegularExpression reSBComment("^sideboard\\b.*$", QRegularExpression::CaseInsensitiveOption);
|
||||
static const QRegularExpression reDeckComment("^((main)?deck(list)?|mainboard)\\b",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
// Regex for advanced card parsing
|
||||
const QRegularExpression reMultiplier(R"(^[xX\(\[]*(\d+)[xX\*\)\]]* ?(.+))");
|
||||
static const QRegularExpression reMultiplier(R"(^[xX\(\[]*(\d+)[xX\*\)\]]* ?(.+))");
|
||||
|
||||
// Regex for extracting set code and collector number with attached symbols
|
||||
const QRegularExpression reHyphenFormat(R"(\((\w{3,})\)\s+(\w{3,})-(\d+[^\w\s]*))");
|
||||
const QRegularExpression reRegularFormat(R"(\((\w{3,})\)\s+(\d+[^\w\s]*))");
|
||||
static const QRegularExpression reHyphenFormat(R"(\((\w{3,})\)\s+(\w{3,})-(\d+[^\w\s]*))");
|
||||
static const QRegularExpression reRegularFormat(R"(\((\w{3,})\)\s+(\d+[^\w\s]*))");
|
||||
|
||||
auto inputs = in.readAll().trimmed().split('\n');
|
||||
auto max_line = inputs.size();
|
||||
|
|
|
|||
|
|
@ -14,11 +14,9 @@ namespace DeckListPlainText
|
|||
/**
|
||||
* @brief Parses a plain-text deck list into a tree and its metadata.
|
||||
*
|
||||
* Clears the tree first, and clears the metadata unless @p preserveMetadata is
|
||||
* true, then fills both from the text.
|
||||
* Clears the tree first, then fills both from the text.
|
||||
*
|
||||
* @param in The text to load
|
||||
* @param preserveMetadata If true, don't clear the existing metadata
|
||||
* @param cardNameNormalizer Function that takes the parsed card name string
|
||||
* in the text and returns the name to store
|
||||
* @param metadata Deck metadata written by the parser
|
||||
|
|
@ -26,7 +24,6 @@ namespace DeckListPlainText
|
|||
* @return False if the input was empty, true otherwise.
|
||||
*/
|
||||
bool parse(QTextStream &in,
|
||||
bool preserveMetadata,
|
||||
const std::function<QString(const QString &)> &cardNameNormalizer,
|
||||
DeckList::Metadata &metadata,
|
||||
DecklistNodeTree &tree);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue