use static (And const where applicable) regular expression objects
the speed increase here is noticable since the work of creating a regex object is only done once per session
This commit is contained in:
parent
d1bdbc2741
commit
37fcfba829
18 changed files with 79 additions and 56 deletions
|
@ -92,7 +92,7 @@ void KeyValueConfigBase::load() {
|
|||
|
||||
QTextStream in(&file);
|
||||
QList<QString> configLines;
|
||||
QRegularExpression re("^(?<key>[^=]+)=(?<value>.*)$");
|
||||
static const QRegularExpression re("^(?<key>[^=]+)=(?<value>.*)$");
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine().trimmed();
|
||||
int commentIndex = line.indexOf("#");
|
||||
|
@ -1132,7 +1132,7 @@ QString ShortcutsConfig::cfgKey(const QObject *object) const {
|
|||
cfg_key = parentWidget->window()->objectName() + '_';
|
||||
cfg_key += object->objectName();
|
||||
|
||||
QRegularExpression re("[A-Z]");
|
||||
static const QRegularExpression re("[A-Z]");
|
||||
int i = cfg_key.indexOf(re, 1);
|
||||
while (i != -1) {
|
||||
if (cfg_key.at(i - 1) != '_')
|
||||
|
|
|
@ -31,9 +31,11 @@ void Map::setName(QString mapName) {
|
|||
|
||||
QString Map::mapConstantFromName(QString mapName) {
|
||||
// Transform map names of the form 'GraniteCave_B1F` into map constants like 'MAP_GRANITE_CAVE_B1F'.
|
||||
QString nameWithUnderscores = mapName.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
|
||||
static const QRegularExpression caseChange("([a-z])([A-Z])");
|
||||
QString nameWithUnderscores = mapName.replace(caseChange, "\\1_\\2");
|
||||
QString withMapAndUppercase = "MAP_" + nameWithUnderscores.toUpper();
|
||||
QString constantName = withMapAndUppercase.replace(QRegularExpression("_+"), "_");
|
||||
static const QRegularExpression underscores("_+");
|
||||
QString constantName = withMapAndUppercase.replace(underscores, "_");
|
||||
|
||||
// Handle special cases.
|
||||
// SSTidal needs to be SS_TIDAL, rather than SSTIDAL
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
QString MapLayout::layoutConstantFromName(QString mapName) {
|
||||
// Transform map names of the form 'GraniteCave_B1F` into layout constants like 'LAYOUT_GRANITE_CAVE_B1F'.
|
||||
QString nameWithUnderscores = mapName.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
|
||||
static const QRegularExpression caseChange("([a-z])([A-Z])");
|
||||
QString nameWithUnderscores = mapName.replace(caseChange, "\\1_\\2");
|
||||
QString withMapAndUppercase = "LAYOUT_" + nameWithUnderscores.toUpper();
|
||||
QString constantName = withMapAndUppercase.replace(QRegularExpression("_+"), "_");
|
||||
static const QRegularExpression underscores("_+");
|
||||
QString constantName = withMapAndUppercase.replace(underscores, "_");
|
||||
|
||||
// Handle special cases.
|
||||
// SSTidal should be SS_TIDAL, rather than SSTIDAL
|
||||
|
|
|
@ -118,7 +118,7 @@ QList<QRgb> parseJASC(QString filepath, bool *error) {
|
|||
}
|
||||
|
||||
QList<QRgb> palette;
|
||||
QRegularExpression re("(?<red>\\d+)\\s(?<green>\\d+)\\s(?<blue>\\d+)");
|
||||
static const QRegularExpression re("(?<red>\\d+)\\s(?<green>\\d+)\\s(?<blue>\\d+)");
|
||||
while (!in.atEnd() && numColors > 0) {
|
||||
numColors--;
|
||||
QString line = in.readLine();
|
||||
|
|
|
@ -40,7 +40,8 @@ void ParseUtil::logRecordedErrors() {
|
|||
}
|
||||
|
||||
QString ParseUtil::createErrorMessage(const QString &message, const QString &expression) {
|
||||
QStringList lines = this->text.split(QRegularExpression("[\r\n]"));
|
||||
static const QRegularExpression newline("[\r\n]");
|
||||
QStringList lines = this->text.split(newline);
|
||||
int lineNum = 0, colNum = 0;
|
||||
for (QString line : lines) {
|
||||
lineNum++;
|
||||
|
@ -90,9 +91,11 @@ QList<QStringList> ParseUtil::parseAsm(const QString &filename) {
|
|||
// There should not be anything else on the line.
|
||||
// gas will raise a syntax error if there is.
|
||||
} else {
|
||||
int index = trimmedLine.indexOf(QRegularExpression("\\s+"));
|
||||
static const QRegularExpression re_spaces("\\s+");
|
||||
int index = trimmedLine.indexOf(re_spaces);
|
||||
const QString macro = trimmedLine.left(index);
|
||||
QStringList params(trimmedLine.right(trimmedLine.length() - index).trimmed().split(QRegularExpression("\\s*,\\s*")));
|
||||
static const QRegularExpression re_spacesCommaSpaces("\\s*,\\s*");
|
||||
QStringList params(trimmedLine.right(trimmedLine.length() - index).trimmed().split(re_spacesCommaSpaces));
|
||||
params.prepend(macro);
|
||||
parsed.append(params);
|
||||
}
|
||||
|
@ -110,7 +113,7 @@ QList<Token> ParseUtil::tokenizeExpression(QString expression, const QMap<QStrin
|
|||
QList<Token> tokens;
|
||||
|
||||
QStringList tokenTypes = (QStringList() << "hex" << "decimal" << "identifier" << "operator" << "leftparen" << "rightparen");
|
||||
QRegularExpression re("^(?<hex>0x[0-9a-fA-F]+)|(?<decimal>[0-9]+)|(?<identifier>[a-zA-Z_0-9]+)|(?<operator>[+\\-*\\/<>|^%]+)|(?<leftparen>\\()|(?<rightparen>\\))");
|
||||
static const QRegularExpression re("^(?<hex>0x[0-9a-fA-F]+)|(?<decimal>[0-9]+)|(?<identifier>[a-zA-Z_0-9]+)|(?<operator>[+\\-*\\/<>|^%]+)|(?<leftparen>\\()|(?<rightparen>\\))");
|
||||
|
||||
expression = expression.trimmed();
|
||||
while (!expression.isEmpty()) {
|
||||
|
@ -257,7 +260,7 @@ QString ParseUtil::readCIncbin(const QString &filename, const QString &label) {
|
|||
|
||||
this->text = readTextFile(this->root + "/" + filename);
|
||||
|
||||
QRegularExpression re(QString(
|
||||
static const QRegularExpression re(QString(
|
||||
"\\b%1\\b"
|
||||
"\\s*\\[?\\s*\\]?\\s*=\\s*"
|
||||
"INCBIN_[US][0-9][0-9]?"
|
||||
|
@ -282,14 +285,14 @@ QStringList ParseUtil::readCIncbinArray(const QString &filename, const QString &
|
|||
this->text = readTextFile(this->root + "/" + filename);
|
||||
|
||||
// Get the text starting after the label all the way to the definition's end
|
||||
QRegularExpression re(QString("\\b%1\\b(.*?)};").arg(label), QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpressionMatch arrayMatch = re.match(this->text);
|
||||
static const QRegularExpression re_labelGroup(QString("\\b%1\\b(.*?)};").arg(label), QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpressionMatch arrayMatch = re_labelGroup.match(this->text);
|
||||
if (!arrayMatch.hasMatch())
|
||||
return paths;
|
||||
|
||||
// Extract incbin paths from the array
|
||||
re.setPattern("INCBIN_[US][0-9][0-9]?\\(\\s*\"([^\"]*)\"\\s*\\)");
|
||||
QRegularExpressionMatchIterator iter = re.globalMatch(arrayMatch.captured(1));
|
||||
static const QRegularExpression re_incbin("INCBIN_[US][0-9][0-9]?\\(\\s*\"([^\"]*)\"\\s*\\)");
|
||||
QRegularExpressionMatchIterator iter = re_incbin.globalMatch(arrayMatch.captured(1));
|
||||
while (iter.hasNext()) {
|
||||
paths.append(iter.next().captured(1));
|
||||
}
|
||||
|
@ -316,12 +319,14 @@ QMap<QString, int> ParseUtil::readCDefines(const QString &filename,
|
|||
return filteredDefines;
|
||||
}
|
||||
|
||||
this->text.replace(QRegularExpression("(//.*)|(\\/+\\*+[^*]*\\*+\\/+)"), "");
|
||||
this->text.replace(QRegularExpression("(\\\\\\s+)"), "");
|
||||
static const QRegularExpression re_extraChars("(//.*)|(\\/+\\*+[^*]*\\*+\\/+)");
|
||||
this->text.replace(re_extraChars, "");
|
||||
static const QRegularExpression re_extraSpaces("(\\\\\\s+)");
|
||||
this->text.replace(re_extraSpaces, "");
|
||||
allDefines.insert("FALSE", 0);
|
||||
allDefines.insert("TRUE", 1);
|
||||
|
||||
QRegularExpression re("#define\\s+(?<defineName>\\w+)[^\\S\\n]+(?<defineValue>.+)");
|
||||
static const QRegularExpression re("#define\\s+(?<defineName>\\w+)[^\\S\\n]+(?<defineValue>.+)");
|
||||
QRegularExpressionMatchIterator iter = re.globalMatch(this->text);
|
||||
this->errorMap.clear();
|
||||
while (iter.hasNext()) {
|
||||
|
@ -368,7 +373,7 @@ QStringList ParseUtil::readCArray(const QString &filename, const QString &label)
|
|||
this->file = filename;
|
||||
this->text = readTextFile(this->root + "/" + filename);
|
||||
|
||||
QRegularExpression re(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
||||
static const QRegularExpression re(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
||||
QRegularExpressionMatch match = re.match(this->text);
|
||||
|
||||
if (match.hasMatch()) {
|
||||
|
@ -376,7 +381,8 @@ QStringList ParseUtil::readCArray(const QString &filename, const QString &label)
|
|||
QStringList split = body.split(',');
|
||||
for (QString item : split) {
|
||||
item = item.trimmed();
|
||||
if (!item.contains(QRegularExpression("[^A-Za-z0-9_&()\\s]"))) list.append(item);
|
||||
static const QRegularExpression validChars("[^A-Za-z0-9_&()\\s]");
|
||||
if (!item.contains(validChars)) list.append(item);
|
||||
// do not print error info here because this is called dozens of times
|
||||
}
|
||||
}
|
||||
|
@ -388,10 +394,11 @@ QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename,
|
|||
this->text = readTextFile(this->root + "/" + filename);
|
||||
QMap<QString, QString> map;
|
||||
|
||||
QRegularExpression re_text(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
||||
QString body = re_text.match(this->text).captured(2).replace(QRegularExpression("\\s*"), "");
|
||||
static const QRegularExpression re_text(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
||||
static const QRegularExpression re_spaces("\\s*");
|
||||
QString body = re_text.match(this->text).captured(2).replace(re_spaces, "");
|
||||
|
||||
QRegularExpression re("\\[(?<index>[A-Za-z0-9_]*)\\]=(?<value>&?[A-Za-z0-9_]*)");
|
||||
static const QRegularExpression re("\\[(?<index>[A-Za-z0-9_]*)\\]=(?<value>&?[A-Za-z0-9_]*)");
|
||||
QRegularExpressionMatchIterator iter = re.globalMatch(body);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
|
|
@ -161,8 +161,8 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
ParseUtil parser;
|
||||
QString text = parser.readTextFile(fullPath(this->layout_path));
|
||||
|
||||
QRegularExpression re("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)"
|
||||
"(\\[(?<const_1>[A-Za-z0-9_]+)\\])(\\[(?<const_2>[A-Za-z0-9_]+)\\])(\\[(?<const_3>[A-Za-z0-9_]+)\\])\\s+=");
|
||||
static const QRegularExpression re("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)"
|
||||
"(\\[(?<const_1>[A-Za-z0-9_]+)\\])(\\[(?<const_2>[A-Za-z0-9_]+)\\])(\\[(?<const_3>[A-Za-z0-9_]+)\\])\\s+=");
|
||||
|
||||
// check for layers, extract info
|
||||
QRegularExpressionMatch match = re.match(text);
|
||||
|
@ -179,7 +179,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
this->layout_array_label = label;
|
||||
|
||||
// find layers
|
||||
QRegularExpression reLayers("(?<layer>\\[(?<label>LAYER_[A-Za-z0-9_]+)\\][^\\[\\]]+)");
|
||||
static const QRegularExpression reLayers("(?<layer>\\[(?<label>LAYER_[A-Za-z0-9_]+)\\][^\\[\\]]+)");
|
||||
QRegularExpressionMatchIterator i = reLayers.globalMatch(text);
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch m = i.next();
|
||||
|
@ -187,7 +187,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
QString layerName = m.captured("label");
|
||||
QString layerLayout = m.captured("layer");
|
||||
|
||||
QRegularExpression rowRe("{(?<row>[A-Z0-9_, ]+)}");
|
||||
static const QRegularExpression rowRe("{(?<row>[A-Z0-9_, ]+)}");
|
||||
QRegularExpressionMatchIterator j = rowRe.globalMatch(layerLayout);
|
||||
|
||||
this->layout_layers.append(layerName);
|
||||
|
@ -217,7 +217,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
|
||||
} else {
|
||||
// try single-layered
|
||||
QRegularExpression reAlt("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)\\[\\]");
|
||||
static const QRegularExpression reAlt("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)\\[\\]");
|
||||
QRegularExpressionMatch matchAlt = reAlt.match(text);
|
||||
if (matchAlt.hasMatch()) {
|
||||
// single dimensional
|
||||
|
@ -228,7 +228,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
this->layout_qualifiers = qualifiers + " " + type;
|
||||
this->layout_array_label = label;
|
||||
|
||||
QRegularExpression reSec("(?<sec>MAPSEC_[A-Za-z0-9_]+)");
|
||||
static const QRegularExpression reSec("(?<sec>MAPSEC_[A-Za-z0-9_]+)");
|
||||
QRegularExpressionMatchIterator k = reSec.globalMatch(text);
|
||||
|
||||
QList<LayoutSquare> layout;
|
||||
|
@ -252,7 +252,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
this->layout_layers.append("main");
|
||||
setLayout("main", layout);
|
||||
} else {
|
||||
QRegularExpression reAlt2("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)"
|
||||
static const QRegularExpression reAlt2("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)"
|
||||
"(\\[(?<const_1>[A-Za-z0-9_]+)\\])(\\[(?<const_2>[A-Za-z0-9_]+)\\])\\s+=");
|
||||
QRegularExpressionMatch matchAlt2 = reAlt2.match(text);
|
||||
if (matchAlt2.hasMatch()) {
|
||||
|
@ -267,7 +267,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
|
|||
this->layout_qualifiers = qualifiers + " " + type;
|
||||
this->layout_array_label = label;
|
||||
|
||||
QRegularExpression rowRe("{(?<row>[A-Z0-9_, ]+)}");
|
||||
static const QRegularExpression rowRe("{(?<row>[A-Z0-9_, ]+)}");
|
||||
QRegularExpressionMatchIterator k = rowRe.globalMatch(text);
|
||||
|
||||
this->layout_layers.append("main");
|
||||
|
@ -779,7 +779,8 @@ QString RegionMap::fixCase(QString caps) {
|
|||
bool big = true;
|
||||
QString camel;
|
||||
|
||||
for (auto ch : caps.remove(QRegularExpression("({.*})")).remove("MAPSEC")) {
|
||||
static const QRegularExpression re_braced("({.*})");
|
||||
for (auto ch : caps.remove(re_braced).remove("MAPSEC")) {
|
||||
if (ch == '_' || ch == ' ') {
|
||||
big = true;
|
||||
continue;
|
||||
|
|
|
@ -258,7 +258,7 @@ QString Tileset::getExpectedDir()
|
|||
|
||||
QString Tileset::getExpectedDir(QString tilesetName, bool isSecondary)
|
||||
{
|
||||
QRegularExpression re("([a-z])([A-Z0-9])");
|
||||
static const QRegularExpression re("([a-z])([A-Z0-9])");
|
||||
const QString category = isSecondary ? "secondary" : "primary";
|
||||
const QString basePath = projectConfig.getFilePath(ProjectFilePath::data_tilesets_folders) + category + "/";
|
||||
return basePath + tilesetName.replace("gTileset_", "").replace(re, "\\1_\\2").toLower();
|
||||
|
|
|
@ -261,7 +261,8 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
|||
QLineEdit *lineEdit = new QLineEdit();
|
||||
lineEdit->setClearButtonEnabled(true);
|
||||
form.addRow(new QLabel("Group Base Label:"), lineEdit);
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(QRegularExpression("[_A-Za-z0-9]*"));
|
||||
static const QRegularExpression re_validChars("[_A-Za-z0-9]*");
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(re_validChars);
|
||||
lineEdit->setValidator(validator);
|
||||
connect(lineEdit, &QLineEdit::textChanged, [this, &lineEdit, &buttonBox](QString text){
|
||||
if (this->project->encounterGroupLabels.contains(text)) {
|
||||
|
|
|
@ -920,7 +920,8 @@ void Project::saveTilesetMetatileLabels(Tileset *primaryTileset, Tileset *second
|
|||
}
|
||||
|
||||
auto getTilesetFromLabel = [](QString labelName) {
|
||||
return QRegularExpression("METATILE_(?<tileset>[A-Za-z0-9]+)_").match(labelName).captured("tileset");
|
||||
static const QRegularExpression re_tilesetName("METATILE_(?<tileset>[A-Za-z0-9]+)_");
|
||||
return re_tilesetName.match(labelName).captured("tileset");
|
||||
};
|
||||
|
||||
QString outputText = "#ifndef GUARD_METATILE_LABELS_H\n";
|
||||
|
@ -1410,10 +1411,12 @@ void Project::loadTilesetPalettes(Tileset* tileset) {
|
|||
QString path = tileset->palettePaths.value(i);
|
||||
QString text = parser.readTextFile(path);
|
||||
if (!text.isNull()) {
|
||||
QStringList lines = text.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
|
||||
static const QRegularExpression re_lineBreak("[\r\n]");
|
||||
QStringList lines = text.split(re_lineBreak, Qt::SkipEmptyParts);
|
||||
if (lines.length() == 19 && lines[0] == "JASC-PAL" && lines[1] == "0100" && lines[2] == "16") {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
QStringList rgb = lines[j + 3].split(QRegularExpression(" "), Qt::SkipEmptyParts);
|
||||
static const QRegularExpression re_space(" ");
|
||||
QStringList rgb = lines[j + 3].split(re_space, Qt::SkipEmptyParts);
|
||||
if (rgb.length() != 3) {
|
||||
logWarn(QString("Invalid tileset palette RGB value: '%1'").arg(lines[j + 3]));
|
||||
palette.append(qRgb((j - 3) * 16, (j - 3) * 16, (j - 3) * 16));
|
||||
|
@ -1827,7 +1830,7 @@ bool Project::readTilesetLabels() {
|
|||
logError(QString("Failed to read tileset labels from '%1' or '%2'.").arg(filename).arg(asm_filename));
|
||||
return false;
|
||||
}
|
||||
QRegularExpression re("(?<label>[A-Za-z0-9_]*):{1,2}[A-Za-z0-9_@ ]*\\s+.+\\s+\\.byte\\s+(?<isSecondary>[A-Za-z0-9_]+)");
|
||||
static const QRegularExpression re("(?<label>[A-Za-z0-9_]*):{1,2}[A-Za-z0-9_@ ]*\\s+.+\\s+\\.byte\\s+(?<isSecondary>[A-Za-z0-9_]+)");
|
||||
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
||||
while (iter.hasNext()) {
|
||||
QRegularExpressionMatch match = iter.next();
|
||||
|
@ -1986,7 +1989,8 @@ bool Project::readHealLocations() {
|
|||
QString text = parser.readTextFile(root + "/" + filename);
|
||||
|
||||
// Strip comments
|
||||
text.replace(QRegularExpression("//.*?(\r\n?|\n)|/\\*.*?\\*/", QRegularExpression::DotMatchesEverythingOption), "");
|
||||
static const QRegularExpression re_comments("//.*?(\r\n?|\n)|/\\*.*?\\*/", QRegularExpression::DotMatchesEverythingOption);
|
||||
text.replace(re_comments, "");
|
||||
|
||||
bool respawnEnabled = projectConfig.getHealLocationRespawnDataEnabled();
|
||||
|
||||
|
@ -1995,7 +1999,7 @@ bool Project::readHealLocations() {
|
|||
this->healLocationDataQualifiers = this->getDataQualifiers(text, tableName);
|
||||
|
||||
// Create regex pattern for the constants (ex: "SPAWN_PALLET_TOWN" or "HEAL_LOCATION_PETALBURG_CITY")
|
||||
QRegularExpression constantsExpr = QRegularExpression("(SPAWN|HEAL_LOCATION)_[A-Za-z0-9_]+");
|
||||
static const QRegularExpression constantsExpr("(SPAWN|HEAL_LOCATION)_[A-Za-z0-9_]+");
|
||||
|
||||
// Find all the unique heal location constants used in the data tables.
|
||||
// Porymap doesn't care whether or not a constant appeared in the heal locations constants file.
|
||||
|
@ -2304,13 +2308,16 @@ bool Project::readEventScriptLabels() {
|
|||
}
|
||||
|
||||
QString Project::fixPalettePath(QString path) {
|
||||
path = path.replace(QRegularExpression("\\.gbapal$"), ".pal");
|
||||
static const QRegularExpression re_gbapal("\\.gbapal$");
|
||||
path = path.replace(re_gbapal, ".pal");
|
||||
return path;
|
||||
}
|
||||
|
||||
QString Project::fixGraphicPath(QString path) {
|
||||
path = path.replace(QRegularExpression("\\.lz$"), "");
|
||||
path = path.replace(QRegularExpression("\\.[1248]bpp$"), ".png");
|
||||
static const QRegularExpression re_lz("\\.lz$");
|
||||
path = path.replace(re_lz, "");
|
||||
static const QRegularExpression re_bpp("\\.[1248]bpp$");
|
||||
path = path.replace(re_bpp, ".png");
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -2416,7 +2423,8 @@ bool Project::readEventGraphics() {
|
|||
QString subsprites_label = gfxInfoAttributes.value("subspriteTables");
|
||||
|
||||
QString gfx_label = parser.readCArray(projectConfig.getFilePath(ProjectFilePath::data_obj_event_pic_tables), pic_label).value(0);
|
||||
gfx_label = gfx_label.section(QRegularExpression("[\\(\\)]"), 1, 1);
|
||||
static const QRegularExpression re_parens("[\\(\\)]");
|
||||
gfx_label = gfx_label.section(re_parens, 1, 1);
|
||||
QString path = parser.readCIncbin(projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx), gfx_label);
|
||||
|
||||
if (!path.isNull()) {
|
||||
|
@ -2424,7 +2432,7 @@ bool Project::readEventGraphics() {
|
|||
eventGraphics->spritesheet = QImage(root + "/" + path);
|
||||
if (!eventGraphics->spritesheet.isNull()) {
|
||||
// Infer the sprite dimensions from the OAM labels.
|
||||
QRegularExpression re("\\S+_(\\d+)x(\\d+)");
|
||||
static const QRegularExpression re("\\S+_(\\d+)x(\\d+)");
|
||||
QRegularExpressionMatch dimensionMatch = re.match(dimensions_label);
|
||||
QRegularExpressionMatch oamTablesMatch = re.match(subsprites_label);
|
||||
if (oamTablesMatch.hasMatch()) {
|
||||
|
|
|
@ -609,7 +609,7 @@ void MainWindow::setMetatileLabel(int metatileId, QString label) {
|
|||
if (!metatile)
|
||||
return;
|
||||
|
||||
QRegularExpression expression("[_A-Za-z0-9]*$");
|
||||
static const QRegularExpression expression("[_A-Za-z0-9]*$");
|
||||
QRegularExpressionValidator validator(expression);
|
||||
int pos = 0;
|
||||
if (validator.validate(label, pos) != QValidator::Acceptable) {
|
||||
|
|
|
@ -18,7 +18,7 @@ AboutPorymap::~AboutPorymap()
|
|||
QList<int> AboutPorymap::getVersionNumbers()
|
||||
{
|
||||
// Get the version string "#.#.#"
|
||||
QRegularExpression regex("Version (\\d+)\\.(\\d+)\\.(\\d+)");
|
||||
static const QRegularExpression regex("Version (\\d+)\\.(\\d+)\\.(\\d+)");
|
||||
QRegularExpressionMatch match = regex.match(ui->label_Version->text());
|
||||
if (!match.hasMatch()) {
|
||||
logError("Failed to locate Porymap version text");
|
||||
|
|
|
@ -245,8 +245,10 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
|||
|
||||
// If map name is not unique, use default value. Also use only valid characters.
|
||||
// After stripping invalid characters, strip any leading digits.
|
||||
QString newMapName = this->ui->lineEdit_NewMap_Name->text().remove(QRegularExpression("[^a-zA-Z0-9_]+"));
|
||||
newMapName.remove(QRegularExpression("^[0-9]*"));
|
||||
static const QRegularExpression re_invalidChars("[^a-zA-Z0-9_]+");
|
||||
QString newMapName = this->ui->lineEdit_NewMap_Name->text().remove(re_invalidChars);
|
||||
static const QRegularExpression re_NaN("^[0-9]*");
|
||||
newMapName.remove(re_NaN);
|
||||
if (project->mapNames.contains(newMapName) || newMapName.isEmpty()) {
|
||||
newMapName = project->getNewMapName();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ NewTilesetDialog::NewTilesetDialog(Project* project, QWidget *parent) :
|
|||
this->setFixedSize(this->width(), this->height());
|
||||
this->project = project;
|
||||
//only allow characters valid for a symbol
|
||||
QRegularExpression expression("[_A-Za-z0-9]+$");
|
||||
static const QRegularExpression expression("[_A-Za-z0-9]+$");
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(expression);
|
||||
this->ui->nameLineEdit->setValidator(validator);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ NoScrollComboBox::NoScrollComboBox(QWidget *parent)
|
|||
this->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
||||
this->completer()->setFilterMode(Qt::MatchContains);
|
||||
|
||||
QRegularExpression re("[^\\s]*");
|
||||
static const QRegularExpression re("[^\\s]*");
|
||||
QValidator *validator = new QRegularExpressionValidator(re);
|
||||
this->setValidator(validator);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ PreferenceEditor::~PreferenceEditor()
|
|||
|
||||
void PreferenceEditor::populateFields() {
|
||||
QStringList themes = { "default" };
|
||||
QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
|
||||
static const QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
|
||||
QDirIterator it(":/themes", QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString themeName = re.match(it.next()).captured(1);
|
||||
|
|
|
@ -151,7 +151,7 @@ void RegionMapPropertiesDialog::accept() {
|
|||
ui->message_alias->setText("alias cannot be empty");
|
||||
ui->message_alias->setVisible(true);
|
||||
} else {
|
||||
QRegularExpression re("[A-Za-z0-9_\\- ]+");
|
||||
static const QRegularExpression re("[A-Za-z0-9_\\- ]+");
|
||||
int temp = 0;
|
||||
QRegularExpressionValidator v(re, 0);
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ void ShortcutsEditor::populateMainContainer() {
|
|||
QString ShortcutsEditor::getShortcutContext(const QObject *object) const {
|
||||
auto objectParentWidget = static_cast<QWidget *>(object->parent());
|
||||
auto context = objectParentWidget->window()->objectName();
|
||||
QRegularExpression re("[A-Z]");
|
||||
static const QRegularExpression re("[A-Z]");
|
||||
int i = context.indexOf(re, 1);
|
||||
while (i != -1) {
|
||||
if (context.at(i - 1) != ' ')
|
||||
|
|
|
@ -164,7 +164,7 @@ void TilesetEditor::setAttributesUi() {
|
|||
|
||||
void TilesetEditor::setMetatileLabelValidator() {
|
||||
//only allow characters valid for a symbol
|
||||
QRegularExpression expression("[_A-Za-z0-9]*$");
|
||||
static const QRegularExpression expression("[_A-Za-z0-9]*$");
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(expression);
|
||||
this->ui->lineEdit_metatileLabel->setValidator(validator);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue