summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r--src/corelib/io/qurl.cpp67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 681a0c7ef2..d9ebc6c750 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -421,6 +421,7 @@
#include "private/qipaddress_p.h"
#include "qurlquery.h"
#include "private/qdir_p.h"
+#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
@@ -520,10 +521,10 @@ public:
bool isEmpty() const
{ return sectionIsPresent == 0 && port == -1 && path.isEmpty(); }
- Error *cloneError() const;
+ std::unique_ptr<Error> cloneError() const;
void clearError();
void setError(ErrorCode errorCode, const QString &source, int supplement = -1);
- ErrorCode validityError(QString *source = 0, int *position = 0) const;
+ ErrorCode validityError(QString *source = nullptr, int *position = nullptr) const;
bool validateComponent(Section section, const QString &input, int begin, int end);
bool validateComponent(Section section, const QString &input)
{ return validateComponent(section, input, 0, uint(input.length())); }
@@ -576,7 +577,7 @@ public:
QString query;
QString fragment;
- Error *error;
+ std::unique_ptr<Error> error;
// not used for:
// - Port (port == -1 means absence)
@@ -591,7 +592,6 @@ public:
inline QUrlPrivate::QUrlPrivate()
: ref(1), port(-1),
- error(0),
sectionIsPresent(0),
flags(0)
{
@@ -613,19 +613,16 @@ inline QUrlPrivate::QUrlPrivate(const QUrlPrivate &copy)
}
inline QUrlPrivate::~QUrlPrivate()
-{
- delete error;
-}
+ = default;
-inline QUrlPrivate::Error *QUrlPrivate::cloneError() const
+std::unique_ptr<QUrlPrivate::Error> QUrlPrivate::cloneError() const
{
- return error ? new Error(*error) : 0;
+ return error ? qt_make_unique<Error>(*error) : nullptr;
}
inline void QUrlPrivate::clearError()
{
- delete error;
- error = 0;
+ error.reset();
}
inline void QUrlPrivate::setError(ErrorCode errorCode, const QString &source, int supplement)
@@ -634,7 +631,7 @@ inline void QUrlPrivate::setError(ErrorCode errorCode, const QString &source, in
// don't overwrite an error set in a previous section during parsing
return;
}
- error = new Error;
+ error = qt_make_unique<Error>();
error->code = errorCode;
error->source = source;
error->position = supplement;
@@ -826,7 +823,7 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to)
QString output;
const QChar *begin = input.constData() + from;
const QChar *end = input.constData() + to;
- if (qt_urlRecode(output, begin, end, 0, actions))
+ if (qt_urlRecode(output, begin, end, nullptr, actions))
return output;
return input.mid(from, to - from);
@@ -954,7 +951,7 @@ inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptio
{
appendToUser(appendTo, fragment, options,
options & QUrl::EncodeDelimiters ? fragmentInUrl :
- appendingTo == FullUrl ? 0 : fragmentInIsolation);
+ appendingTo == FullUrl ? nullptr : fragmentInIsolation);
}
inline void QUrlPrivate::appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
@@ -1179,7 +1176,7 @@ inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions o
if (host.at(0).unicode() == '[') {
// IPv6 addresses might contain a zone-id which needs to be recoded
if (options != 0)
- if (qt_urlRecode(appendTo, host.constBegin(), host.constEnd(), options, 0))
+ if (qt_urlRecode(appendTo, host.constBegin(), host.constEnd(), options, nullptr))
return;
appendTo += host;
} else {
@@ -1221,7 +1218,7 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar
--end;
QString decoded;
- if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, QUrl::FullyDecoded, 0)) {
+ if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, QUrl::FullyDecoded, nullptr)) {
begin = decoded.constBegin();
end = decoded.constEnd();
}
@@ -1233,13 +1230,13 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar
host += *begin;
else if (begin->unicode() >= '0' && begin->unicode() <= '9')
host += *begin;
- else if (begin->unicode() < 0x80 && strchr(acceptable, begin->unicode()) != 0)
+ else if (begin->unicode() < 0x80 && strchr(acceptable, begin->unicode()) != nullptr)
host += *begin;
else
return decoded.isEmpty() ? begin : &origBegin[2];
}
host += QLatin1Char(']');
- return 0;
+ return nullptr;
}
return &origBegin[2];
}
@@ -1286,7 +1283,7 @@ static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end
host += zoneId;
}
host += QLatin1Char(']');
- return 0;
+ return nullptr;
}
inline bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl::ParsingMode mode)
@@ -1352,7 +1349,7 @@ inline bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl:
// check for percent-encoding first
QString s;
- if (mode == QUrl::TolerantMode && qt_urlRecode(s, begin, end, 0, 0)) {
+ if (mode == QUrl::TolerantMode && qt_urlRecode(s, begin, end, { }, nullptr)) {
// something was decoded
// anything encoded left?
int pos = s.indexOf(QChar(0x25)); // '%'
@@ -1837,7 +1834,7 @@ inline void QUrlPrivate::validate() const
\sa setUrl(), fromEncoded(), TolerantMode
*/
-QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(0)
+QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(nullptr)
{
setUrl(url, parsingMode);
}
@@ -1845,7 +1842,7 @@ QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(0)
/*!
Constructs an empty QUrl object.
*/
-QUrl::QUrl() : d(0)
+QUrl::QUrl() : d(nullptr)
{
}
@@ -1879,7 +1876,7 @@ QUrl::~QUrl()
bool QUrl::isValid() const
{
if (isEmpty()) {
- // also catches d == 0
+ // also catches d == nullptr
return false;
}
return d->validityError() == QUrlPrivate::NoError;
@@ -1907,7 +1904,7 @@ void QUrl::clear()
{
if (d && !d->ref.deref())
delete d;
- d = 0;
+ d = nullptr;
}
/*!
@@ -3805,7 +3802,7 @@ void QUrl::detach()
*/
bool QUrl::isDetached() const
{
- return !d || d->ref.load() == 1;
+ return !d || d->ref.loadRelaxed() == 1;
}
@@ -3994,21 +3991,21 @@ static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &err
return QString();
case QUrlPrivate::InvalidSchemeError: {
- QString msg = QStringLiteral("Invalid scheme (character '%1' not permitted)");
+ auto msg = QLatin1String("Invalid scheme (character '%1' not permitted)");
return msg.arg(c);
}
case QUrlPrivate::InvalidUserNameError:
- return QString(QStringLiteral("Invalid user name (character '%1' not permitted)"))
+ return QLatin1String("Invalid user name (character '%1' not permitted)")
.arg(c);
case QUrlPrivate::InvalidPasswordError:
- return QString(QStringLiteral("Invalid password (character '%1' not permitted)"))
+ return QLatin1String("Invalid password (character '%1' not permitted)")
.arg(c);
case QUrlPrivate::InvalidRegNameError:
if (errorPosition != -1)
- return QString(QStringLiteral("Invalid hostname (character '%1' not permitted)"))
+ return QLatin1String("Invalid hostname (character '%1' not permitted)")
.arg(c);
else
return QStringLiteral("Invalid hostname (contains invalid characters)");
@@ -4017,9 +4014,9 @@ static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &err
case QUrlPrivate::InvalidIPv6AddressError:
return QStringLiteral("Invalid IPv6 address");
case QUrlPrivate::InvalidCharacterInIPv6Error:
- return QStringLiteral("Invalid IPv6 address (character '%1' not permitted)").arg(c);
+ return QLatin1String("Invalid IPv6 address (character '%1' not permitted)").arg(c);
case QUrlPrivate::InvalidIPvFutureError:
- return QStringLiteral("Invalid IPvFuture address (character '%1' not permitted)").arg(c);
+ return QLatin1String("Invalid IPvFuture address (character '%1' not permitted)").arg(c);
case QUrlPrivate::HostMissingEndBracket:
return QStringLiteral("Expected ']' to match '[' in hostname");
@@ -4029,15 +4026,15 @@ static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &err
return QStringLiteral("Port field was empty");
case QUrlPrivate::InvalidPathError:
- return QString(QStringLiteral("Invalid path (character '%1' not permitted)"))
+ return QLatin1String("Invalid path (character '%1' not permitted)")
.arg(c);
case QUrlPrivate::InvalidQueryError:
- return QString(QStringLiteral("Invalid query (character '%1' not permitted)"))
+ return QLatin1String("Invalid query (character '%1' not permitted)")
.arg(c);
case QUrlPrivate::InvalidFragmentError:
- return QString(QStringLiteral("Invalid fragment (character '%1' not permitted)"))
+ return QLatin1String("Invalid fragment (character '%1' not permitted)")
.arg(c);
case QUrlPrivate::AuthorityPresentAndPathIsRelative:
@@ -4187,7 +4184,7 @@ static QUrl adjustFtpPath(QUrl url)
static bool isIp6(const QString &text)
{
QIPAddressUtils::IPv6Address address;
- return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == 0;
+ return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == nullptr;
}
/*!