diff options
author | David Faure <faure@kde.org> | 2013-04-25 10:33:55 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-13 17:11:59 +0200 |
commit | a7bc4e849447758e1b67b1daefd0772f3f205ca6 (patch) | |
tree | c5965b91d4c8f965b2f27e20942055930b520fa4 /src/corelib/io/qurl.cpp | |
parent | 659f62981f8fa475e138a6c47f3b50adaacba53e (diff) |
QUrl: add NormalizePathSegments to UrlFormattingOptions
This is a bit like QDir::cleanPath(), but for URL paths.
The code is shared with QDir::cleanPath(), by extracting the common parts
it into a helper, qt_normalizePathSegments().
Change-Id: I7133c5e4aa2bf17fba98af13eb5371afba64197a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r-- | src/corelib/io/qurl.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 16263ad736..b343a28e2f 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -231,6 +231,8 @@ \value PreferLocalFile If the URL is a local file according to isLocalFile() and contains no query or fragment, a local file path is returned. \value StripTrailingSlash The trailing slash is removed if one is present. + \value NormalizePathSegments Modifies the path to remove redundant directory separators, + and to resolve "."s and ".."s (as far as possible). Note that the case folding rules in \l{RFC 3491}{Nameprep}, which QUrl conforms to, require host names to always be converted to lower case, @@ -324,6 +326,7 @@ #endif QT_BEGIN_NAMESPACE +extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths); // qdir.cpp inline static bool isHex(char c) { @@ -803,6 +806,9 @@ inline void QUrlPrivate::appendPassword(QString &appendTo, QUrl::FormattingOptio inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const { QString thePath = path; + if (options & QUrl::NormalizePathSegments) { + thePath = qt_normalizePathSegments(path, false); + } if (options & QUrl::RemoveFilename) { const int slash = path.lastIndexOf(QLatin1Char('/')); if (slash == -1) @@ -3235,7 +3241,7 @@ QUrl QUrl::adjusted(QUrl::FormattingOptions options) const that.setFragment(QString()); if (options & RemovePath) { that.setPath(QString()); - } else if (options & (StripTrailingSlash | RemoveFilename)) { + } else if (options & (StripTrailingSlash | RemoveFilename | NormalizePathSegments)) { QString path; d->appendPath(path, options, QUrlPrivate::Path); that.setPath(path); |