From 605bda587e0d3b3eebb871a668ad6014cf843a10 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 27 Mar 2020 13:07:25 +0100 Subject: Remove QRegExp usage in QNetworkCookie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/network/access/qnetworkcookie.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/network/access/qnetworkcookie.cpp') 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 +#include #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; } } -- cgit v1.2.3