diff options
Diffstat (limited to 'src/corelib/io/qdataurl.cpp')
-rw-r--r-- | src/corelib/io/qdataurl.cpp | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp index ed8abdd839..7e856ad647 100644 --- a/src/corelib/io/qdataurl.cpp +++ b/src/corelib/io/qdataurl.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -51,51 +51,49 @@ QT_BEGIN_NAMESPACE Decode a data: URL into its mimetype and payload. Returns a null string if the URL could not be decoded. */ -Q_CORE_EXPORT QPair<QString, QByteArray> qDecodeDataUrl(const QUrl &uri) +Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray &payload) { - QString mimeType; - QByteArray payload; + if (uri.scheme() != QLatin1String("data") || !uri.host().isEmpty()) + return false; - if (uri.scheme() == QLatin1String("data") && uri.host().isEmpty()) { - mimeType = QLatin1String("text/plain;charset=US-ASCII"); + mimeType = QLatin1String("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.encodedPath()); - QByteArray data = QByteArray::fromPercentEncoding(uri.toEncoded()); + // 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.encodedPath()); + QByteArray data = QByteArray::fromPercentEncoding(uri.toEncoded()); - // remove the data: scheme - data.remove(0, 5); + // remove the data: scheme + data.remove(0, 5); - // parse it: - int pos = data.indexOf(','); - if (pos != -1) { - payload = data.mid(pos + 1); - data.truncate(pos); - data = data.trimmed(); + // parse it: + int pos = data.indexOf(','); + if (pos != -1) { + payload = data.mid(pos + 1); + data.truncate(pos); + data = data.trimmed(); - // find out if the payload is encoded in Base64 - if (data.endsWith(";base64")) { - payload = QByteArray::fromBase64(payload); - data.chop(7); - } + // find out if the payload is encoded in Base64 + if (data.endsWith(";base64")) { + payload = QByteArray::fromBase64(payload); + data.chop(7); + } - if (data.toLower().startsWith("charset")) { - int i = 7; // strlen("charset") - while (data.at(i) == ' ') - ++i; - if (data.at(i) == '=') - data.prepend("text/plain;"); - } + if (data.toLower().startsWith("charset")) { + int i = 7; // strlen("charset") + while (data.at(i) == ' ') + ++i; + if (data.at(i) == '=') + data.prepend("text/plain;"); + } - if (!data.isEmpty()) - mimeType = QLatin1String(data.trimmed()); + if (!data.isEmpty()) + mimeType = QLatin1String(data.trimmed()); - } } - return QPair<QString,QByteArray>(mimeType,payload); + return true; } QT_END_NAMESPACE |