Instantiate QRegularExpression instances statically
This commit is contained in:
parent
c5a616de35
commit
d95f9e778b
5 changed files with 20 additions and 15 deletions
|
|
@ -64,9 +64,11 @@ QString UrlClickHandler::EncodeForOpening(const QString &originalUrl) {
|
||||||
? QString::fromUtf8(good.toEncoded())
|
? QString::fromUtf8(good.toEncoded())
|
||||||
: originalUrl;
|
: originalUrl;
|
||||||
|
|
||||||
|
static const auto RegExp = QRegularExpression(
|
||||||
|
QStringLiteral("^[a-zA-Z]+:"));
|
||||||
|
|
||||||
if (!result.isEmpty()
|
if (!result.isEmpty()
|
||||||
&& !QRegularExpression(
|
&& !RegExp.match(result).hasMatch()) {
|
||||||
QStringLiteral("^[a-zA-Z]+:")).match(result).hasMatch()) {
|
|
||||||
// No protocol.
|
// No protocol.
|
||||||
return QStringLiteral("https://") + result;
|
return QStringLiteral("https://") + result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1236,8 +1236,9 @@ const QRegularExpression &RegExpBotCommand() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpression RegExpDigitsExclude() {
|
const QRegularExpression &RegExpDigitsExclude() {
|
||||||
return QRegularExpression("[^\\d]");
|
static const auto result = QRegularExpression("[^\\d]");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MarkdownBoldGoodBefore() {
|
QString MarkdownBoldGoodBefore() {
|
||||||
|
|
@ -2225,9 +2226,10 @@ TextWithTags::Tags ConvertEntitiesToTextTags(
|
||||||
};
|
};
|
||||||
switch (entity.type()) {
|
switch (entity.type()) {
|
||||||
case EntityType::MentionName: {
|
case EntityType::MentionName: {
|
||||||
const auto match = QRegularExpression(
|
static const auto RegExp = QRegularExpression(
|
||||||
"^(\\d+\\.\\d+:\\d+)$"
|
"^(\\d+\\.\\d+:\\d+)$"
|
||||||
).match(entity.data());
|
);
|
||||||
|
const auto match = RegExp.match(entity.data());
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
push(kMentionTagStart + entity.data());
|
push(kMentionTagStart + entity.data());
|
||||||
}
|
}
|
||||||
|
|
@ -2240,9 +2242,8 @@ TextWithTags::Tags ConvertEntitiesToTextTags(
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case EntityType::CustomEmoji: {
|
case EntityType::CustomEmoji: {
|
||||||
const auto match = QRegularExpression(
|
static const auto RegExp = QRegularExpression("^(\\d+)$");
|
||||||
"^(\\d+)$"
|
const auto match = RegExp.match(entity.data());
|
||||||
).match(entity.data());
|
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
push(Ui::InputField::CustomEmojiLink(entity.data()));
|
push(Ui::InputField::CustomEmojiLink(entity.data()));
|
||||||
}
|
}
|
||||||
|
|
@ -2261,8 +2262,8 @@ TextWithTags::Tags ConvertEntitiesToTextTags(
|
||||||
case EntityType::Code: push(Ui::InputField::kTagCode); break;
|
case EntityType::Code: push(Ui::InputField::kTagCode); break;
|
||||||
case EntityType::Pre: {
|
case EntityType::Pre: {
|
||||||
if (!entity.data().isEmpty()) {
|
if (!entity.data().isEmpty()) {
|
||||||
const auto language = QRegularExpression("^[a-z0-9\\-]+$");
|
static const auto Language = QRegularExpression("^[a-z0-9\\-]+$");
|
||||||
if (language.match(entity.data()).hasMatch()) {
|
if (Language.match(entity.data()).hasMatch()) {
|
||||||
push(Ui::InputField::kTagPre + entity.data());
|
push(Ui::InputField::kTagPre + entity.data());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ const QRegularExpression &RegExpHashtag();
|
||||||
const QRegularExpression &RegExpHashtagExclude();
|
const QRegularExpression &RegExpHashtagExclude();
|
||||||
const QRegularExpression &RegExpMention();
|
const QRegularExpression &RegExpMention();
|
||||||
const QRegularExpression &RegExpBotCommand();
|
const QRegularExpression &RegExpBotCommand();
|
||||||
QRegularExpression RegExpDigitsExclude();
|
const QRegularExpression &RegExpDigitsExclude();
|
||||||
QString MarkdownBoldGoodBefore();
|
QString MarkdownBoldGoodBefore();
|
||||||
QString MarkdownBoldBadAfter();
|
QString MarkdownBoldBadAfter();
|
||||||
QString MarkdownItalicGoodBefore();
|
QString MarkdownItalicGoodBefore();
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,13 @@
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
std::optional<int> TimePart::number() {
|
std::optional<int> TimePart::number() {
|
||||||
|
static const auto RegExp = QRegularExpression("^\\d+$");
|
||||||
const auto text = getLastText();
|
const auto text = getLastText();
|
||||||
auto view = QStringView(text);
|
auto view = QStringView(text);
|
||||||
while (view.size() > 1 && view.at(0) == '0') {
|
while (view.size() > 1 && view.at(0) == '0') {
|
||||||
view = base::StringViewMid(view, 1);
|
view = base::StringViewMid(view, 1);
|
||||||
}
|
}
|
||||||
return QRegularExpression("^\\d+$").match(view).hasMatch()
|
return RegExp.match(view).hasMatch()
|
||||||
? std::make_optional(view.toInt())
|
? std::make_optional(view.toInt())
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QTime ValidateTime(const QString &value) {
|
QTime ValidateTime(const QString &value) {
|
||||||
const auto match = QRegularExpression(
|
static const auto RegExp = QRegularExpression(
|
||||||
"^(\\d{1,2})\\:(\\d\\d)$").match(value);
|
"^(\\d{1,2})\\:(\\d\\d)$");
|
||||||
|
const auto match = RegExp.match(value);
|
||||||
if (!match.hasMatch()) {
|
if (!match.hasMatch()) {
|
||||||
return QTime();
|
return QTime();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue