mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-05-07 22:33:22 -05:00
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, 12) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, skip, 11) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, 41) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, skip, 40) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, 24.04) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 20.04) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 22.04) (push) Blocked by required conditions
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (yes, Arch, skip) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, 1, macos-14, Apple, 14, Release, 15.4) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, 1, macos-15, Apple, 15, Release, 16.2) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, macos-15, Apple, 15, Debug, 16.2) (push) Blocked by required conditions
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (4, 1, macos-13, Intel, 13, Release, 14.3.1) (push) Blocked by required conditions
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, 5.15.*, 7) (push) Blocked by required conditions
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, qtimageformats qtmultimedia qtwebsockets, 6.6.*, 10) (push) Blocked by required conditions
70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
#include "parsehelpers.h"
|
|
|
|
#include <QChar>
|
|
#include <QRegularExpression>
|
|
|
|
/**
|
|
* Parses the card text to determine if the card should have the cipt tag
|
|
*
|
|
* The parsing logic is able to handle the following cases:
|
|
* - "<name> enters tapped"
|
|
* - "<shortname> enters tapped", if the card name starts with the shortname
|
|
* - "This <type> enters tapped"
|
|
* - "..., it enters tapped"
|
|
* - Any naming scheme that appends a non-alphanumeric character plus extra text to the end of the name.
|
|
* (e.g. name is "Card Name_SET" or "Card Name (Set)" and text contains "Card Name enters tapped")
|
|
*
|
|
* However, it will still miss on certain cases:
|
|
* - shortnames that aren't the at the beginning of the card name
|
|
*
|
|
* Note that "...enters tapped unless..." returns false.
|
|
*
|
|
* @param name The name of the card
|
|
* @param text The oracle text of the card
|
|
*/
|
|
bool parseCipt(const QString &name, const QString &text)
|
|
{
|
|
// Use precompiled regex to check if text is a possible candidate, and early return if not
|
|
static auto prelimCheck = QRegularExpression(" enters( the battlefield)? tapped(?! unless)");
|
|
if (!prelimCheck.match(text).hasMatch()) {
|
|
return false;
|
|
}
|
|
|
|
// Try to split shortname on most non-alphanumeric characters (including _)
|
|
auto isShortnameDivider = [](const QChar &c) {
|
|
return c == '_' || (!c.isLetterOrNumber() && c != '\'' && c != '\"');
|
|
};
|
|
|
|
// Try all possible shortnames.
|
|
// This also handles the case of extra text appended at end.
|
|
QStringList possibleNames;
|
|
bool inAlphanumericPart = true;
|
|
for (int i = 0; i < name.length(); ++i) {
|
|
if (isShortnameDivider(name.at(i))) {
|
|
if (inAlphanumericPart) {
|
|
// only add to names on a "falling edge", in order to reduce the amount of redundant splits
|
|
possibleNames.append(QRegularExpression::escape(name.left(i)));
|
|
inAlphanumericPart = false;
|
|
}
|
|
} else {
|
|
inAlphanumericPart = true;
|
|
}
|
|
}
|
|
|
|
// and the full name
|
|
possibleNames.append(QRegularExpression::escape(name));
|
|
|
|
QString subject = "(it|" // "..., it enters tapped"
|
|
"(T|t)his [^ ]+|" // "This <type> enters tapped"
|
|
+ possibleNames.join("|") + ")";
|
|
|
|
auto ciptPattern = QRegularExpression(
|
|
// cipt phrase is either first sentence of line, or is after a punctuation mark
|
|
"(^|(, |\\. ))" + subject +
|
|
// support old wording, and exclude the "unless" case
|
|
" enters( the battlefield)? tapped(?! unless)",
|
|
QRegularExpression::MultilineOption);
|
|
|
|
return ciptPattern.match(text).hasMatch();
|
|
}
|