Commit 3895eeb2 authored by David Jarvie's avatar David Jarvie
Browse files

Make QRegularExpressions static const

parent 95fe1f8b
Pipeline #218437 passed with stage
in 1 minute and 49 seconds
KAlarm Change Log
=== Version 3.5.2 (KDE Gear 22.12) --- 3 August 2022 ===
=== Version 3.5.2 (KDE Gear 22.12) --- 15 August 2022 ===
* Provide build option to disable use of X11, even if it is available.
=== Version 3.5.1 (KDE Gear 22.08.1) --- 15 August 2022 ===
......
......@@ -33,7 +33,7 @@ ResourceId EventId::resourceDisplayId() const
QString EventId::extractIDs(const QString& resourceEventId, QString& eventId)
{
QRegularExpression rx(QStringLiteral("^(\\w+):(.*)$"));
static const QRegularExpression rx(QStringLiteral("^(\\w+):(.*)$"));
QRegularExpressionMatch rxmatch = rx.match(resourceEventId);
if (!rxmatch.hasMatch())
{
......
......@@ -1971,7 +1971,7 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
int nmin = 8;
int nsec = 9;
// Also accept obsolete form "Weekday, DD-Mon-YY HH:MM:SS ±hhmm"
const QRegularExpression rx1(QLatin1String(R"(^(?:([A-Z][a-z]+),\s*)?(\d{1,2})(\s+|-)([^-\s]+)(\s+|-)(\d{2,4})\s+(\d\d):(\d\d)(?::(\d\d))?\s+(\S+)$)"));
static const QRegularExpression rx1(QStringLiteral(R"(^(?:([A-Z][a-z]+),\s*)?(\d{1,2})(\s+|-)([^-\s]+)(\s+|-)(\d{2,4})\s+(\d\d):(\d\d)(?::(\d\d))?\s+(\S+)$)"));
const QRegularExpressionMatch match1 = rx1.match(str);
QStringList parts_;
if (match1.hasMatch())
......@@ -1986,7 +1986,7 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
else
{
// Check for the obsolete form "Wdy Mon DD HH:MM:SS YYYY"
const QRegularExpression rx2(QLatin1String(R"(^([A-Z][a-z]+)\s+(\S+)\s+(\d\d)\s+(\d\d):(\d\d):(\d\d)\s+(\d\d\d\d)$)"));
static const QRegularExpression rx2(QStringLiteral(R"(^([A-Z][a-z]+)\s+(\S+)\s+(\d\d)\s+(\d\d):(\d\d):(\d\d)\s+(\d\d\d\d)$)"));
const QRegularExpressionMatch match2 = rx2.match(str);
QStringList parts_;
if (!match2.hasMatch())
......@@ -2044,7 +2044,7 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
bool negOffset = false;
if (parts.count() > 10)
{
const QRegularExpression rx(QLatin1String(R"(^([+-])(\d\d)(\d\d)$)"));
static const QRegularExpression rx(QStringLiteral(R"(^([+-])(\d\d)(\d\d)$)"));
const QRegularExpressionMatch match = rx.match(parts[10]);
if (match.hasMatch())
{
......@@ -2110,7 +2110,7 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
}
case RFC3339Date: // format is YYYY-MM-DDThh:mm:ss[.s]TZ
{
const QRegularExpression rx(QLatin1String(R"(^(\d{4})-(\d\d)-(\d\d)[Tt](\d\d):(\d\d):(\d\d)(?:\.(\d+))?([Zz]|([+-])(\d\d):(\d\d))$)"));
static const QRegularExpression rx(QStringLiteral(R"(^(\d{4})-(\d\d)-(\d\d)[Tt](\d\d):(\d\d):(\d\d)(?:\.(\d+))?([Zz]|([+-])(\d\d):(\d\d))$)"));
const QRegularExpressionMatch match = rx.match(str);
if (!match.hasMatch())
break;
......@@ -2196,31 +2196,31 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
*/
bool dateOnly = false;
// Check first for the extended format of ISO 8601
const QRegularExpression rx1(QLatin1String(R"(^([+-])?(\d{4,})-(\d\d\d|\d\d-\d\d)[T ](\d\d)(?::(\d\d)(?::(\d\d)(?:(?:\.|,)(\d+))?)?)?(Z|([+-])(\d\d)(?::(\d\d))?)?$)"));
static const QRegularExpression rx1(QStringLiteral(R"(^([+-])?(\d{4,})-(\d\d\d|\d\d-\d\d)[T ](\d\d)(?::(\d\d)(?::(\d\d)(?:(?:\.|,)(\d+))?)?)?(Z|([+-])(\d\d)(?::(\d\d))?)?$)"));
QRegularExpressionMatch match = rx1.match(str);
if (!match.hasMatch())
{
// It's not the extended format - check for the basic format
const QRegularExpression rx2(QLatin1String(R"(^([+-])?(\d{4,})(\d{4})[T ](\d\d)(?:(\d\d)(?:(\d\d)(?:(?:\.|,)(\d+))?)?)?(Z|([+-])(\d\d)(\d\d)?)?$)"));
static const QRegularExpression rx2(QStringLiteral(R"(^([+-])?(\d{4,})(\d{4})[T ](\d\d)(?:(\d\d)(?:(\d\d)(?:(?:\.|,)(\d+))?)?)?(Z|([+-])(\d\d)(\d\d)?)?$)"));
match = rx2.match(str);
if (!match.hasMatch())
{
const QRegularExpression rx3(QLatin1String(R"(^([+-])?(\d{4})(\d{3})[T ](\d\d)(?:(\d\d)(?:(\d\d)(?:(?:\.|,)(\d+))?)?)?(Z|([+-])(\d\d)(\d\d)?)?$)"));
static const QRegularExpression rx3(QStringLiteral(R"(^([+-])?(\d{4})(\d{3})[T ](\d\d)(?:(\d\d)(?:(\d\d)(?:(?:\.|,)(\d+))?)?)?(Z|([+-])(\d\d)(\d\d)?)?$)"));
match = rx3.match(str);
if (!match.hasMatch())
{
// Check for date-only formats
dateOnly = true;
const QRegularExpression rx4(QLatin1String(R"(^([+-])?(\d{4,})-(\d\d\d|\d\d-\d\d)$)"));
static const QRegularExpression rx4(QStringLiteral(R"(^([+-])?(\d{4,})-(\d\d\d|\d\d-\d\d)$)"));
match = rx4.match(str);
if (!match.hasMatch())
{
// It's not the extended format - check for the basic format
const QRegularExpression rx5(QLatin1String("^([+-])?(\\d{4,})(\\d{4})$"));
static const QRegularExpression rx5(QStringLiteral("^([+-])?(\\d{4,})(\\d{4})$"));
match = rx5.match(str);
if (!match.hasMatch())
{
const QRegularExpression rx6(QLatin1String("^([+-])?(\\d{4})(\\d{3})$"));
static const QRegularExpression rx6(QStringLiteral("^([+-])?(\\d{4})(\\d{3})$"));
match = rx6.match(str);
if (!match.hasMatch())
break;
......@@ -2355,7 +2355,7 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
case QtTextDate: // format is Wdy Mth DD [hh:mm:ss] YYYY [±hhmm]
{
int offset = 0;
const QRegularExpression rx(QLatin1String(R"(^(\S+\s+\S+\s+\d\d\s+(\d\d:\d\d:\d\d\s+)?\d\d\d\d)\s*(.*)$)"));
static const QRegularExpression rx(QStringLiteral(R"(^(\S+\s+\S+\s+\d\d\s+(\d\d:\d\d:\d\d\s+)?\d\d\d\d)\s*(.*)$)"));
const QRegularExpressionMatch match = rx.match(str);
if (!match.hasMatch())
break;
......@@ -2386,7 +2386,7 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
return KADateTime(qdt.date(), qdt.time(), KADateTimePrivate::fromStringDefault());
}
}
const QRegularExpression rx2(QLatin1String(R"(([+-])([\d][\d])(?::?([\d][\d]))?$)"));
static const QRegularExpression rx2(QStringLiteral(R"(([+-])([\d][\d])(?::?([\d][\d]))?$)"));
const QRegularExpressionMatch match2 = rx2.match(parts[3]);
if (!match2.hasMatch())
break;
......
......@@ -163,7 +163,8 @@ bool browseFile(QString& file, const QString& caption, QString& defaultDir,
bool existing, QWidget* parent)
{
file.clear();
const QString initialDir = !initialFile.isEmpty() ? pathOrUrl(initialFile).remove(QRegularExpression(QLatin1String("/[^/]*$")))
static const QRegularExpression re(QStringLiteral("/[^/]*$"));
const QString initialDir = !initialFile.isEmpty() ? pathOrUrl(initialFile).remove(re)
: !defaultDir.isEmpty() ? defaultDir
: QDir::homePath();
// Use AutoQPointer to guard against crash on application exit while
......
......@@ -150,7 +150,7 @@ void LineEdit::dropEvent(QDropEvent* e)
{
// Remove newlines from a list of email addresses, and allow an eventual mailto: scheme
const QString mailto = QStringLiteral("mailto:");
static QRegularExpression regexp(QLatin1String("[\r\n]+"));
static const QRegularExpression regexp(QStringLiteral("[\r\n]+"));
newEmails = txt.split(regexp, Qt::SkipEmptyParts);
for (QStringList::Iterator it = newEmails.begin(); it != newEmails.end(); ++it)
{
......
......@@ -210,7 +210,7 @@ void MessageDisplayHelper::initTexts()
// start of the translated string, allowing for possible HTML tags
// enclosing "Reminder".
QString s = i18nc("@info", "Reminder");
const QRegularExpression re(QStringLiteral("^(<[^>]+>)*")); // search for HTML tag "<...>"
static const QRegularExpression re(QStringLiteral("^(<[^>]+>)*")); // search for HTML tag "<...>"
const QRegularExpressionMatch match = re.match(s);
// Prefix the time, plus a newline, to "Reminder", inside any HTML tags.
s.insert(match.capturedEnd(0), mTexts.time + QLatin1String("<br/>"));
......
......@@ -433,7 +433,8 @@ bool FileResource::save(QString* errorMessage, bool writeThroughCache, bool forc
if (errorMessage)
{
*errorMessage = msg + errMessage;
errorMessage->replace(QRegularExpression(QStringLiteral("</html><html>")), QStringLiteral("<br><br>"));
static const QRegularExpression re(QStringLiteral("</html><html>"));
errorMessage->replace(re, QStringLiteral("<br><br>"));
}
else
Resources::notifyResourceMessage(this, MessageType::Error, msg, errMessage);
......
......@@ -57,7 +57,8 @@ void FileResourceConfigManager::createResources(QObject* parent)
return;
manager->mCreated = 1;
QStringList resourceGroups = manager->mConfig->groupList().filter(QRegularExpression(QStringLiteral("^Resource_\\d+$")));
static const QRegularExpression re(QStringLiteral("^Resource_\\d+$"));
QStringList resourceGroups = manager->mConfig->groupList().filter(re);
if (!resourceGroups.isEmpty())
{
std::sort(resourceGroups.begin(), resourceGroups.end(),
......
......@@ -710,9 +710,9 @@ QString ResourceDataModelBase::alarmTimeText(const DateTime& dateTime, char lead
// 'HH' and 'hh' provide leading zeroes; single 'H' or 'h' provide no
// leading zeroes.
static const QRegularExpression hourReg(QLatin1String("[hH]"));
static const QRegularExpression hourReg(QStringLiteral("[hH]"));
int i = timeFormat.indexOf(hourReg);
static const QRegularExpression hourMinAmPmReg(QLatin1String("[hHmaA]"));
static const QRegularExpression hourMinAmPmReg(QStringLiteral("[hHmaA]"));
int first = timeFormat.indexOf(hourMinAmPmReg);
if (i >= 0 && i == first && (i == timeFormat.size() - 1 || timeFormat.at(i) != timeFormat.at(i + 1)))
{
......
......@@ -677,7 +677,8 @@ bool ResourceView::viewportEvent(QEvent* e)
int i = toolTip.indexOf(QLatin1Char('@'));
if (i > 0)
{
const int j = toolTip.indexOf(QRegularExpression(QLatin1String("<(nl|br)"), QRegularExpression::CaseInsensitiveOption), i + 1);
static const QRegularExpression re(QStringLiteral("<(nl|br)"), QRegularExpression::CaseInsensitiveOption);
const int j = toolTip.indexOf(re, i + 1);
const int k = toolTip.indexOf(QLatin1Char('@'), j);
const QString name = toolTip.mid(i + 1, j - i - 1);
value = model()->data(index, Qt::FontRole);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment