Use QRegularExpression instead of deprecated QRegExp

Now it follows closely the definition of wildcard for glob patterns.
The backslash (\) character is not an escape char in this context.
In order to match one of the special characters, place it in square
brackets (for example, [?]).
This commit is contained in:
Vladimir Golovnev (Glassez) 2021-03-14 18:11:23 +03:00
parent ea1c4a8fc8
commit 61d2ff359b
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
11 changed files with 53 additions and 32 deletions

View file

@ -34,7 +34,7 @@
#include <QGlobalStatic>
#include <QHash>
#include <QMetaObject>
#include <QRegExp>
#include <QRegularExpression>
#include <QStringList>
#include <QVariant>
#include <QXmlStreamEntityResolver>
@ -391,12 +391,13 @@ namespace
int nmin = 8;
int nsec = 9;
// Also accept obsolete form "Weekday, DD-Mon-YY HH:MM:SS ±hhmm"
QRegExp rx("^(?:([A-Z][a-z]+),\\s*)?(\\d{1,2})(\\s+|-)([^-\\s]+)(\\s+|-)(\\d{2,4})\\s+(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s+(\\S+)$");
QRegularExpression rx {"^(?:([A-Z][a-z]+),\\s*)?(\\d{1,2})(\\s+|-)([^-\\s]+)(\\s+|-)(\\d{2,4})\\s+(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s+(\\S+)$"};
QRegularExpressionMatch rxMatch;
QStringList parts;
if (!str.indexOf(rx))
if (str.indexOf(rx, 0, &rxMatch) == 0)
{
// Check that if date has '-' separators, both separators are '-'.
parts = rx.capturedTexts();
parts = rxMatch.capturedTexts();
const bool h1 = (parts[3] == QLatin1String("-"));
const bool h2 = (parts[5] == QLatin1String("-"));
if (h1 != h2)
@ -405,9 +406,10 @@ namespace
else
{
// Check for the obsolete form "Wdy Mon DD HH:MM:SS YYYY"
rx = QRegExp("^([A-Z][a-z]+)\\s+(\\S+)\\s+(\\d\\d)\\s+(\\d\\d):(\\d\\d):(\\d\\d)\\s+(\\d\\d\\d\\d)$");
if (str.indexOf(rx))
rx = QRegularExpression {"^([A-Z][a-z]+)\\s+(\\S+)\\s+(\\d\\d)\\s+(\\d\\d):(\\d\\d):(\\d\\d)\\s+(\\d\\d\\d\\d)$"};
if (str.indexOf(rx, 0, &rxMatch) != 0)
return QDateTime::currentDateTime();
nyear = 7;
nmonth = 2;
nday = 3;
@ -415,7 +417,7 @@ namespace
nhour = 4;
nmin = 5;
nsec = 6;
parts = rx.capturedTexts();
parts = rxMatch.capturedTexts();
}
bool ok[4];
@ -463,11 +465,11 @@ namespace
bool negOffset = false;
if (parts.count() > 10)
{
rx = QRegExp("^([+-])(\\d\\d)(\\d\\d)$");
if (!parts[10].indexOf(rx))
rx = QRegularExpression {"^([+-])(\\d\\d)(\\d\\d)$"};
if (parts[10].indexOf(rx, 0, &rxMatch) == 0)
{
// It's a UTC offset ±hhmm
parts = rx.capturedTexts();
parts = rxMatch.capturedTexts();
offset = parts[2].toInt(&ok[0]) * 3600;
const int offsetMin = parts[3].toInt(&ok[1]);
if (!ok[0] || !ok[1] || offsetMin > 59)