qdataurl: extract string literals
to reuse size() to avoid magic numbers Change-Id: Id1dc69a024ce5597c2d1468e7cb1470df728d84c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
bb5e3b56db
commit
567bbbb3e9
@ -38,14 +38,16 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray
|
|||||||
data = data.trimmed();
|
data = data.trimmed();
|
||||||
|
|
||||||
// find out if the payload is encoded in Base64
|
// 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);
|
payload = QByteArray::fromBase64(payload);
|
||||||
data.chop(7);
|
data.chop(base64.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
QLatin1StringView textPlain;
|
QLatin1StringView textPlain;
|
||||||
if (QLatin1StringView{data}.startsWith("charset"_L1, Qt::CaseInsensitive)) {
|
constexpr auto charset = "charset"_L1;
|
||||||
qsizetype i = 7; // strlen("charset")
|
if (QLatin1StringView{data}.startsWith(charset, Qt::CaseInsensitive)) {
|
||||||
|
qsizetype i = charset.size();
|
||||||
while (data.at(i) == ' ')
|
while (data.at(i) == ' ')
|
||||||
++i;
|
++i;
|
||||||
if (data.at(i) == '=')
|
if (data.at(i) == '=')
|
||||||
|
Loading…
Reference in New Issue
Block a user