mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Instantiate QRegularExpression instances statically
This commit is contained in:
parent
4b297bfa09
commit
e6b9a07163
18 changed files with 74 additions and 47 deletions
|
@ -113,7 +113,8 @@ Base64UrlInput::Base64UrlInput(
|
|||
rpl::producer<QString> placeholder,
|
||||
const QString &val)
|
||||
: MaskedInputField(parent, st, std::move(placeholder), val) {
|
||||
if (!QRegularExpression("^[a-zA-Z0-9_\\-]+$").match(val).hasMatch()) {
|
||||
static const auto RegExp = QRegularExpression("^[a-zA-Z0-9_\\-]+$");
|
||||
if (!RegExp.match(val).hasMatch()) {
|
||||
setText(QString());
|
||||
}
|
||||
}
|
||||
|
@ -831,8 +832,9 @@ void ProxyBox::prepare() {
|
|||
connect(_host.data(), &HostInput::changed, [=] {
|
||||
Ui::PostponeCall(_host, [=] {
|
||||
const auto host = _host->getLastText().trimmed();
|
||||
static const auto mask = u"^\\d+\\.\\d+\\.\\d+\\.\\d+:(\\d*)$"_q;
|
||||
const auto match = QRegularExpression(mask).match(host);
|
||||
static const auto mask = QRegularExpression(
|
||||
u"^\\d+\\.\\d+\\.\\d+\\.\\d+:(\\d*)$"_q);
|
||||
const auto match = mask.match(host);
|
||||
if (_host->cursorPosition() == host.size()
|
||||
&& match.hasMatch()) {
|
||||
const auto port = match.captured(1);
|
||||
|
@ -1107,6 +1109,10 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
|||
proxy.password = fields.value(u"secret"_q);
|
||||
}
|
||||
if (proxy) {
|
||||
static const auto UrlStartRegExp = QRegularExpression(
|
||||
"^https://",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
static const auto UrlEndRegExp = QRegularExpression("/$");
|
||||
const auto displayed = "https://" + server + "/";
|
||||
const auto parsed = QUrl::fromUserInput(displayed);
|
||||
const auto displayUrl = !UrlClickHandler::IsSuspicious(displayed)
|
||||
|
@ -1117,11 +1123,9 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
|||
const auto displayServer = QString(
|
||||
displayUrl
|
||||
).replace(
|
||||
QRegularExpression(
|
||||
"^https://",
|
||||
QRegularExpression::CaseInsensitiveOption),
|
||||
UrlStartRegExp,
|
||||
QString()
|
||||
).replace(QRegularExpression("/$"), QString());
|
||||
).replace(UrlEndRegExp, QString());
|
||||
const auto text = tr::lng_sure_enable_socks(
|
||||
tr::now,
|
||||
lt_server,
|
||||
|
|
|
@ -542,9 +542,13 @@ void Launcher::processArguments() {
|
|||
}
|
||||
}
|
||||
|
||||
static const auto RegExp = QRegularExpression("[^a-z0-9\\-_]");
|
||||
gDebugMode = parseResult.contains("-debug");
|
||||
gKeyFile = parseResult.value("-key", {}).join(QString()).toLower();
|
||||
gKeyFile = gKeyFile.replace(QRegularExpression("[^a-z0-9\\-_]"), {});
|
||||
gKeyFile = parseResult
|
||||
.value("-key", {})
|
||||
.join(QString())
|
||||
.toLower()
|
||||
.replace(RegExp, {});
|
||||
gLaunchMode = parseResult.contains("-autostart") ? LaunchModeAutoStart
|
||||
: parseResult.contains("-fixprevious") ? LaunchModeFixPrevious
|
||||
: parseResult.contains("-cleanup") ? LaunchModeCleanup
|
||||
|
|
|
@ -241,7 +241,7 @@ QString FindUpdateFile() {
|
|||
}
|
||||
const auto list = updates.entryInfoList(QDir::Files);
|
||||
for (const auto &info : list) {
|
||||
if (QRegularExpression(
|
||||
static const auto RegExp = QRegularExpression(
|
||||
"^("
|
||||
"tupdate|"
|
||||
"tx64upd|"
|
||||
|
@ -250,7 +250,8 @@ QString FindUpdateFile() {
|
|||
"tlinuxupd|"
|
||||
")\\d+(_[a-z\\d]+)?$",
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
).match(info.fileName()).hasMatch()) {
|
||||
);
|
||||
if (RegExp.match(info.fileName()).hasMatch()) {
|
||||
return info.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,8 @@ void PhoneWidget::submit() {
|
|||
|
||||
// Check if such account is authorized already.
|
||||
const auto digitsOnly = [](QString value) {
|
||||
return value.replace(QRegularExpression("[^0-9]"), QString());
|
||||
static const auto RegExp = QRegularExpression("[^0-9]");
|
||||
return value.replace(RegExp, QString());
|
||||
};
|
||||
const auto phoneDigits = digitsOnly(phone);
|
||||
for (const auto &[index, existing] : Core::App().domain().accounts()) {
|
||||
|
|
|
@ -1354,8 +1354,11 @@ bool Instance::Private::onErrorDefault(
|
|||
const auto &type = error.type();
|
||||
const auto code = error.code();
|
||||
auto badGuestDc = (code == 400) && (type == u"FILE_ID_INVALID"_q);
|
||||
static const auto MigrateRegExp = QRegularExpression("^(FILE|PHONE|NETWORK|USER)_MIGRATE_(\\d+)$");
|
||||
static const auto FloodWaitRegExp = QRegularExpression("^FLOOD_WAIT_(\\d+)$");
|
||||
static const auto SlowmodeWaitRegExp = QRegularExpression("^SLOWMODE_WAIT_(\\d+)$");
|
||||
QRegularExpressionMatch m1, m2;
|
||||
if ((m1 = QRegularExpression("^(FILE|PHONE|NETWORK|USER)_MIGRATE_(\\d+)$").match(type)).hasMatch()) {
|
||||
if ((m1 = MigrateRegExp.match(type)).hasMatch()) {
|
||||
if (!requestId) return false;
|
||||
|
||||
auto dcWithShift = ShiftedDcId(0);
|
||||
|
@ -1458,8 +1461,8 @@ bool Instance::Private::onErrorDefault(
|
|||
return true;
|
||||
} else if (code < 0
|
||||
|| code >= 500
|
||||
|| (m1 = QRegularExpression("^FLOOD_WAIT_(\\d+)$").match(type)).hasMatch()
|
||||
|| ((m2 = QRegularExpression("^SLOWMODE_WAIT_(\\d+)$").match(type)).hasMatch()
|
||||
|| (m1 = FloodWaitRegExp.match(type)).hasMatch()
|
||||
|| ((m2 = SlowmodeWaitRegExp.match(type)).hasMatch()
|
||||
&& m2.captured(1).toInt() < 3)) {
|
||||
if (!requestId) return false;
|
||||
|
||||
|
|
|
@ -757,8 +757,9 @@ bool DcOptions::loadFromFile(const QString &path) {
|
|||
stream.setCodec("UTF-8");
|
||||
#endif // Qt < 6.0.0
|
||||
while (!stream.atEnd()) {
|
||||
static const auto RegExp = QRegularExpression(R"(\s)");
|
||||
auto line = stream.readLine();
|
||||
auto components = line.split(QRegularExpression(R"(\s)"), Qt::SkipEmptyParts);
|
||||
auto components = line.split(RegExp, Qt::SkipEmptyParts);
|
||||
if (components.isEmpty() || components[0].startsWith('#')) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -157,11 +157,12 @@ bool ProxyData::supportsCalls() const {
|
|||
}
|
||||
|
||||
bool ProxyData::tryCustomResolve() const {
|
||||
static const auto RegExp = QRegularExpression(
|
||||
QStringLiteral("^\\d+\\.\\d+\\.\\d+\\.\\d+$")
|
||||
);
|
||||
return (type == Type::Socks5 || type == Type::Mtproto)
|
||||
&& !qthelp::is_ipv6(host)
|
||||
&& !QRegularExpression(
|
||||
QStringLiteral("^\\d+\\.\\d+\\.\\d+\\.\\d+$")
|
||||
).match(host).hasMatch();
|
||||
&& !RegExp.match(host).hasMatch();
|
||||
}
|
||||
|
||||
bytes::vector ProxyData::secretFromMtprotoPassword() const {
|
||||
|
|
|
@ -25,11 +25,11 @@ namespace {
|
|||
Error::Error(const MTPrpcError &error)
|
||||
: _code(error.c_rpc_error().verror_code().v) {
|
||||
QString text = qs(error.c_rpc_error().verror_message());
|
||||
const auto expression = QRegularExpression(
|
||||
static const auto Expression = QRegularExpression(
|
||||
"^([A-Z0-9_]+)(: .*)?$",
|
||||
(QRegularExpression::DotMatchesEverythingOption
|
||||
| QRegularExpression::MultilineOption));
|
||||
const auto match = expression.match(text);
|
||||
const auto match = Expression.match(text);
|
||||
if (match.hasMatch()) {
|
||||
_type = match.captured(1);
|
||||
_description = match.captured(2).mid(2);
|
||||
|
|
|
@ -62,8 +62,9 @@ QString InstanceId() {
|
|||
}
|
||||
|
||||
bool CheckPhoneByPrefixesRules(const QString &phone, const QString &rules) {
|
||||
static const auto RegExp = QRegularExpression("[^0-9]");
|
||||
const auto check = QString(phone).replace(
|
||||
QRegularExpression("[^0-9]"),
|
||||
RegExp,
|
||||
QString());
|
||||
auto result = false;
|
||||
for (const auto &prefix : rules.split(',')) {
|
||||
|
|
|
@ -152,11 +152,12 @@ EditDocumentScheme GetDocumentScheme(
|
|||
};
|
||||
using Result = std::optional<QString>;
|
||||
const auto NameValidate = [](const QString &value) -> Result {
|
||||
static const auto RegExp = QRegularExpression(
|
||||
"^[a-zA-Z0-9\\.,/&\\-' ]+$"
|
||||
);
|
||||
if (value.isEmpty() || value.size() > kMaxNameSize) {
|
||||
return QString();
|
||||
} else if (!QRegularExpression(
|
||||
"^[a-zA-Z0-9\\.,/&\\-' ]+$"
|
||||
).match(value).hasMatch()) {
|
||||
} else if (!RegExp.match(value).hasMatch()) {
|
||||
return tr::lng_passport_bad_name(tr::now);
|
||||
}
|
||||
return std::nullopt;
|
||||
|
@ -167,14 +168,16 @@ EditDocumentScheme GetDocumentScheme(
|
|||
const auto StreetValidate = LimitedValidate(kMaxStreetSize);
|
||||
const auto CityValidate = LimitedValidate(kMaxCitySize, kMinCitySize);
|
||||
const auto PostcodeValidate = FromBoolean([](const QString &value) {
|
||||
return QRegularExpression(
|
||||
static const auto RegExp = QRegularExpression(
|
||||
QString("^[a-zA-Z0-9\\-]{2,%1}$").arg(kMaxPostcodeSize)
|
||||
).match(value).hasMatch();
|
||||
);
|
||||
return RegExp.match(value).hasMatch();
|
||||
});
|
||||
const auto DateValidateBoolean = [](const QString &value) {
|
||||
return QRegularExpression(
|
||||
static const auto RegExp = QRegularExpression(
|
||||
"^\\d{2}\\.\\d{2}\\.\\d{4}$"
|
||||
).match(value).hasMatch();
|
||||
);
|
||||
return RegExp.match(value).hasMatch();
|
||||
};
|
||||
const auto DateValidate = FromBoolean(DateValidateBoolean);
|
||||
const auto DateOrEmptyValidate = FromBoolean([=](const QString &value) {
|
||||
|
@ -479,9 +482,8 @@ EditContactScheme GetContactScheme(Scope::Type type) {
|
|||
result.newHeader = tr::lng_passport_new_phone(tr::now);
|
||||
result.aboutNew = tr::lng_passport_new_phone_code(tr::now);
|
||||
result.validate = [](const QString &value) {
|
||||
return QRegularExpression(
|
||||
"^\\d{2,12}$"
|
||||
).match(value).hasMatch();
|
||||
static const auto RegExp = QRegularExpression("^\\d{2,12}$");
|
||||
return RegExp.match(value).hasMatch();
|
||||
};
|
||||
result.format = [](const QString &value) {
|
||||
return Ui::FormatPhone(value);
|
||||
|
|
|
@ -51,7 +51,8 @@ PostcodeInput::PostcodeInput(
|
|||
rpl::producer<QString> placeholder,
|
||||
const QString &val)
|
||||
: MaskedInputField(parent, st, std::move(placeholder), val) {
|
||||
if (!QRegularExpression("^[a-zA-Z0-9\\-]+$").match(val).hasMatch()) {
|
||||
static const auto RegExp = QRegularExpression("^[a-zA-Z0-9\\-]+$");
|
||||
if (!RegExp.match(val).hasMatch()) {
|
||||
setText(QString());
|
||||
}
|
||||
}
|
||||
|
@ -414,8 +415,9 @@ void CountryRow::chooseCountry() {
|
|||
}
|
||||
|
||||
QDate ValidateDate(const QString &value) {
|
||||
const auto match = QRegularExpression(
|
||||
"^([0-9]{2})\\.([0-9]{2})\\.([0-9]{4})$").match(value);
|
||||
static const auto RegExp = QRegularExpression(
|
||||
"^([0-9]{2})\\.([0-9]{2})\\.([0-9]{4})$");
|
||||
const auto match = RegExp.match(value);
|
||||
if (!match.hasMatch()) {
|
||||
return QDate();
|
||||
}
|
||||
|
|
|
@ -54,8 +54,9 @@ bool Card::empty() const {
|
|||
}
|
||||
|
||||
QString Last4(const Card &card) {
|
||||
static const auto RegExp = QRegularExpression("[^\\d]\\d*(\\d{4})$");
|
||||
const auto masked = card.maskedNumber();
|
||||
const auto m = QRegularExpression("[^\\d]\\d*(\\d{4})$").match(masked);
|
||||
const auto m = RegExp.match(masked);
|
||||
return m.hasMatch() ? m.captured(1) : QString();
|
||||
}
|
||||
|
||||
|
|
|
@ -90,11 +90,13 @@ struct BinRange {
|
|||
}
|
||||
|
||||
[[nodiscard]] bool IsNumeric(const QString &value) {
|
||||
return QRegularExpression("^[0-9]*$").match(value).hasMatch();
|
||||
static const auto RegExp = QRegularExpression("^[0-9]*$");
|
||||
return RegExp.match(value).hasMatch();
|
||||
}
|
||||
|
||||
[[nodiscard]] QString RemoveWhitespaces(QString value) {
|
||||
return value.replace(QRegularExpression("\\s"), QString());
|
||||
static const auto RegExp = QRegularExpression("\\s");
|
||||
return value.replace(RegExp, QString());
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<BinRange> BinRangesForNumber(
|
||||
|
|
|
@ -39,7 +39,8 @@ struct SimpleFieldState {
|
|||
}
|
||||
|
||||
[[nodiscard]] QString RemoveNonNumbers(QString value) {
|
||||
return value.replace(QRegularExpression("[^0-9]"), QString());
|
||||
static const auto RegExp = QRegularExpression("[^0-9]");
|
||||
return value.replace(RegExp, QString());
|
||||
}
|
||||
|
||||
[[nodiscard]] SimpleFieldState NumbersOnlyState(SimpleFieldState state) {
|
||||
|
|
|
@ -36,7 +36,8 @@ struct SimpleFieldState {
|
|||
}
|
||||
|
||||
[[nodiscard]] QString RemoveNonNumbers(QString value) {
|
||||
return value.replace(QRegularExpression("[^0-9]"), QString());
|
||||
static const auto RegExp = QRegularExpression("[^0-9]");
|
||||
return value.replace(RegExp, QString());
|
||||
}
|
||||
|
||||
[[nodiscard]] SimpleFieldState CleanMoneyState(
|
||||
|
@ -216,6 +217,7 @@ struct SimpleFieldState {
|
|||
const FieldConfig &config,
|
||||
const QString &parsed,
|
||||
const QString &countryIso2) {
|
||||
static const auto RegExp = QRegularExpression("[^0-9]\\.");
|
||||
if (config.type == FieldType::Country) {
|
||||
return countryIso2;
|
||||
} else if (config.type == FieldType::Money) {
|
||||
|
@ -227,16 +229,14 @@ struct SimpleFieldState {
|
|||
QChar(','),
|
||||
QChar('.')
|
||||
).replace(
|
||||
QRegularExpression("[^0-9\\.]"),
|
||||
RegExp,
|
||||
QString()
|
||||
).toDouble();
|
||||
return QString::number(
|
||||
int64(base::SafeRound(real * std::pow(10., rule.exponent))));
|
||||
} else if (config.type == FieldType::CardNumber
|
||||
|| config.type == FieldType::CardCVC) {
|
||||
return QString(parsed).replace(
|
||||
QRegularExpression("[^0-9\\.]"),
|
||||
QString());
|
||||
return QString(parsed).replace(RegExp, QString());
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,8 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
|||
for (auto &line : result.lines) {
|
||||
const auto colorIt = colors.constFind(line.idString);
|
||||
if (colorIt != colors.constEnd() && (*colorIt).isString()) {
|
||||
const auto match = QRegularExpression(colorPattern).match(
|
||||
static const auto RegExp = QRegularExpression(u"(.*)(#.*)"_q);
|
||||
const auto match = RegExp.match(
|
||||
colorIt->toString());
|
||||
if (match.hasMatch()) {
|
||||
line.colorKey = match.captured(1);
|
||||
|
|
|
@ -579,8 +579,9 @@ void writeAutoupdatePrefix(const QString &prefix) {
|
|||
QString readAutoupdatePrefix() {
|
||||
Expects(!Core::UpdaterDisabled());
|
||||
|
||||
static const auto RegExp = QRegularExpression("/+$");
|
||||
auto result = readAutoupdatePrefixRaw();
|
||||
return result.replace(QRegularExpression("/+$"), QString());
|
||||
return result.replace(RegExp, QString());
|
||||
}
|
||||
|
||||
void writeBackground(const Data::WallPaper &paper, const QImage &image) {
|
||||
|
|
|
@ -234,13 +234,14 @@ void CountrySelectBox::Inner::init() {
|
|||
}
|
||||
auto index = 0;
|
||||
for (const auto &info : _list) {
|
||||
static const auto RegExp = QRegularExpression("[\\s\\-]");
|
||||
auto full = info.country
|
||||
+ ' '
|
||||
+ (!info.alternativeName.isEmpty()
|
||||
? info.alternativeName
|
||||
: QString());
|
||||
const auto namesList = std::move(full).toLower().split(
|
||||
QRegularExpression("[\\s\\-]"),
|
||||
RegExp,
|
||||
Qt::SkipEmptyParts);
|
||||
auto &names = _namesList.emplace_back();
|
||||
names.reserve(namesList.size());
|
||||
|
|
Loading…
Add table
Reference in a new issue