diff options
Diffstat (limited to 'src/libs/utils/stringutils.cpp')
-rw-r--r-- | src/libs/utils/stringutils.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libs/utils/stringutils.cpp b/src/libs/utils/stringutils.cpp index cf1b4b36cf..10a2d41839 100644 --- a/src/libs/utils/stringutils.cpp +++ b/src/libs/utils/stringutils.cpp @@ -31,6 +31,8 @@ #include <QtCore/QString> #include <QtCore/QStringList> +#include <QtCore/QFileInfo> +#include <QtCore/QDir> #include <limits.h> @@ -100,4 +102,21 @@ QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files) return common; } +QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path) +{ +#ifdef Q_OS_WIN + QString outPath = path; +#else + static const QString homePath = QDir::homePath(); + + QFileInfo fi(QDir::cleanPath(path)); + QString outPath = fi.absoluteFilePath(); + if (outPath.startsWith(homePath)) + outPath = QLatin1Char('~') + outPath.mid(homePath.size()); + else + outPath = path; +#endif + return outPath; +} + } // namespace Utils |