chore: make all the regexes static const
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@@ -54,11 +54,11 @@ struct GradleSpecifier {
|
||||
4 "jdk15"
|
||||
5 "jar"
|
||||
*/
|
||||
QRegularExpression matcher(
|
||||
static const QRegularExpression s_matcher(
|
||||
QRegularExpression::anchoredPattern("([^:@]+):([^:@]+):([^:@]+)"
|
||||
"(?::([^:@]+))?"
|
||||
"(?:@([^:@]+))?"));
|
||||
QRegularExpressionMatch match = matcher.match(value);
|
||||
QRegularExpressionMatch match = s_matcher.match(value);
|
||||
m_valid = match.hasMatch();
|
||||
if (!m_valid) {
|
||||
m_invalidValue = value;
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
#include "MMCTime.h"
|
||||
#include "java/JavaVersion.h"
|
||||
#include "pathmatcher/MultiMatcher.h"
|
||||
#include "pathmatcher/RegexpMatcher.h"
|
||||
|
||||
#include "launch/LaunchTask.h"
|
||||
#include "launch/TaskStepWrapper.h"
|
||||
@@ -689,9 +688,9 @@ static QString replaceTokensIn(QString text, QMap<QString, QString> with)
|
||||
{
|
||||
// TODO: does this still work??
|
||||
QString result;
|
||||
QRegularExpression token_regexp("\\$\\{(.+)\\}", QRegularExpression::InvertedGreedinessOption);
|
||||
static const QRegularExpression s_token_regexp("\\$\\{(.+)\\}", QRegularExpression::InvertedGreedinessOption);
|
||||
QStringList list;
|
||||
QRegularExpressionMatchIterator i = token_regexp.globalMatch(text);
|
||||
QRegularExpressionMatchIterator i = s_token_regexp.globalMatch(text);
|
||||
int lastCapturedEnd = 0;
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
|
||||
@@ -114,9 +114,9 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
|
||||
out->uid = root.value("fileId").toString();
|
||||
}
|
||||
|
||||
const QRegularExpression valid_uid_regex{ QRegularExpression::anchoredPattern(
|
||||
static const QRegularExpression s_validUidRegex{ QRegularExpression::anchoredPattern(
|
||||
QStringLiteral(R"([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)*)")) };
|
||||
if (!valid_uid_regex.match(out->uid).hasMatch()) {
|
||||
if (!s_validUidRegex.match(out->uid).hasMatch()) {
|
||||
qCritical() << "The component's 'uid' contains illegal characters! UID:" << out->uid;
|
||||
out->addProblem(ProblemSeverity::Error,
|
||||
QObject::tr("The component's 'uid' contains illegal characters! This can cause security issues."));
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QRegularExpression>
|
||||
#include <QSaveFile>
|
||||
|
||||
namespace ProfileUtils {
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QUuid>
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -55,7 +55,8 @@
|
||||
|
||||
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent)
|
||||
{
|
||||
data.internalId = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
||||
static const QRegularExpression s_removeChars("[{}-]");
|
||||
data.internalId = QUuid::createUuid().toString().remove(s_removeChars);
|
||||
}
|
||||
|
||||
MinecraftAccountPtr MinecraftAccount::loadFromJsonV3(const QJsonObject& json)
|
||||
@@ -76,14 +77,15 @@ MinecraftAccountPtr MinecraftAccount::createBlankMSA()
|
||||
|
||||
MinecraftAccountPtr MinecraftAccount::createOffline(const QString& username)
|
||||
{
|
||||
static const QRegularExpression s_removeChars("[{}-]");
|
||||
auto account = makeShared<MinecraftAccount>();
|
||||
account->data.type = AccountType::Offline;
|
||||
account->data.yggdrasilToken.token = "0";
|
||||
account->data.yggdrasilToken.validity = Validity::Certain;
|
||||
account->data.yggdrasilToken.issueInstant = QDateTime::currentDateTimeUtc();
|
||||
account->data.yggdrasilToken.extra["userName"] = username;
|
||||
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
||||
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegularExpression("[{}-]"));
|
||||
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(s_removeChars);
|
||||
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(s_removeChars);
|
||||
account->data.minecraftProfile.name = username;
|
||||
account->data.minecraftProfile.validity = Validity::Certain;
|
||||
return account;
|
||||
@@ -231,6 +233,7 @@ bool MinecraftAccount::shouldRefresh() const
|
||||
|
||||
void MinecraftAccount::fillSession(AuthSessionPtr session)
|
||||
{
|
||||
static const QRegularExpression s_removeChars("[{}-]");
|
||||
if (ownsMinecraft() && !hasProfile()) {
|
||||
session->status = AuthSession::RequiresProfileSetup;
|
||||
} else {
|
||||
@@ -248,7 +251,7 @@ void MinecraftAccount::fillSession(AuthSessionPtr session)
|
||||
// profile ID
|
||||
session->uuid = data.profileId();
|
||||
if (session->uuid.isEmpty())
|
||||
session->uuid = uuidFromUsername(session->player_name).toString().remove(QRegularExpression("[{}-]"));
|
||||
session->uuid = uuidFromUsername(session->player_name).toString().remove(s_removeChars);
|
||||
// 'legacy' or 'mojang', depending on account type
|
||||
session->user_type = typeString();
|
||||
if (!session->access_token.isEmpty()) {
|
||||
|
||||
@@ -53,15 +53,16 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent)
|
||||
, m_process(parent->instance()->getJavaVersion().defaultsToUtf8() ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale())
|
||||
{
|
||||
if (parent->instance()->settings()->get("CloseAfterLaunch").toBool()) {
|
||||
static const QRegularExpression s_settingUser(".*Setting user.+", QRegularExpression::CaseInsensitiveOption);
|
||||
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
|
||||
*connection = connect(
|
||||
&m_process, &LoggedProcess::log, this, [connection](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
|
||||
qDebug() << lines;
|
||||
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
|
||||
APPLICATION->closeAllWindows();
|
||||
disconnect(*connection);
|
||||
}
|
||||
});
|
||||
*connection = connect(&m_process, &LoggedProcess::log, this,
|
||||
[connection](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
|
||||
qDebug() << lines;
|
||||
if (lines.filter(s_settingUser).length() != 0) {
|
||||
APPLICATION->closeAllWindows();
|
||||
disconnect(*connection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
|
||||
|
||||
@@ -82,8 +82,8 @@ auto Resource::name() const -> QString
|
||||
|
||||
static void removeThePrefix(QString& string)
|
||||
{
|
||||
QRegularExpression regex(QStringLiteral("^(?:the|teh) +"), QRegularExpression::CaseInsensitiveOption);
|
||||
string.remove(regex);
|
||||
static const QRegularExpression s_regex(QStringLiteral("^(?:the|teh) +"), QRegularExpression::CaseInsensitiveOption);
|
||||
string.remove(s_regex);
|
||||
string = string.trimmed();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "MTPixmapCache.h"
|
||||
#include "Version.h"
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#include "ShaderPack.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
void ShaderPack::setPackFormat(ShaderPackFormat new_format)
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "MTPixmapCache.h"
|
||||
|
||||
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "minecraft/mod/ModDetails.h"
|
||||
#include "settings/INIFile.h"
|
||||
|
||||
static QRegularExpression newlineRegex("\r\n|\n|\r");
|
||||
static const QRegularExpression s_newlineRegex("\r\n|\n|\r");
|
||||
|
||||
namespace ModUtils {
|
||||
|
||||
@@ -494,7 +494,7 @@ bool processZIP(Mod& mod, [[maybe_unused]] ProcessingLevel level)
|
||||
}
|
||||
|
||||
// quick and dirty line-by-line parser
|
||||
auto manifestLines = QString(file.readAll()).split(newlineRegex);
|
||||
auto manifestLines = QString(file.readAll()).split(s_newlineRegex);
|
||||
QString manifestVersion = "";
|
||||
for (auto& line : manifestLines) {
|
||||
if (line.startsWith("Implementation-Version: ", Qt::CaseInsensitive)) {
|
||||
|
||||
Reference in New Issue
Block a user