From 0eb97c91b38f0096cc32044c4e5973d76155cfb9 Mon Sep 17 00:00:00 2001 From: arxanas Date: Sat, 19 Jul 2014 14:47:19 -0400 Subject: [PATCH] Fix #183: Deck parser doesn't too eagerly replace ampersands. --- common/decklist.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/decklist.cpp b/common/decklist.cpp index 8e877ba9..f2808337 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -563,9 +563,20 @@ bool DeckList::loadFromStream_Plain(QTextStream &in) cardName.replace(rx, "AE"); rx.setPattern("^Aether"); cardName.replace(rx, "AEther"); - rx.setPattern("\\s*[&|/]{1,2}\\s*"); + rx.setPattern("\\s*[|/]{1,2}\\s*"); cardName.replace(rx, " // "); + // Replace only if the ampersand is preceded by a non-capital letter, + // as would happen with acronyms. So 'Fire & Ice' is replaced but not + // 'R&D' or 'R & D'. + // + // Qt regexes don't support lookbehind so we capture and replace + // instead. + rx.setPattern("([^A-Z])\\s*&\\s*"); + if (rx.indexIn(cardName) != -1) { + cardName.replace(rx, QString("%1 // ").arg(rx.cap(1))); + } + ++okRows; new DecklistCardNode(cardName, number, zone); }