refactor: replace QRegExp with QRegularExpression

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu
2022-05-02 19:48:37 +02:00
parent 984692dc62
commit ff2cd50bfa
17 changed files with 48 additions and 53 deletions

View File

@ -473,25 +473,25 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
static QString replaceTokensIn(QString text, QMap<QString, QString> with)
{
// TODO: does this still work??
QString result;
QRegExp token_regexp("\\$\\{(.+)\\}");
token_regexp.setMinimal(true);
QRegularExpression token_regexp("\\$\\{(.+)\\}", QRegularExpression::InvertedGreedinessOption);
QStringList list;
int tail = 0;
int head = 0;
while ((head = token_regexp.indexIn(text, head)) != -1)
QRegularExpressionMatchIterator i = token_regexp.globalMatch(text);
int lastCapturedEnd = 0;
while (i.hasNext())
{
result.append(text.mid(tail, head - tail));
QString key = token_regexp.cap(1);
QRegularExpressionMatch match = i.next();
result.append(text.mid(lastCapturedEnd, match.capturedStart()));
QString key = match.captured(1);
auto iter = with.find(key);
if (iter != with.end())
{
result.append(*iter);
}
head += token_regexp.matchedLength();
tail = head;
lastCapturedEnd = match.capturedEnd();
}
result.append(text.mid(tail));
result.append(text.mid(lastCapturedEnd));
return result;
}