From 56a8c598454c2e25d0e0df0a05c9df3097db59a3 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 4 Aug 2022 16:35:31 +0200 Subject: [PATCH] Utils: Make OsType addition less visible Change-Id: I092930ef6b0ed6876e32ed6b0c78d6bd58becddc Reviewed-by: Christian Stenger Reviewed-by: --- src/libs/utils/filepath.cpp | 21 ++++++++++++++++---- src/libs/utils/filepath.h | 9 +++++---- src/libs/utils/reloadpromptutils.cpp | 1 + tests/auto/utils/fileutils/tst_fileutils.cpp | 6 +++--- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 5a354287caf..6aba785c44d 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -740,14 +740,22 @@ QString FilePath::displayName(const QString &args) const \sa toString, fromUserInput */ -FilePath FilePath::fromString(const QString &filepath, OsType osType) +FilePath FilePath::fromString(const QString &filepath) { FilePath fn; - fn.setFromString(filepath, osType); + fn.setFromString(filepath); return fn; } -bool isWindowsDriveLetter(QChar ch) { +FilePath FilePath::fromStringAndOs(const QString &filepath, OsType osType) +{ + FilePath fn; + fn.setFromStringAndOs(filepath, osType); + return fn; +} + +bool isWindowsDriveLetter(QChar ch) +{ return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); } @@ -817,7 +825,12 @@ void FilePath::setRootAndPath(QStringView path, OsType osType) } } -void FilePath::setFromString(const QString &filename, OsType osType) +void FilePath::setFromString(const QString &fileName) +{ + setFromStringAndOs(fileName, HostOsInfo::hostOs()); +} + +void FilePath::setFromStringAndOs(const QString &filename, OsType osType) { static const QLatin1String qtcDevSlash("__qtc_devices__/"); static const QLatin1String colonSlashSlash("://"); diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 2f8e1d0e1e1..c0fb4b0e34e 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -6,7 +6,6 @@ #include "utils_global.h" #include "osspecificaspects.h" -#include "hostosinfo.h" #include #include @@ -48,9 +47,10 @@ class QTCREATOR_UTILS_EXPORT FilePath public: FilePath(); - template FilePath(const char (&literal)[N], OsType osType = HostOsInfo::hostOs()) { setFromString(literal, osType); } + template FilePath(const char (&literal)[N]) { setFromString(literal); } - [[nodiscard]] static FilePath fromString(const QString &filepath, OsType osType = HostOsInfo::hostOs()); + [[nodiscard]] static FilePath fromString(const QString &filepath); + [[nodiscard]] static FilePath fromStringAndOs(const QString &filepath, OsType osType); [[nodiscard]] static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension); [[nodiscard]] static FilePath fromUserInput(const QString &filepath); [[nodiscard]] static FilePath fromUtf8(const char *filepath, int filepathSize = -1); @@ -205,7 +205,8 @@ private: friend class ::tst_fileutils; static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath); void setRootAndPath(QStringView path, OsType osType); - void setFromString(const QString &filepath, OsType osType); + void setFromString(const QString &filepath); + void setFromStringAndOs(const QString &filepath, OsType osType); [[nodiscard]] QString mapToDevicePath() const; QString m_scheme; diff --git a/src/libs/utils/reloadpromptutils.cpp b/src/libs/utils/reloadpromptutils.cpp index 50f4f503ab5..4489908724e 100644 --- a/src/libs/utils/reloadpromptutils.cpp +++ b/src/libs/utils/reloadpromptutils.cpp @@ -4,6 +4,7 @@ #include "reloadpromptutils.h" #include "fileutils.h" +#include "hostosinfo.h" #include #include diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index c8dfe3ed451..55d137f2f75 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -374,7 +374,7 @@ void tst_fileutils::fromString() QFETCH(QString, path); QFETCH(OsType, osType); - FilePath filePath = FilePath::fromString(input, osType); + FilePath filePath = FilePath::fromStringAndOs(input, osType); QCOMPARE(filePath.scheme(), scheme); QCOMPARE(filePath.host(), host); QCOMPARE(filePath.path(), path); @@ -715,8 +715,8 @@ void tst_fileutils::startsWithDriveLetter_data() QTest::addColumn("expected"); QTest::newRow("empty") << FilePath() << false; - QTest::newRow("simple-win") << FilePath("c:/a", OsType::OsTypeWindows) << true; - QTest::newRow("simple-linux") << FilePath("/c:/a", OsType::OsTypeLinux) << false; + QTest::newRow("simple-win") << FilePath::fromStringAndOs("c:/a", OsType::OsTypeWindows) << true; + QTest::newRow("simple-linux") << FilePath::fromStringAndOs("/c:/a", OsType::OsTypeLinux) << false; QTest::newRow("relative") << FilePath("a/b") << false; }