diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-27 13:07:25 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-01 22:32:39 +0200 |
commit | 605bda587e0d3b3eebb871a668ad6014cf843a10 (patch) | |
tree | 171ab1ef1f0758103253262ffd81473c7686ea4c /src/network/access | |
parent | 0f78e85421de113d73edf0d58b34e12ad188417c (diff) |
Remove QRegExp usage in QNetworkCookie
Changed this to not use capturedTexts(), as it
is slower than required, and behaves slightly
differently than in QRegExp (the returned list
might be shorter than the amount of captures if the
last capture didn't match).
Change-Id: I3f90128af62d784a3d1beb993ab215e0c7d6b826
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qnetworkcookie.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index 47f6112b22..16c38d89ab 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -46,7 +46,7 @@ #include "QtCore/qdebug.h" #include "QtCore/qlist.h" #include "QtCore/qlocale.h" -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #include "QtCore/qstring.h" #include "QtCore/qstringlist.h" #include "QtCore/qurl.h" @@ -593,7 +593,7 @@ static QDateTime parseDateString(const QByteArray &dateString) int zoneOffset = -1; // hour:minute:second.ms pm - QRegExp timeRx(QLatin1String("(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)")); + QRegularExpression timeRx(QLatin1String("(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)")); int at = 0; while (at < dateString.length()) { @@ -673,21 +673,23 @@ static QDateTime parseDateString(const QByteArray &dateString) && (dateString[at + 2] == ':' || dateString[at + 1] == ':')) { // While the date can be found all over the string the format // for the time is set and a nice regexp can be used. - int pos = timeRx.indexIn(QLatin1String(dateString), at); + QRegularExpressionMatch match; + int pos = QString::fromLatin1(dateString).indexOf(timeRx, at, &match); if (pos != -1) { - QStringList list = timeRx.capturedTexts(); - int h = atoi(list.at(1).toLatin1().constData()); - int m = atoi(list.at(2).toLatin1().constData()); - int s = atoi(list.at(4).toLatin1().constData()); - int ms = atoi(list.at(6).toLatin1().constData()); - if (h < 12 && !list.at(9).isEmpty()) - if (list.at(9) == QLatin1String("pm")) + QStringList list = match.capturedTexts(); + int h = match.captured(1).toInt(); + int m = match.captured(2).toInt(); + int s = match.captured(4).toInt(); + int ms = match.captured(6).toInt(); + QString ampm = match.captured(9); + if (h < 12 && !ampm.isEmpty()) + if (ampm == QLatin1String("pm")) h += 12; time = QTime(h, m, s, ms); #ifdef PARSEDATESTRINGDEBUG qDebug() << "Time:" << list << timeRx.matchedLength(); #endif - at += timeRx.matchedLength(); + at += match.capturedLength(); continue; } } |