mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 13:47:46 +02:00
chore: make all the regexes static const (#3647)
This commit is contained in:
@ -72,7 +72,8 @@ ApplicationId ApplicationId::fromTraditionalApp()
|
||||
protoId = protoId.toLower();
|
||||
#endif
|
||||
auto prefix = protoId.section(QLatin1Char('/'), -1);
|
||||
prefix.remove(QRegularExpression("[^a-zA-Z]"));
|
||||
static const QRegularExpression s_removeChars("[^a-zA-Z]");
|
||||
prefix.remove(s_removeChars);
|
||||
prefix.truncate(6);
|
||||
QByteArray idc = protoId.toUtf8();
|
||||
quint16 idNum = qChecksum(idc);
|
||||
|
@ -8,19 +8,19 @@
|
||||
#include <QRegularExpressionMatch>
|
||||
#include <QRegularExpressionMatchIterator>
|
||||
|
||||
QRegularExpression ruleset_re = QRegularExpression(R"([#.]?(@?\w+?)\s*\{(.*?)\})", QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpression rule_re = QRegularExpression(R"((\S+?)\s*:\s*(?:\"(.*?)(?<!\\)\"|'(.*?)(?<!\\)'|(\S+?))\s*(?:;|$))");
|
||||
static const QRegularExpression s_rulesetRe(R"([#.]?(@?\w+?)\s*\{(.*?)\})", QRegularExpression::DotMatchesEverythingOption);
|
||||
static const QRegularExpression s_ruleRe(R"((\S+?)\s*:\s*(?:\"(.*?)(?<!\\)\"|'(.*?)(?<!\\)'|(\S+?))\s*(?:;|$))");
|
||||
|
||||
QDCSS::QDCSS(QString s)
|
||||
{
|
||||
// not much error handling over here...
|
||||
// the original java code used indeces returned by the matcher for them, but QRE does not expose those
|
||||
QRegularExpressionMatchIterator ruleset_i = ruleset_re.globalMatch(s);
|
||||
QRegularExpressionMatchIterator ruleset_i = s_rulesetRe.globalMatch(s);
|
||||
while (ruleset_i.hasNext()) {
|
||||
QRegularExpressionMatch ruleset = ruleset_i.next();
|
||||
QString selector = ruleset.captured(1);
|
||||
QString rules = ruleset.captured(2);
|
||||
QRegularExpressionMatchIterator rule_i = rule_re.globalMatch(rules);
|
||||
QRegularExpressionMatchIterator rule_i = s_ruleRe.globalMatch(rules);
|
||||
while (rule_i.hasNext()) {
|
||||
QRegularExpressionMatch rule = rule_i.next();
|
||||
QString property = rule.captured(1);
|
||||
|
@ -40,6 +40,8 @@ SOFTWARE.
|
||||
|
||||
#include <functional>
|
||||
|
||||
static const QRegularExpression s_distoSplitRegex("\\s+");
|
||||
|
||||
Sys::DistributionInfo Sys::read_os_release()
|
||||
{
|
||||
Sys::DistributionInfo out;
|
||||
@ -145,7 +147,7 @@ void Sys::lsb_postprocess(Sys::LsbInfo& lsb, Sys::DistributionInfo& out)
|
||||
vers = lsb.codename;
|
||||
} else {
|
||||
// ubuntu, debian, gentoo, scientific, slackware, ... ?
|
||||
auto parts = dist.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||
auto parts = dist.split(s_distoSplitRegex, Qt::SkipEmptyParts);
|
||||
if (parts.size()) {
|
||||
dist = parts[0];
|
||||
}
|
||||
@ -178,7 +180,7 @@ QString Sys::_extract_distribution(const QString& x)
|
||||
if (release.startsWith("suse linux enterprise")) {
|
||||
return "sles";
|
||||
}
|
||||
QStringList list = release.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||
QStringList list = release.split(s_distoSplitRegex, Qt::SkipEmptyParts);
|
||||
if (list.size()) {
|
||||
return list[0];
|
||||
}
|
||||
@ -187,11 +189,11 @@ QString Sys::_extract_distribution(const QString& x)
|
||||
|
||||
QString Sys::_extract_version(const QString& x)
|
||||
{
|
||||
QRegularExpression versionish_string(QRegularExpression::anchoredPattern("\\d+(?:\\.\\d+)*$"));
|
||||
QStringList list = x.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||
static const QRegularExpression s_versionishString(QRegularExpression::anchoredPattern("\\d+(?:\\.\\d+)*$"));
|
||||
QStringList list = x.split(s_distoSplitRegex, Qt::SkipEmptyParts);
|
||||
for (int i = list.size() - 1; i >= 0; --i) {
|
||||
QString chunk = list[i];
|
||||
if (versionish_string.match(chunk).hasMatch()) {
|
||||
if (s_versionishString.match(chunk).hasMatch()) {
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user