From 9a35dcd5d31c04721ba8dcba22a8de08f0b87f5a Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Thu, 24 Mar 2022 22:32:31 +0100 Subject: [PATCH] [libnotificationmanager] Don't recreate same regex all the time We have better things to do --- libnotificationmanager/notification.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libnotificationmanager/notification.cpp b/libnotificationmanager/notification.cpp index 66cdf16d5..a3be4eae7 100644 --- a/libnotificationmanager/notification.cpp +++ b/libnotificationmanager/notification.cpp @@ -41,11 +41,13 @@ QString Notification::Private::sanitize(const QString &text) // Finally, check if we don't have multiple
s following, // can happen for example when "\n \n" is sent, this replaces // all
s in succession with just one - t.replace(QRegularExpression(QStringLiteral("
\\s*
(\\s|
)*")), QLatin1String("
")); + static const QRegularExpression brExpr(QStringLiteral("
\\s*
(\\s|
)*")); + t.replace(brExpr, QLatin1String("
")); // This fancy RegExp escapes every occurrence of & since QtQuick Text will blatantly cut off // text where it finds a stray ampersand. // Only &{apos, quot, gt, lt, amp}; as well as { character references will be allowed - t.replace(QRegularExpression(QStringLiteral("&(?!(?:apos|quot|[gl]t|amp);|#)")), QLatin1String("&")); + static const QRegularExpression escapeExpr(QStringLiteral("&(?!(?:apos|quot|[gl]t|amp);|#)")); + t.replace(escapeExpr, QLatin1String("&")); // Don't bother adding some HTML structure if the body is now empty if (t.isEmpty()) {