From 567bbbb3e93fcc97a45743b0bc00e3e63c459a89 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Fri, 8 Sep 2023 13:18:16 +0300 Subject: [PATCH] qdataurl: extract string literals to reuse size() to avoid magic numbers Change-Id: Id1dc69a024ce5597c2d1468e7cb1470df728d84c Reviewed-by: Edward Welbourne --- src/corelib/io/qdataurl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp index bb29af54ac..65b934b3f6 100644 --- a/src/corelib/io/qdataurl.cpp +++ b/src/corelib/io/qdataurl.cpp @@ -38,14 +38,16 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray data = data.trimmed(); // find out if the payload is encoded in Base64 - if (QLatin1StringView{data}.endsWith(";base64"_L1, Qt::CaseInsensitive)) { + constexpr auto base64 = ";base64"_L1; + if (QLatin1StringView{data}.endsWith(base64, Qt::CaseInsensitive)) { payload = QByteArray::fromBase64(payload); - data.chop(7); + data.chop(base64.size()); } QLatin1StringView textPlain; - if (QLatin1StringView{data}.startsWith("charset"_L1, Qt::CaseInsensitive)) { - qsizetype i = 7; // strlen("charset") + 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) == '=')