summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdataurl.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2025-04-26 15:12:06 +0300
committerAhmad Samir <a.samirh78@gmail.com>2025-05-24 01:12:55 +0300
commitd4960f380e718bbc3df3fe33c68ba8c693394892 (patch)
tree246771b69859d50237be8f0bb8733a09becb5830 /src/corelib/io/qdataurl.cpp
parent0b8f0123e01d995e77a1d9c000b488d75041e7bc (diff)
qdataurl: use QLatin1StringView instead of QByteArrayView
This is URL data and we use toLatin1() to convert from QString to QByteArray. QL1SV is more suitable here because we need to do case-insensitive look ups into the <mediatype> (see https://www.rfc-editor.org/rfc/rfc2397.html) part of the URL. Drive by, use QL1SV::sliced() instead of mid(), the precondition has already been checked. Change-Id: I670c41fdb6728f6420b1a4e2046357013ea210e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdataurl.cpp')
-rw-r--r--src/corelib/io/qdataurl.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp
index b946f2bae44..ef468f2ea16 100644
--- a/src/corelib/io/qdataurl.cpp
+++ b/src/corelib/io/qdataurl.cpp
@@ -26,18 +26,18 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray
//QByteArray data = QByteArray::fromPercentEncoding(uri.path(QUrl::FullyEncoded).toLatin1());
const QByteArray dataArray =
QByteArray::fromPercentEncoding(uri.url(QUrl::FullyEncoded | QUrl::RemoveScheme).toLatin1());
- QByteArrayView data = dataArray;
+ auto data = QLatin1StringView{dataArray};
// parse it:
- const qsizetype pos = data.indexOf(',');
+ const qsizetype pos = data.indexOf(u',');
if (pos != -1) {
- payload = data.mid(pos + 1).toByteArray();
+ payload = QByteArray{data.sliced(pos + 1)};
data.truncate(pos);
data = data.trimmed();
// find out if the payload is encoded in Base64
constexpr auto base64 = ";base64"_L1; // per the RFC, at the end of `data`
- if (QLatin1StringView{data}.endsWith(base64, Qt::CaseInsensitive)) {
+ if (data.endsWith(base64, Qt::CaseInsensitive)) {
auto r = QByteArray::fromBase64Encoding(std::move(payload));
if (!r) {
// just in case someone uses `payload` without checking the returned bool
@@ -50,16 +50,16 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray
QLatin1StringView textPlain;
constexpr auto charset = "charset"_L1;
- if (QLatin1StringView{data}.startsWith(charset, Qt::CaseInsensitive)) {
- QByteArrayView copy = data.sliced(charset.size());
- while (copy.startsWith(' '))
+ if (data.startsWith(charset, Qt::CaseInsensitive)) {
+ QLatin1StringView copy = data.sliced(charset.size());
+ while (copy.startsWith(u' '))
copy.slice(1);
- if (copy.startsWith('='))
+ if (copy.startsWith(u'='))
textPlain = "text/plain;"_L1;
}
if (!data.isEmpty())
- mimeType = textPlain + QLatin1StringView(data.trimmed());
+ mimeType = textPlain + data.trimmed();
else
mimeType = QStringLiteral("text/plain;charset=US-ASCII");
return true;