From 7aada633be93f581f32079610cb3db9800680449 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 10 Apr 2024 16:47:02 +0200 Subject: [PATCH] QTZP_TZ: make PosixZone default constructor replace its invalid() The type is always constructed by brace-initialization otherwise, so just NSDMI-ing its offset to InvalidOffset simplifies the handling of invalid values. Task-number: QTBUG-122619 Change-Id: Ic7173fe6572bf700bb5858a2553750023c267160 Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezoneprivate_tz.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index c046dd881d..8c6a32edc9 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -521,12 +521,10 @@ struct PosixZone }; QString name; - int offset; - - static PosixZone invalid() { return {QString(), InvalidOffset}; } - static PosixZone parse(const char *&pos, const char *end); - + int offset = InvalidOffset; bool hasValidOffset() const noexcept { return offset != InvalidOffset; } + + static PosixZone parse(const char *&pos, const char *end); }; } // unnamed namespace @@ -557,7 +555,7 @@ PosixZone PosixZone::parse(const char *&pos, const char *end) pos = nameEnd; } if (nameEnd - nameBegin < 3) - return invalid(); // name must be at least 3 characters long + return {}; // name must be at least 3 characters long // zone offset, form [+-]hh:mm:ss const char *zoneBegin = pos; @@ -576,7 +574,7 @@ PosixZone PosixZone::parse(const char *&pos, const char *end) // UTC+hh:mm:ss or GMT+hh:mm:ss should be read as offsets from UTC, not as a // POSIX rule naming a zone as UTC or GMT and specifying a non-zero offset. if (offset != 0 && (name =="UTC"_L1 || name == "GMT"_L1)) - return invalid(); + return {}; return {std::move(name), offset}; } @@ -646,7 +644,7 @@ static QList calculatePosixTransitions(const QByteArray // and the link in validatePosixRule(), above. QList parts = posixRule.split(','); - PosixZone stdZone, dstZone = PosixZone::invalid(); + PosixZone stdZone, dstZone; { const QByteArray &zoneinfo = parts.at(0); const char *begin = zoneinfo.constBegin();