summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qtimezoneprivate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qtimezoneprivate.cpp')
-rw-r--r--src/corelib/tools/qtimezoneprivate.cpp84
1 files changed, 44 insertions, 40 deletions
diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp
index 4286119586..e768905462 100644
--- a/src/corelib/tools/qtimezoneprivate.cpp
+++ b/src/corelib/tools/qtimezoneprivate.cpp
@@ -5,36 +5,28 @@
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -44,6 +36,7 @@
#include "qtimezoneprivate_p.h"
#include "qtimezoneprivate_data_p.h"
+#include <qdatastream.h>
#include <qdebug.h>
QT_BEGIN_NAMESPACE
@@ -446,32 +439,43 @@ QTimeZone::OffsetData QTimeZonePrivate::toOffsetData(const QTimeZonePrivate::Dat
bool QTimeZonePrivate::isValidId(const QByteArray &ianaId)
{
// Rules for defining TZ/IANA names as per ftp://ftp.iana.org/tz/code/Theory
- // * Use only valid POSIX file name components
- // * Within a file name component, use only ASCII letters, `.', `-' and `_'.
- // * Do not use digits
- // * A file name component must not exceed 14 characters or start with `-'
- // Aliases such as "Etc/GMT+7" and "SystemV/EST5EDT" are valid so we need to accept digits
- if (ianaId.contains(' '))
- return false;
- QList<QByteArray> parts = ianaId.split('/');
- foreach (const QByteArray &part, parts) {
- if (part.size() > 14 || part.size() < 1)
- return false;
- if (part.at(0) == '-')
- return false;
- for (int i = 0; i < part.size(); ++i) {
- QChar ch = part.at(i);
- if (!(ch >= 'a' && ch <= 'z')
+ // 1. Use only valid POSIX file name components
+ // 2. Within a file name component, use only ASCII letters, `.', `-' and `_'.
+ // 3. Do not use digits
+ // 4. A file name component must not exceed 14 characters or start with `-'
+ // Aliases such as "Etc/GMT+7" and "SystemV/EST5EDT" are valid so we need to accept digits, ':', and '+'.
+
+ // The following would be preferable if QRegExp would work on QByteArrays directly:
+ // const QRegExp rx(QStringLiteral("[a-z0-9:+._][a-z0-9:+._-]{,13}(?:/[a-z0-9:+._][a-z0-9:+._-]{,13})*"),
+ // Qt::CaseInsensitive);
+ // return rx.exactMatch(ianaId);
+
+ // hand-rolled version:
+ const int MinSectionLength = 1;
+ const int MaxSectionLength = 14;
+ int sectionLength = 0;
+ for (const char *it = ianaId.begin(), * const end = ianaId.end(); it != end; ++it, ++sectionLength) {
+ const char ch = *it;
+ if (ch == '/') {
+ if (sectionLength < MinSectionLength || sectionLength > MaxSectionLength)
+ return false; // violates (4)
+ sectionLength = -1;
+ } else if (ch == '-') {
+ if (sectionLength == 0)
+ return false; // violates (4)
+ } else if (!(ch >= 'a' && ch <= 'z')
&& !(ch >= 'A' && ch <= 'Z')
&& !(ch == '_')
&& !(ch >= '0' && ch <= '9')
&& !(ch == '-')
&& !(ch == '+')
&& !(ch == ':')
- && !(ch == '.'))
- return false;
+ && !(ch == '.')) {
+ return false; // violates (2)
}
}
+ if (sectionLength < MinSectionLength || sectionLength > MaxSectionLength)
+ return false; // violates (4)
return true;
}
@@ -558,8 +562,8 @@ template<> QTimeZonePrivate *QSharedDataPointer<QTimeZonePrivate>::clone()
// Create default UTC time zone
QUtcTimeZonePrivate::QUtcTimeZonePrivate()
{
- const QString name = QStringLiteral("UTC");
- init(QByteArrayLiteral("UTC"), 0, name, name, QLocale::AnyCountry, name);
+ const QString name = utcQString();
+ init(utcQByteArray(), 0, name, name, QLocale::AnyCountry, name);
}
// Create a named UTC time zone
@@ -583,7 +587,7 @@ QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds)
QString utcId;
if (offsetSeconds == 0)
- utcId = QStringLiteral("UTC");
+ utcId = utcQString();
else
utcId = isoOffsetFormat(offsetSeconds);
@@ -675,7 +679,7 @@ qint32 QUtcTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const
QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const
{
- return QByteArrayLiteral("UTC");
+ return utcQByteArray();
}
QSet<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const