mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
optimization?
This commit is contained in:
parent
f50d2acf8a
commit
2f1d97b5e0
1 changed files with 16 additions and 6 deletions
|
|
@ -23,16 +23,26 @@
|
||||||
*/
|
*/
|
||||||
bool parseCipt(const QString &name, const QString &text)
|
bool parseCipt(const QString &name, const QString &text)
|
||||||
{
|
{
|
||||||
// try to split shortname on all non-alphanumeric characters (including _)
|
// Try to split shortname on most non-alphanumeric characters (including _)
|
||||||
static auto SHORTNAME_DIVIDERS = QRegularExpression("[^\\w]|_");
|
static QSet<QChar> exceptions = {'\'', '\"'};
|
||||||
|
static auto isShortnameDivider = [](const QChar &c) {
|
||||||
|
return c == '_' || (!c.isLetterOrNumber() && !exceptions.contains(c));
|
||||||
|
};
|
||||||
|
|
||||||
// Try all possible shortnames.
|
// Try all possible shortnames.
|
||||||
// This also handles the case of extra text appended at end.
|
// This also handles the case of extra text appended at end.
|
||||||
QStringList possibleNames;
|
QStringList possibleNames;
|
||||||
qsizetype i = 0;
|
bool inAlphanumericPart = true;
|
||||||
while ((i = name.indexOf(SHORTNAME_DIVIDERS, i)) != -1) {
|
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.first(i)));
|
possibleNames.append(QRegularExpression::escape(name.first(i)));
|
||||||
++i;
|
inAlphanumericPart = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inAlphanumericPart = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// and the full name
|
// and the full name
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue