diff options
author | Christian Kandeler <christian.kandeler@nokia.com> | 2012-08-23 15:53:58 +0200 |
---|---|---|
committer | hjk <qthjk@ovi.com> | 2012-08-27 17:00:03 +0200 |
commit | e669f054069c3a1214a31c4c1d7d9269659c31c4 (patch) | |
tree | d611e865215dc8ee705a640fdf3e35660542632f /src/libs/utils/stringutils.cpp | |
parent | b674b59b3d652fa9c5d74dc4e16380e3a5d23882 (diff) | |
download | qt-creator-e669f054069c3a1214a31c4c1d7d9269659c31c4.tar.gz |
Utils: Introduce HostOsInfo class.
The class' member functions are intended to be used
instead of the Q_OS_* macros in all contexts where
the latter are not syntactically required.
This lowers the likelihood of changes made on one
platform breaking the build on another, e.g. due to
the code model missing symbols in #ifdef'ed out code
when refactoring.
Change-Id: I4a54788591b4c8f8d589b8368a6c683d4155c9fa
Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'src/libs/utils/stringutils.cpp')
-rw-r--r-- | src/libs/utils/stringutils.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/libs/utils/stringutils.cpp b/src/libs/utils/stringutils.cpp index 7d06ed9a8c..c6ddb87c18 100644 --- a/src/libs/utils/stringutils.cpp +++ b/src/libs/utils/stringutils.cpp @@ -30,6 +30,8 @@ #include "stringutils.h" +#include "hostosinfo.h" + #include <QString> #include <QStringList> #include <QFileInfo> @@ -95,19 +97,17 @@ QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files) lastSeparatorPos = common.lastIndexOf(QLatin1Char('\\')); if (lastSeparatorPos == -1) return QString(); -#ifdef Q_OS_UNIX - if (lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/' + if (HostOsInfo::isAnyUnixHost() && lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/' lastSeparatorPos = 1; -#endif common.truncate(lastSeparatorPos); return common; } QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path) { -#ifdef Q_OS_WIN - QString outPath = path; -#else + if (HostOsInfo::isWindowsHost()) + return path; + static const QString homePath = QDir::homePath(); QFileInfo fi(QDir::cleanPath(path)); @@ -116,7 +116,6 @@ QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path) outPath = QLatin1Char('~') + outPath.mid(homePath.size()); else outPath = path; -#endif return outPath; } |