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>
This commit is contained in:
parent
9935dfe289
commit
b33ccd99e1
@ -664,7 +664,8 @@ static QDateTime parseDateString(const QByteArray &dateString)
|
|||||||
int zoneOffset = -1;
|
int zoneOffset = -1;
|
||||||
|
|
||||||
// hour:minute:second.ms pm
|
// 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;
|
int at = 0;
|
||||||
while (at < dateString.length()) {
|
while (at < dateString.length()) {
|
||||||
@ -748,18 +749,17 @@ static QDateTime parseDateString(const QByteArray &dateString)
|
|||||||
// or else we get use-after-free issues:
|
// or else we get use-after-free issues:
|
||||||
QString dateToString = QString::fromLatin1(dateString);
|
QString dateToString = QString::fromLatin1(dateString);
|
||||||
if (auto match = timeRx.match(dateToString, at); match.hasMatch()) {
|
if (auto match = timeRx.match(dateToString, at); match.hasMatch()) {
|
||||||
QStringList list = match.capturedTexts();
|
int h = match.capturedView(1).toInt();
|
||||||
int h = match.captured(1).toInt();
|
int m = match.capturedView(2).toInt();
|
||||||
int m = match.captured(2).toInt();
|
int s = match.capturedView(3).toInt();
|
||||||
int s = match.captured(4).toInt();
|
int ms = match.capturedView(4).toInt();
|
||||||
int ms = match.captured(6).toInt();
|
QStringView ampm = match.capturedView(5);
|
||||||
QString ampm = match.captured(9);
|
|
||||||
if (h < 12 && !ampm.isEmpty())
|
if (h < 12 && !ampm.isEmpty())
|
||||||
if (ampm == QLatin1String("pm"))
|
if (ampm == QLatin1String("pm"))
|
||||||
h += 12;
|
h += 12;
|
||||||
time = QTime(h, m, s, ms);
|
time = QTime(h, m, s, ms);
|
||||||
#ifdef PARSEDATESTRINGDEBUG
|
#ifdef PARSEDATESTRINGDEBUG
|
||||||
qDebug() << "Time:" << list << timeRx.matchedLength();
|
qDebug() << "Time:" << match.capturedTexts() << match.capturedLength();
|
||||||
#endif
|
#endif
|
||||||
at += match.capturedLength();
|
at += match.capturedLength();
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user