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
No known key found for this signature in database
GPG Key ID: C10411294912A422
17 changed files with 48 additions and 53 deletions

View File

@ -39,6 +39,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QDebug> #include <QDebug>
#include <QRegularExpression>
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
#include "settings/Setting.h" #include "settings/Setting.h"
@ -335,7 +336,7 @@ QString BaseInstance::name() const
QString BaseInstance::windowTitle() const QString BaseInstance::windowTitle() const
{ {
return BuildConfig.LAUNCHER_NAME + ": " + name().replace(QRegExp("[ \n\r\t]+"), " "); return BuildConfig.LAUNCHER_NAME + ": " + name().replace(QRegularExpression("\\s+"), " ");
} }
// FIXME: why is this here? move it to MinecraftInstance!!! // FIXME: why is this here? move it to MinecraftInstance!!!

View File

@ -978,6 +978,7 @@ target_link_libraries(Launcher_logic
Qt5::Network Qt5::Network
Qt5::Concurrent Qt5::Concurrent
Qt5::Gui Qt5::Gui
Qt5::Widgets
) )
target_link_libraries(Launcher_logic target_link_libraries(Launcher_logic
QuaZip::QuaZip QuaZip::QuaZip

View File

@ -325,7 +325,7 @@ void InstanceImportTask::processFlame()
// Hack to correct some 'special sauce'... // Hack to correct some 'special sauce'...
if(mcVersion.endsWith('.')) if(mcVersion.endsWith('.'))
{ {
mcVersion.remove(QRegExp("[.]+$")); mcVersion.remove(QRegularExpression("[.]+$"));
logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack.")); logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack."));
} }
auto components = instance.getPackProfile(); auto components = instance.getPackProfile();

View File

@ -2,10 +2,11 @@
#include "java/JavaUtils.h" #include "java/JavaUtils.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include <MMCStrings.h> #include <MMCStrings.h>
#include <QRegularExpression>
bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent) bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent)
{ {
if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegExp("-Xm[sx]")) if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegularExpression("-Xm[sx]"))
|| jvmargs.contains("-XX-MaxHeapSize") || jvmargs.contains("-XX:InitialHeapSize")) || jvmargs.contains("-XX-MaxHeapSize") || jvmargs.contains("-XX:InitialHeapSize"))
{ {
auto warnStr = QObject::tr( auto warnStr = QObject::tr(
@ -19,7 +20,7 @@ bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent)
return false; return false;
} }
// block lunacy with passing required version to the JVM // block lunacy with passing required version to the JVM
if (jvmargs.contains(QRegExp("-version:.*"))) { if (jvmargs.contains(QRegularExpression("-version:.*"))) {
auto warnStr = QObject::tr( auto warnStr = QObject::tr(
"You tried to pass required Java version argument to the JVM (using \"-version:xxx\"). This is not safe and will not be allowed.\n" "You tried to pass required Java version argument to the JVM (using \"-version:xxx\"). This is not safe and will not be allowed.\n"
"This message will be displayed until you remove this from the JVM arguments."); "This message will be displayed until you remove this from the JVM arguments.");

View File

@ -15,7 +15,6 @@
#include <QtNetwork> #include <QtNetwork>
#include <QtXml> #include <QtXml>
#include <QRegExp>
#include <QDebug> #include <QDebug>

View File

@ -2,6 +2,7 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QRegularExpression>
#include "DefaultVariable.h" #include "DefaultVariable.h"
struct GradleSpecifier struct GradleSpecifier
@ -25,20 +26,21 @@ struct GradleSpecifier
4 "jdk15" 4 "jdk15"
5 "jar" 5 "jar"
*/ */
QRegExp matcher("([^:@]+):([^:@]+):([^:@]+)" "(?::([^:@]+))?" "(?:@([^:@]+))?"); QRegularExpression matcher(QRegularExpression::anchoredPattern("([^:@]+):([^:@]+):([^:@]+)" "(?::([^:@]+))?" "(?:@([^:@]+))?"));
m_valid = matcher.exactMatch(value); QRegularExpressionMatch match = matcher.match(value);
m_valid = match.hasMatch();
if(!m_valid) { if(!m_valid) {
m_invalidValue = value; m_invalidValue = value;
return *this; return *this;
} }
auto elements = matcher.capturedTexts(); auto elements = match.captured();
m_groupId = elements[1]; m_groupId = match.captured(1);
m_artifactId = elements[2]; m_artifactId = match.captured(2);
m_version = elements[3]; m_version = match.captured(3);
m_classifier = elements[4]; m_classifier = match.captured(4);
if(!elements[5].isEmpty()) if(match.lastCapturedIndex() >= 5)
{ {
m_extension = elements[5]; m_extension = match.captured(5);
} }
return *this; return *this;
} }

View File

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

View File

@ -89,14 +89,3 @@ void VersionFile::applyTo(LaunchProfile *profile)
} }
profile->applyProblemSeverity(getProblemSeverity()); profile->applyProblemSeverity(getProblemSeverity());
} }
/*
auto theirVersion = profile->getMinecraftVersion();
if (!theirVersion.isNull() && !dependsOnMinecraftVersion.isNull())
{
if (QRegExp(dependsOnMinecraftVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(theirVersion) == -1)
{
throw MinecraftVersionMismatch(uid, dependsOnMinecraftVersion, theirVersion);
}
}
*/

View File

@ -39,6 +39,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QDebug> #include <QDebug>
#include <QUuid> #include <QUuid>
#include <QRegularExpression>
namespace { namespace {
void tokenToJSONV3(QJsonObject &parent, Katabasis::Token t, const char * tokenName) { void tokenToJSONV3(QJsonObject &parent, Katabasis::Token t, const char * tokenName) {
@ -451,7 +452,7 @@ void AccountData::invalidateClientToken() {
if(type != AccountType::Mojang) { if(type != AccountType::Mojang) {
return; return;
} }
yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{-}]")); yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{-}]"));
} }
QString AccountData::profileId() const { QString AccountData::profileId() const {

View File

@ -40,7 +40,7 @@
#include <QUuid> #include <QUuid>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QRegExp> #include <QRegularExpression>
#include <QStringList> #include <QStringList>
#include <QJsonDocument> #include <QJsonDocument>
@ -53,7 +53,7 @@
#include "flows/Offline.h" #include "flows/Offline.h"
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent) { MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent) {
data.internalId = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); data.internalId = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
} }
@ -78,7 +78,7 @@ MinecraftAccountPtr MinecraftAccount::createFromUsername(const QString &username
MinecraftAccountPtr account = new MinecraftAccount(); MinecraftAccountPtr account = new MinecraftAccount();
account->data.type = AccountType::Mojang; account->data.type = AccountType::Mojang;
account->data.yggdrasilToken.extra["userName"] = username; account->data.yggdrasilToken.extra["userName"] = username;
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
return account; return account;
} }
@ -97,10 +97,10 @@ MinecraftAccountPtr MinecraftAccount::createOffline(const QString &username)
account->data.yggdrasilToken.validity = Katabasis::Validity::Certain; account->data.yggdrasilToken.validity = Katabasis::Validity::Certain;
account->data.yggdrasilToken.issueInstant = QDateTime::currentDateTimeUtc(); account->data.yggdrasilToken.issueInstant = QDateTime::currentDateTimeUtc();
account->data.yggdrasilToken.extra["userName"] = username; account->data.yggdrasilToken.extra["userName"] = username;
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
account->data.minecraftEntitlement.ownsMinecraft = true; account->data.minecraftEntitlement.ownsMinecraft = true;
account->data.minecraftEntitlement.canPlayMinecraft = true; account->data.minecraftEntitlement.canPlayMinecraft = true;
account->data.minecraftProfile.id = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); account->data.minecraftProfile.id = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
account->data.minecraftProfile.name = username; account->data.minecraftProfile.name = username;
account->data.minecraftProfile.validity = Katabasis::Validity::Certain; account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
return account; return account;

View File

@ -754,7 +754,7 @@ bool PackInstallTask::extractMods(
QString folderToExtract = ""; QString folderToExtract = "";
if(mod.type == ModType::Extract) { if(mod.type == ModType::Extract) {
folderToExtract = mod.extractFolder; folderToExtract = mod.extractFolder;
folderToExtract.remove(QRegExp("^/")); folderToExtract.remove(QRegularExpression("^/"));
} }
qDebug() << "Extracting " + mod.file + " to " + extractToDir; qDebug() << "Extracting " + mod.file + " to " + extractToDir;

View File

@ -18,7 +18,7 @@
#include <QPushButton> #include <QPushButton>
#include <QAction> #include <QAction>
#include <QRegExpValidator> #include <QRegularExpressionValidator>
#include <QJsonDocument> #include <QJsonDocument>
#include <QDebug> #include <QDebug>
@ -39,9 +39,9 @@ ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidg
yellowIcon = APPLICATION->getThemedIcon("status-yellow"); yellowIcon = APPLICATION->getThemedIcon("status-yellow");
badIcon = APPLICATION->getThemedIcon("status-bad"); badIcon = APPLICATION->getThemedIcon("status-bad");
QRegExp permittedNames("[a-zA-Z0-9_]{3,16}"); QRegularExpression permittedNames("[a-zA-Z0-9_]{3,16}");
auto nameEdit = ui->nameEdit; auto nameEdit = ui->nameEdit;
nameEdit->setValidator(new QRegExpValidator(permittedNames)); nameEdit->setValidator(new QRegularExpressionValidator(permittedNames));
nameEdit->setClearButtonEnabled(true); nameEdit->setClearButtonEnabled(true);
validityAction = nameEdit->addAction(yellowIcon, QLineEdit::LeadingPosition); validityAction = nameEdit->addAction(yellowIcon, QLineEdit::LeadingPosition);
connect(nameEdit, &QLineEdit::textEdited, this, &ProfileSetupDialog::nameEdited); connect(nameEdit, &QLineEdit::textEdited, this, &ProfileSetupDialog::nameEdited);

View File

@ -22,10 +22,10 @@ void SkinUploadDialog::on_buttonBox_accepted()
{ {
QString fileName; QString fileName;
QString input = ui->skinPathTextBox->text(); QString input = ui->skinPathTextBox->text();
QRegExp urlPrefixMatcher("^([a-z]+)://.+$"); QRegularExpression urlPrefixMatcher(QRegularExpression::anchoredPattern("^([a-z]+)://.+$"));
bool isLocalFile = false; bool isLocalFile = false;
// it has an URL prefix -> it is an URL // it has an URL prefix -> it is an URL
if(urlPrefixMatcher.exactMatch(input)) if(urlPrefixMatcher.match(input).hasMatch()) // TODO: does this work?
{ {
QUrl fileURL = input; QUrl fileURL = input;
if(fileURL.isValid()) if(fileURL.isValid())

View File

@ -58,7 +58,7 @@ QString reprocessMarkdown(QByteArray markdown)
QString output = hoedown.process(markdown); QString output = hoedown.process(markdown);
// HACK: easier than customizing hoedown // HACK: easier than customizing hoedown
output.replace(QRegExp("GH-([0-9]+)"), "<a href=\"https://github.com/PolyMC/PolyMC/issues/\\1\">GH-\\1</a>"); output.replace(QRegularExpression("GH-([0-9]+)"), "<a href=\"https://github.com/PolyMC/PolyMC/issues/\\1\">GH-\\1</a>");
qDebug() << output; qDebug() << output;
return output; return output;
} }

View File

@ -32,13 +32,13 @@ class SortProxy : public QSortFilterProxyModel {
const auto& mod = model->at(source_row); const auto& mod = model->at(source_row);
if (mod.name().contains(filterRegExp())) if (mod.name().contains(filterRegularExpression()))
return true; return true;
if (mod.description().contains(filterRegExp())) if (mod.description().contains(filterRegularExpression()))
return true; return true;
for (auto& author : mod.authors()) { for (auto& author : mod.authors()) {
if (author.contains(filterRegExp())) { if (author.contains(filterRegularExpression())) {
return true; return true;
} }
} }

View File

@ -50,6 +50,7 @@
#include <QClipboard> #include <QClipboard>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QRegularExpression>
#include <Application.h> #include <Application.h>
@ -154,7 +155,7 @@ public:
if (role == Qt::DisplayRole || role == Qt::EditRole) if (role == Qt::DisplayRole || role == Qt::EditRole)
{ {
QVariant result = sourceModel()->data(mapToSource(proxyIndex), role); QVariant result = sourceModel()->data(mapToSource(proxyIndex), role);
return result.toString().remove(QRegExp("\\.png$")); return result.toString().remove(QRegularExpression("\\.png$"));
} }
if (role == Qt::DecorationRole) if (role == Qt::DecorationRole)
{ {

View File

@ -66,7 +66,7 @@ public:
protected: protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{ {
const QString pattern = filterRegExp().pattern(); const QString pattern = filterRegularExpression().pattern();
const auto model = static_cast<PageModel *>(sourceModel()); const auto model = static_cast<PageModel *>(sourceModel());
const auto page = model->pages().at(sourceRow); const auto page = model->pages().at(sourceRow);
if (!page->shouldDisplay()) if (!page->shouldDisplay())