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.cpp75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 38eb613d74..0f8ed9fb17 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -3403,27 +3403,8 @@ QDebug operator<<(QDebug d, const QUrl &url)
}
#endif
-/*!
- \since 4.2
-
- Returns a text string that explains why an URL is invalid in the case being;
- otherwise returns an empty string.
-*/
-QString QUrl::errorString() const
+static QString errorMessage(QUrlPrivate::ErrorCode errorCode, QChar c)
{
- if (!d)
- return QString();
-
- QUrlPrivate::ErrorCode errorCode = d->validityError();
- if (errorCode == QUrlPrivate::NoError)
- return QString();
-
- // check if the error code matches a section with error
- // unless it's a compound error (0x10000)
- if ((d->sectionHasError & (errorCode >> 8)) == 0 && (errorCode & 0x10000) == 0)
- return QString();
-
- QChar c = d->errorSupplement;
switch (errorCode) {
case QUrlPrivate::NoError:
return QString();
@@ -3444,7 +3425,7 @@ QString QUrl::errorString() const
.arg(c);
case QUrlPrivate::InvalidRegNameError:
- if (d->errorSupplement)
+ if (!c.isNull())
return QString(QStringLiteral("Invalid hostname (character '%1' not permitted)"))
.arg(c);
else
@@ -3482,6 +3463,58 @@ QString QUrl::errorString() const
return QStringLiteral("<unknown error>");
}
+static inline void appendComponentIfPresent(QString &msg, bool present, const char *componentName,
+ const QString &component)
+{
+ if (present) {
+ msg += QLatin1String(componentName);
+ msg += QLatin1Char('"');
+ msg += component;
+ msg += QLatin1String("\",");
+ }
+}
+
+/*!
+ \since 4.2
+
+ Returns a text string that explains why an URL is invalid in the case being;
+ otherwise returns an empty string.
+*/
+QString QUrl::errorString() const
+{
+ if (!d)
+ return QString();
+
+ QUrlPrivate::ErrorCode errorCode = d->validityError();
+ if (errorCode == QUrlPrivate::NoError)
+ return QString();
+
+ // check if the error code matches a section with error
+ // unless it's a compound error (0x10000)
+ if ((d->sectionHasError & (errorCode >> 8)) == 0 && (errorCode & 0x10000) == 0)
+ return QString();
+
+ QString msg = errorMessage(errorCode, d->errorSupplement);
+ msg += QLatin1Char(';');
+ appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Scheme,
+ " scheme = ", d->scheme);
+ appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::UserInfo,
+ " userinfo = ", userInfo());
+ appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Host,
+ " host = ", d->host);
+ appendComponentIfPresent(msg, d->port != -1,
+ " port = ", QString::number(d->port));
+ appendComponentIfPresent(msg, !d->path.isEmpty(),
+ " path = ", d->path);
+ appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Query,
+ " query = ", d->query);
+ appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Fragment,
+ " fragment = ", d->fragment);
+ if (msg.endsWith(QLatin1Char(',')))
+ msg.chop(1);
+ return msg;
+}
+
/*!
\typedef QUrl::DataPtr
\internal