summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurl.cpp
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2013-04-25 10:01:23 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-08 15:20:47 +0200
commit10023de7a8e5a90a2be2ddbcf8a659d309b61c97 (patch)
tree0f431194b6a3b6fb3bf4a6df0665723f1b61a05f /src/corelib/io/qurl.cpp
parent602c911820fd8b0832dba64b37b3110580f381ae (diff)
QUrl: add RemoveFilename to UrlFormattingOptions.
This allows to find the parent directory url using url.adjusted(QUrl::RemoveFilename). Change-Id: I1ca433ac67e4f93080de54a9b7ab2e538509ed04 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r--src/corelib/io/qurl.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 11cc6ed7da..16263ad736 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -225,6 +225,9 @@
\value RemoveQuery The query part of the URL (following a '?' character)
is removed.
\value RemoveFragment
+ \value RemoveFilename The filename (i.e. everything after the last '/' in the path) is removed.
+ The trailing '/' is kept, unless StripTrailingSlash is set.
+ Only valid if RemovePath is not set.
\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.
@@ -800,6 +803,12 @@ 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::RemoveFilename) {
+ const int slash = path.lastIndexOf(QLatin1Char('/'));
+ if (slash == -1)
+ return;
+ thePath = path.left(slash+1);
+ }
// check if we need to remove trailing slashes
if ((options & QUrl::StripTrailingSlash) && !thePath.isEmpty() && thePath != QLatin1String("/") && thePath.endsWith(QLatin1Char('/')))
thePath.chop(1);
@@ -3226,7 +3235,7 @@ QUrl QUrl::adjusted(QUrl::FormattingOptions options) const
that.setFragment(QString());
if (options & RemovePath) {
that.setPath(QString());
- } else if (options & StripTrailingSlash) {
+ } else if (options & (StripTrailingSlash | RemoveFilename)) {
QString path;
d->appendPath(path, options, QUrlPrivate::Path);
that.setPath(path);