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