diff options
Diffstat (limited to 'src/corelib/io/qdataurl.cpp')
-rw-r--r-- | src/corelib/io/qdataurl.cpp | 70 |
1 files changed, 20 insertions, 50 deletions
diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp index 9cb1b9abd0..65b934b3f6 100644 --- a/src/corelib/io/qdataurl.cpp +++ b/src/corelib/io/qdataurl.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qplatformdefs.h" #include "qurl.h" @@ -43,6 +7,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::Literals; + /*! \internal @@ -51,41 +17,45 @@ QT_BEGIN_NAMESPACE */ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray &payload) { - if (uri.scheme() != QLatin1String("data") || !uri.host().isEmpty()) + if (uri.scheme() != "data"_L1 || !uri.host().isEmpty()) return false; - mimeType = QLatin1String("text/plain;charset=US-ASCII"); + mimeType = QStringLiteral("text/plain;charset=US-ASCII"); // the following would have been the correct thing, but // reality often differs from the specification. People have // data: URIs with ? and # //QByteArray data = QByteArray::fromPercentEncoding(uri.path(QUrl::FullyEncoded).toLatin1()); - QByteArray data = QByteArray::fromPercentEncoding(uri.url(QUrl::FullyEncoded | QUrl::RemoveScheme).toLatin1()); + const QByteArray dataArray = + QByteArray::fromPercentEncoding(uri.url(QUrl::FullyEncoded | QUrl::RemoveScheme).toLatin1()); + QByteArrayView data = dataArray; // parse it: - int pos = data.indexOf(','); + const qsizetype pos = data.indexOf(','); if (pos != -1) { - payload = data.mid(pos + 1); + payload = data.mid(pos + 1).toByteArray(); data.truncate(pos); data = data.trimmed(); // find out if the payload is encoded in Base64 - if (data.endsWith(";base64")) { + constexpr auto base64 = ";base64"_L1; + if (QLatin1StringView{data}.endsWith(base64, Qt::CaseInsensitive)) { payload = QByteArray::fromBase64(payload); - data.chop(7); + data.chop(base64.size()); } - if (data.toLower().startsWith("charset")) { - int i = 7; // strlen("charset") + QLatin1StringView textPlain; + constexpr auto charset = "charset"_L1; + if (QLatin1StringView{data}.startsWith(charset, Qt::CaseInsensitive)) { + qsizetype i = charset.size(); while (data.at(i) == ' ') ++i; if (data.at(i) == '=') - data.prepend("text/plain;"); + textPlain = "text/plain;"_L1; } if (!data.isEmpty()) - mimeType = QLatin1String(data.trimmed()); - + mimeType = textPlain + QLatin1StringView(data.trimmed()); } return true; |