From 3c03878293bf2a155762a61d3a29c958eddbe0b1 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Thu, 20 Oct 2011 00:21:08 +0200
Subject: [PATCH] Use the new QUrl API

Use QByteArray::{from,to}PercentEncoding when operating directly on
byte arrays.

Don't use toEncoded/fromEncoded if the final source/destination is a
QString -- QUrl's constructor and toString() are fine for that.

Change-Id: I9349c2c6a12c43b8c5a4a4fca1fa796272ca90fa
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
---
 src/xmlpatterns/api/qcoloringmessagehandler.cpp | 8 ++++----
 src/xmlpatterns/functions/qstringvaluefns.cpp   | 5 ++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/xmlpatterns/api/qcoloringmessagehandler.cpp b/src/xmlpatterns/api/qcoloringmessagehandler.cpp
index dc574e3a..b7d0d9f8 100644
--- a/src/xmlpatterns/api/qcoloringmessagehandler.cpp
+++ b/src/xmlpatterns/api/qcoloringmessagehandler.cpp
@@ -84,14 +84,14 @@ void ColoringMessageHandler::handleMessage(QtMsgType type,
         {
             if(hasLine)
             {
-                writeUncolored(QXmlPatternistCLI::tr("Warning in %1, at line %2, column %3: %4").arg(QString::fromLatin1(sourceLocation.uri().toEncoded()),
+                writeUncolored(QXmlPatternistCLI::tr("Warning in %1, at line %2, column %3: %4").arg(sourceLocation.uri().toString(),
                                                                                                  QString::number(sourceLocation.line()),
                                                                                                  QString::number(sourceLocation.column()),
                                                                                                  colorifyDescription(description)));
             }
             else
             {
-                writeUncolored(QXmlPatternistCLI::tr("Warning in %1: %2").arg(QString::fromLatin1(sourceLocation.uri().toEncoded()),
+                writeUncolored(QXmlPatternistCLI::tr("Warning in %1: %2").arg(sourceLocation.uri().toString(),
                                                                           colorifyDescription(description)));
             }
 
@@ -109,7 +109,7 @@ void ColoringMessageHandler::handleMessage(QtMsgType type,
             if(sourceLocation.isNull())
                 location = QXmlPatternistCLI::tr("Unknown location");
             else
-                location = QString::fromLatin1(sourceLocation.uri().toEncoded());
+                location = sourceLocation.uri().toString();
 
             QString errorId;
             /* If it's a standard error code, we don't want to output the
@@ -117,7 +117,7 @@ void ColoringMessageHandler::handleMessage(QtMsgType type,
             if(uri.toString() == QLatin1String("http://www.w3.org/2005/xqt-errors"))
                 errorId = errorCode;
             else
-                errorId = QString::fromLatin1(identifier.toEncoded());
+                errorId = identifier.toString();
 
             if(hasLine)
             {
diff --git a/src/xmlpatterns/functions/qstringvaluefns.cpp b/src/xmlpatterns/functions/qstringvaluefns.cpp
index d3cb62f0..06567215 100644
--- a/src/xmlpatterns/functions/qstringvaluefns.cpp
+++ b/src/xmlpatterns/functions/qstringvaluefns.cpp
@@ -345,9 +345,8 @@ Item EncodeString::evaluateSingleton(const DynamicContext::Ptr &context) const
     if(!item)
         return CommonValues::EmptyString;
 
-    return AtomicString::fromValue(QString::fromAscii(QUrl::toPercentEncoding(item.stringValue(),
-                                                                        m_excludeChars,
-                                                                        m_includeChars).constData()));
+    return AtomicString::fromValue(item.stringValue().toUtf8().toPercentEncoding(m_excludeChars,
+                                                                        m_includeChars).constData());
 }
 
 const char *const EncodeForURIFN::include = "#!*'()";
-- 
GitLab