summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdataurl.cpp
diff options
context:
space:
mode:
authorJonas M. Gastal <jgastal@profusion.mobi>2011-12-29 12:24:17 -0200
committerQt by Nokia <qt-info@nokia.com>2011-12-29 16:20:45 +0100
commit231369eb043e9c5221da1a4f2a724643a3f380f3 (patch)
tree0aeb845bbeea919dba5485c2351f3d7341525d0e /src/corelib/io/qdataurl.cpp
parent4c1469f7da33dd65eb5e8e9a50b79d935eb4add0 (diff)
Make qDecodeDataUrl return bool.
Change-Id: I23b9fed39af7bea6c171b35e10bd72c424bd903e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdataurl.cpp')
-rw-r--r--src/corelib/io/qdataurl.cpp66
1 files changed, 32 insertions, 34 deletions
diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp
index ed8abdd839..2764212279 100644
--- a/src/corelib/io/qdataurl.cpp
+++ b/src/corelib/io/qdataurl.cpp
@@ -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