mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06:00
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:
@@ -213,10 +213,8 @@ QRegularExpression AutoDownloadRule::cachedRegex(const QString &expression, cons
|
||||
QRegularExpression ®ex = m_dataPtr->cachedRegexes[expression];
|
||||
if (regex.pattern().isEmpty())
|
||||
{
|
||||
regex = QRegularExpression
|
||||
{
|
||||
(isRegex ? expression : Utils::String::wildcardToRegex(expression))
|
||||
, QRegularExpression::CaseInsensitiveOption};
|
||||
const QString pattern = (isRegex ? expression : Utils::String::wildcardToRegexPattern(expression));
|
||||
regex = QRegularExpression {pattern, QRegularExpression::CaseInsensitiveOption};
|
||||
}
|
||||
|
||||
return regex;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user