fix const for dynamic regular expressions
This commit is contained in:
parent
c773b5c22a
commit
2f0894fb67
1 changed files with 30 additions and 18 deletions
|
@ -260,14 +260,14 @@ QString ParseUtil::readCIncbin(const QString &filename, const QString &label) {
|
||||||
|
|
||||||
this->text = readTextFile(this->root + "/" + filename);
|
this->text = readTextFile(this->root + "/" + filename);
|
||||||
|
|
||||||
static const QRegularExpression re(QString(
|
int start = this->text.indexOf(label);
|
||||||
"\\b%1\\b"
|
if (start < 0) return path;
|
||||||
"\\s*\\[?\\s*\\]?\\s*=\\s*"
|
int end = this->text.indexOf(';', start);
|
||||||
"INCBIN_[US][0-9][0-9]?"
|
QString incbinText = this->text.mid(start, end - start);
|
||||||
"\\(\\s*\"([^\"]*)\"\\s*\\)").arg(label));
|
|
||||||
|
|
||||||
|
static const QRegularExpression re_incbin("\\s*\\[?\\s*\\]?\\s*=\\s*INCBIN_[US][0-9][0-9]?\\(\\s*\\\"(?<path>[^\\\"]*)\\\"\\s*\\)");
|
||||||
QRegularExpressionMatch match;
|
QRegularExpressionMatch match;
|
||||||
qsizetype pos = this->text.indexOf(re, 0, &match);
|
qsizetype pos = incbinText.indexOf(re_incbin, 0, &match);
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
path = match.captured(1);
|
path = match.captured(1);
|
||||||
}
|
}
|
||||||
|
@ -284,15 +284,28 @@ QStringList ParseUtil::readCIncbinArray(const QString &filename, const QString &
|
||||||
|
|
||||||
this->text = readTextFile(this->root + "/" + filename);
|
this->text = readTextFile(this->root + "/" + filename);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
QString arrayText;
|
||||||
|
|
||||||
// Get the text starting after the label all the way to the definition's end
|
// Get the text starting after the label all the way to the definition's end
|
||||||
static const QRegularExpression re_labelGroup(QString("\\b%1\\b(.*?)};").arg(label), QRegularExpression::DotMatchesEverythingOption);
|
static const QRegularExpression re_labelGroup(QString("(?<label>[A-Za-z0-9_]+)\\[([^;]*?)};"), QRegularExpression::DotMatchesEverythingOption);
|
||||||
QRegularExpressionMatch arrayMatch = re_labelGroup.match(this->text);
|
QRegularExpressionMatchIterator findLabelIter = re_labelGroup.globalMatch(this->text);
|
||||||
if (!arrayMatch.hasMatch())
|
while (findLabelIter.hasNext()) {
|
||||||
|
QRegularExpressionMatch labelMatch = findLabelIter.next();
|
||||||
|
if (labelMatch.captured("label") == label) {
|
||||||
|
found = true;
|
||||||
|
arrayText = labelMatch.captured(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
return paths;
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
// Extract incbin paths from the array
|
// Extract incbin paths from the array
|
||||||
static const QRegularExpression re_incbin("INCBIN_[US][0-9][0-9]?\\(\\s*\"([^\"]*)\"\\s*\\)");
|
static const QRegularExpression re_incbin("INCBIN_[US][0-9][0-9]?\\(\\s*\"([^\"]*)\"\\s*\\)");
|
||||||
QRegularExpressionMatchIterator iter = re_incbin.globalMatch(arrayMatch.captured(1));
|
QRegularExpressionMatchIterator iter = re_incbin.globalMatch(arrayText);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
paths.append(iter.next().captured(1));
|
paths.append(iter.next().captured(1));
|
||||||
}
|
}
|
||||||
|
@ -373,7 +386,7 @@ QStringList ParseUtil::readCArray(const QString &filename, const QString &label)
|
||||||
this->file = filename;
|
this->file = filename;
|
||||||
this->text = readTextFile(this->root + "/" + filename);
|
this->text = readTextFile(this->root + "/" + filename);
|
||||||
|
|
||||||
static const QRegularExpression re(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
QRegularExpression re(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
||||||
QRegularExpressionMatch match = re.match(this->text);
|
QRegularExpressionMatch match = re.match(this->text);
|
||||||
|
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
|
@ -394,15 +407,14 @@ QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename,
|
||||||
this->text = readTextFile(this->root + "/" + filename);
|
this->text = readTextFile(this->root + "/" + filename);
|
||||||
QMap<QString, QString> map;
|
QMap<QString, QString> map;
|
||||||
|
|
||||||
static const QRegularExpression re_text(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
QRegularExpression re_text(QString(R"(\b%1\b\s*(\[?[^\]]*\])?\s*=\s*\{([^\}]*)\})").arg(label));
|
||||||
static const QRegularExpression re_spaces("\\s*");
|
QString arrayText = re_text.match(this->text).captured(2).replace(QRegularExpression("\\s*"), "");
|
||||||
QString body = re_text.match(this->text).captured(2).replace(re_spaces, "");
|
|
||||||
|
|
||||||
static const QRegularExpression re("\\[(?<index>[A-Za-z0-9_]*)\\]=(?<value>&?[A-Za-z0-9_]*)");
|
static const QRegularExpression re_findRow("\\[(?<index>[A-Za-z0-9_]*)\\][\\s=]+(?<value>&?[A-Za-z0-9_]*)");
|
||||||
QRegularExpressionMatchIterator iter = re.globalMatch(body);
|
QRegularExpressionMatchIterator rowIter = re_findRow.globalMatch(arrayText);
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (rowIter.hasNext()) {
|
||||||
QRegularExpressionMatch match = iter.next();
|
QRegularExpressionMatch match = rowIter.next();
|
||||||
QString key = match.captured("index");
|
QString key = match.captured("index");
|
||||||
QString value = match.captured("value");
|
QString value = match.captured("value");
|
||||||
map.insert(key, value);
|
map.insert(key, value);
|
||||||
|
|
Loading…
Reference in a new issue