summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-01-29 21:04:52 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-01-30 23:52:42 +0200
commit482a75fef9643220366029862dbf636a88bccb82 (patch)
tree8f53ca9c52d3943ca7283e2cbfe5f201a73a88bb /src
parente2b303124f8d460ec091b7c4caa0c37391bc245a (diff)
QStandardPaths/Unix: minor cleanup
- Better readability by returning early - Make a QRegularExpression static const so that the regex pattern is compiled only once Change-Id: Ic0d6bd4b068624c4ff60c6e71d09f20393adaa64 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 339f3c565e..038cdd3b8d 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -180,10 +180,11 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case CacheLocation:
case GenericCacheLocation:
{
+ if (isTestModeEnabled())
+ return QDir::homePath() + "/.qttest/cache"_L1;
+
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
- if (isTestModeEnabled())
- xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1;
if (xdgCacheHome.isEmpty())
xdgCacheHome = QDir::homePath() + "/.cache"_L1;
if (type == QStandardPaths::CacheLocation)
@@ -194,9 +195,10 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case AppLocalDataLocation:
case GenericDataLocation:
{
- QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
if (isTestModeEnabled())
- xdgDataHome = QDir::homePath() + "/.qttest/share"_L1;
+ return QDir::homePath() + "/.qttest/share"_L1;
+
+ QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
if (xdgDataHome.isEmpty())
xdgDataHome = QDir::homePath() + "/.local/share"_L1;
if (type == AppDataLocation || type == AppLocalDataLocation)
@@ -207,10 +209,11 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case GenericConfigLocation:
case AppConfigLocation:
{
+ if (isTestModeEnabled())
+ return QDir::homePath() + "/.qttest/config"_L1;
+
// http://standards.freedesktop.org/basedir-spec/latest/
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
- if (isTestModeEnabled())
- xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1;
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + "/.config"_L1;
if (type == AppConfigLocation)
@@ -253,7 +256,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (!key.isEmpty() && !isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
// Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop"
- QRegularExpression exp("^XDG_(.*)_DIR=(.*)$"_L1);
+ static const QRegularExpression exp(u"^XDG_(.*)_DIR=(.*)$"_s);
QString result;
while (!stream.atEnd()) {
const QString &line = stream.readLine();