aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2016-07-13 00:37:38 +0200
committerAleix Pol <aleixpol@kde.org>2016-07-13 00:37:38 +0200
commit6c4e504d76b2424ac06c50394a0cca63860e65b5 (patch)
treeb1a918a24741c36572f3f42404cea2031319d347 /src/core
parentb068952004e123cc0879314f47e59f6ab11915eb (diff)
downloadkconfig-6c4e504d76b2424ac06c50394a0cca63860e65b5.tar.gz
kconfig-6c4e504d76b2424ac06c50394a0cca63860e65b5.tar.bz2
Reduce string modifications when calling translatePath
Don't drop the file: prefix twice in every run. Use appropriate API on paths rather than string handling, when possible. REVIEW: 127813
Diffstat (limited to 'src/core')
-rw-r--r--src/core/kconfiggroup.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp
index 39d2441a..f6eb2f52 100644
--- a/src/core/kconfiggroup.cpp
+++ b/src/core/kconfiggroup.cpp
@@ -416,24 +416,13 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue
// only "our" $HOME should be interpreted
path.replace(QLatin1Char('$'), QLatin1String("$$"));
- bool startsWithFile = path.startsWith(QLatin1String("file:"), Qt::CaseInsensitive);
+ const bool startsWithFile = path.startsWith(QLatin1String("file:"), Qt::CaseInsensitive);
+ path = startsWithFile ? QUrl(path).toLocalFile() : path;
- // return original path, if it refers to another type of URL (e.g. http:/), or
- // if the path is already relative to another directory
- if ((!startsWithFile && QFileInfo(path).isRelative()) ||
- (startsWithFile && QFileInfo(path.mid(5)).isRelative())) {
+ if (QDir::isRelativePath(path)) {
return path;
}
- if (startsWithFile) {
- path.remove(0, 5); // strip leading "file:/" off the string
- }
-
- // keep only one single '/' at the beginning - needed for cleanHomeDirPath()
- while (path[0] == QLatin1Char('/') && path[1] == QLatin1Char('/')) {
- path.remove(0, 1);
- }
-
// we can not use KGlobal::dirs()->relativeLocation("home", path) here,
// since it would not recognize paths without a trailing '/'.
// All of the 3 following functions to return the user's home directory
@@ -448,7 +437,7 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue
}
if (startsWithFile) {
- path.prepend(QStringLiteral("file://"));
+ path = QUrl::fromLocalFile(path).toString();
}
return path;