Utils: Drop commonPath(QStringList)

There's FileUtils::commonPath(FilePaths) nowadays.

Change-Id: I26e30d61eb80cb457458791e9ad049356f18de98
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-01-03 16:45:23 +01:00
parent 9441865714
commit ad7fe6fa1c
2 changed files with 0 additions and 24 deletions

View File

@@ -73,26 +73,6 @@ QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings)
return strings.at(0).left(commonLength); return strings.at(0).left(commonLength);
} }
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
{
QStringList appendedSlashes = transform(files, [](const QString &file) -> QString {
if (!file.endsWith('/'))
return QString(file + '/');
return file;
});
QString common = commonPrefix(appendedSlashes);
// Find common directory part: "C:\foo\bar" -> "C:\foo"
int lastSeparatorPos = common.lastIndexOf('/');
if (lastSeparatorPos == -1)
lastSeparatorPos = common.lastIndexOf('\\');
if (lastSeparatorPos == -1)
return QString();
if (HostOsInfo::isAnyUnixHost() && lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/'
lastSeparatorPos = 1;
common.truncate(lastSeparatorPos);
return common;
}
QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path) QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path)
{ {
if (HostOsInfo::isWindowsHost()) if (HostOsInfo::isWindowsHost())

View File

@@ -26,10 +26,6 @@ QTCREATOR_UTILS_EXPORT QString settingsKey(const QString &category);
// "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo\bar" // "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo\bar"
QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings); QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings);
// Return the common path of a list of files:
// "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo"
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files);
// On Linux/Mac replace user's home path with ~ // On Linux/Mac replace user's home path with ~
// Uses cleaned path and tries to use absolute path of "path" if possible // Uses cleaned path and tries to use absolute path of "path" if possible
// If path is not sub of home path, or when running on Windows, returns the input // If path is not sub of home path, or when running on Windows, returns the input