diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2021-08-25 16:18:04 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2021-08-27 19:22:28 +0200 |
commit | b33ccd99e130c02d582ae42158663e13f093b7c3 (patch) | |
tree | c4cb461934e82c2ae27ee3736d3456eb1d38f274 /src | |
parent | 9935dfe289a2982ae336eb83b50ffdcec6d2e88a (diff) |
QNetworkCookie: Clean up
Rewrite the regex to not capture the things we ignore anyway.
Use capturedView to avoid allocating a string just to turn it into an
int.
Fix a (usually) ifdef-ed out piece of code that was still calling
a QRegExp function.
Make the QRegularExpression static const to save it from having to
recompile every time.
Change-Id: I2f4841a2bc35df4e6cea44aec72432410583f770
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qnetworkcookie.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index 8dbb36829d..81e321d86a 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -664,7 +664,8 @@ static QDateTime parseDateString(const QByteArray &dateString) int zoneOffset = -1; // hour:minute:second.ms pm - QRegularExpression timeRx(QLatin1String("(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)")); + static const QRegularExpression timeRx( + u"(\\d\\d?):(\\d\\d?)(?::(\\d\\d?)(?:\\.(\\d{1,3}))?)?(?:\\s*(am|pm))?"_qs); int at = 0; while (at < dateString.length()) { @@ -748,18 +749,17 @@ static QDateTime parseDateString(const QByteArray &dateString) // or else we get use-after-free issues: QString dateToString = QString::fromLatin1(dateString); if (auto match = timeRx.match(dateToString, at); match.hasMatch()) { - 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); + int h = match.capturedView(1).toInt(); + int m = match.capturedView(2).toInt(); + int s = match.capturedView(3).toInt(); + int ms = match.capturedView(4).toInt(); + QStringView ampm = match.capturedView(5); if (h < 12 && !ampm.isEmpty()) if (ampm == QLatin1String("pm")) h += 12; time = QTime(h, m, s, ms); #ifdef PARSEDATESTRINGDEBUG - qDebug() << "Time:" << list << timeRx.matchedLength(); + qDebug() << "Time:" << match.capturedTexts() << match.capturedLength(); #endif at += match.capturedLength(); continue; |