forked from qt-creator/qt-creator
Utils: Consolidate the isRelative/isAbsolute implementations
Even if we do it wrong in corner cases, we should do it consistently. Change-Id: I68d5a6e55ede889cb44bedb46d0ea545dae7ba2c Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -625,7 +625,7 @@ FilePath FilePath::withExecutableSuffix() const
|
|||||||
|
|
||||||
static bool startsWithWindowsDriveLetterAndSlash(QStringView path)
|
static bool startsWithWindowsDriveLetterAndSlash(QStringView path)
|
||||||
{
|
{
|
||||||
return path.size() > 2 && (path[1] == ':' && path[2] == '/' && isWindowsDriveLetter(path[0]));
|
return path.size() > 2 && path[1] == ':' && path[2] == '/' && isWindowsDriveLetter(path[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FilePath::rootLength(const QStringView path)
|
int FilePath::rootLength(const QStringView path)
|
||||||
@@ -1533,7 +1533,7 @@ bool FilePath::isRelativePath() const
|
|||||||
const QStringView p = pathView();
|
const QStringView p = pathView();
|
||||||
if (p.startsWith('/'))
|
if (p.startsWith('/'))
|
||||||
return false;
|
return false;
|
||||||
if (p.size() > 1 && isWindowsDriveLetter(p[0]) && p.at(1) == ':')
|
if (startsWithWindowsDriveLetterAndSlash(p))
|
||||||
return false;
|
return false;
|
||||||
if (p.startsWith(u":/")) // QRC
|
if (p.startsWith(u":/")) // QRC
|
||||||
return false;
|
return false;
|
||||||
|
@@ -758,27 +758,6 @@ QString FileUtils::normalizedPathName(const QString &name)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isRelativePathHelper(const QString &path, OsType osType)
|
|
||||||
{
|
|
||||||
if (path.startsWith('/'))
|
|
||||||
return false;
|
|
||||||
if (osType == OsType::OsTypeWindows) {
|
|
||||||
if (path.startsWith('\\'))
|
|
||||||
return false;
|
|
||||||
// Unlike QFileInfo, this won't accept a relative path with a drive letter.
|
|
||||||
// Such paths result in a royal mess anyway ...
|
|
||||||
if (path.length() >= 3 && path.at(1) == ':' && path.at(0).isLetter()
|
|
||||||
&& (path.at(2) == '/' || path.at(2) == '\\'))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileUtils::isRelativePath(const QString &path)
|
|
||||||
{
|
|
||||||
return isRelativePathHelper(path, HostOsInfo::hostOs());
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath FileUtils::commonPath(const FilePath &oldCommonPath, const FilePath &filePath)
|
FilePath FileUtils::commonPath(const FilePath &oldCommonPath, const FilePath &filePath)
|
||||||
{
|
{
|
||||||
FilePath newCommonPath = oldCommonPath;
|
FilePath newCommonPath = oldCommonPath;
|
||||||
|
@@ -77,8 +77,6 @@ public:
|
|||||||
static bool makeWritable(const FilePath &path);
|
static bool makeWritable(const FilePath &path);
|
||||||
static QString normalizedPathName(const QString &name);
|
static QString normalizedPathName(const QString &name);
|
||||||
|
|
||||||
static bool isRelativePath(const QString &fileName);
|
|
||||||
static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); }
|
|
||||||
static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName);
|
static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName);
|
||||||
static FilePath commonPath(const FilePaths &paths);
|
static FilePath commonPath(const FilePaths &paths);
|
||||||
static FilePath homePath();
|
static FilePath homePath();
|
||||||
|
@@ -81,9 +81,7 @@ QStringList toAbsolutePath(const Utils::FilePath &refPath, QStringList &pathList
|
|||||||
std::cend(pathList),
|
std::cend(pathList),
|
||||||
std::back_inserter(allAbs),
|
std::back_inserter(allAbs),
|
||||||
[refPath](const QString &path) {
|
[refPath](const QString &path) {
|
||||||
if (Utils::FileUtils::isAbsolutePath(path))
|
return refPath.resolvePath(path).toString();
|
||||||
return path;
|
|
||||||
return refPath.pathAppended(path).toString();
|
|
||||||
});
|
});
|
||||||
return allAbs;
|
return allAbs;
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,7 @@ struct Target
|
|||||||
static inline QString fullName(const Utils::FilePath &srcDir, const Target &target)
|
static inline QString fullName(const Utils::FilePath &srcDir, const Target &target)
|
||||||
{
|
{
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
if (FileUtils::isAbsolutePath(target.fileName.first())) {
|
if (FilePath::fromString((target.fileName.first())).isAbsolutePath()) {
|
||||||
const auto fname = target.fileName.first().split('/').last();
|
const auto fname = target.fileName.first().split('/').last();
|
||||||
QString definedIn = FilePath::fromString(target.definedIn).absolutePath().toString();
|
QString definedIn = FilePath::fromString(target.definedIn).absolutePath().toString();
|
||||||
return definedIn.remove(srcDir.toString()) + '/' + fname;
|
return definedIn.remove(srcDir.toString()) + '/' + fname;
|
||||||
|
@@ -642,7 +642,7 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
|
|||||||
&& !isReservedName(entry.extraInfo)
|
&& !isReservedName(entry.extraInfo)
|
||||||
&& !entry.extraInfo.startsWith('~')
|
&& !entry.extraInfo.startsWith('~')
|
||||||
&& !entry.extraInfo.contains("Anonymous:")
|
&& !entry.extraInfo.contains("Anonymous:")
|
||||||
&& !FileUtils::isAbsolutePath(entry.extraInfo);
|
&& !FilePath::fromString(entry.extraInfo).isAbsolutePath();
|
||||||
const bool isBaseClassCandidate = !isReservedName(entry.displayName)
|
const bool isBaseClassCandidate = !isReservedName(entry.displayName)
|
||||||
&& !entry.displayName.startsWith("Anonymous:");
|
&& !entry.displayName.startsWith("Anonymous:");
|
||||||
if (isBaseClassCandidate)
|
if (isBaseClassCandidate)
|
||||||
|
Reference in New Issue
Block a user