Utils: Use QStringView in FilePath::setFromString

Change-Id: I830f4b3a7a12bfb4ddcbef443b53a37bb24bc992
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2022-12-06 17:59:50 +01:00
parent 81075b813c
commit 4d80daf71a
2 changed files with 13 additions and 13 deletions

View File

@@ -810,17 +810,16 @@ void FilePath::setPath(QStringView path)
setParts(scheme(), host(), path);
}
void FilePath::setFromString(const QString &fileName)
void FilePath::setFromString(const QStringView fileNameView)
{
static const QStringView qtcDevSlash(u"__qtc_devices__/");
static const QStringView colonSlashSlash(u"://");
const QChar slash('/');
const QStringView fileNameView(fileName);
bool startsWithQtcSlashDev = false;
QStringView withoutQtcDeviceRoot = fileNameView;
if (fileNameView.startsWith('/') && fileNameView.mid(1).startsWith(qtcDevSlash)) {
if (fileNameView.startsWith(slash) && fileNameView.mid(1).startsWith(qtcDevSlash)) {
startsWithQtcSlashDev = true;
withoutQtcDeviceRoot = withoutQtcDeviceRoot.mid(1 + qtcDevSlash.size());
} else if (fileNameView.size() > 3 && isWindowsDriveLetter(fileNameView.at(0))
@@ -847,22 +846,23 @@ void FilePath::setFromString(const QString &fileName)
return;
}
setParts({}, {}, fileName);
setParts({}, {}, fileNameView);
return;
}
const int firstSlash = fileName.indexOf(slash);
const int schemeEnd = fileName.indexOf(colonSlashSlash);
const int firstSlash = fileNameView.indexOf(slash);
const int schemeEnd = fileNameView.indexOf(colonSlashSlash);
if (schemeEnd != -1 && schemeEnd < firstSlash) {
// This is a pseudo Url, we can't use QUrl here sadly.
const QString scheme = fileName.left(schemeEnd);
const int hostEnd = fileName.indexOf(slash, schemeEnd + 3);
const QString host = decodeHost(fileName.mid(schemeEnd + 3, hostEnd - schemeEnd - 3));
setParts(scheme, host, hostEnd != -1 ? QStringView(fileName).mid(hostEnd) : QStringView());
const QStringView scheme = fileNameView.left(schemeEnd);
const int hostEnd = fileNameView.indexOf(slash, schemeEnd + 3);
const QString host = decodeHost(
fileNameView.mid(schemeEnd + 3, hostEnd - schemeEnd - 3).toString());
setParts(scheme, host, hostEnd != -1 ? fileNameView.mid(hostEnd) : QStringView());
return;
}
setParts({}, {}, fileName);
setParts({}, {}, fileNameView);
}
DeviceFileAccess *FilePath::fileAccess() const

View File

@@ -55,7 +55,7 @@ class QTCREATOR_UTILS_EXPORT FilePath
public:
FilePath();
template <size_t N> FilePath(const char (&literal)[N]) { setFromString(literal); }
template <size_t N> FilePath(const char (&literal)[N]) { setFromString(QString::fromUtf8(literal)); }
[[nodiscard]] static FilePath fromString(const QString &filepath);
[[nodiscard]] static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension);
@@ -239,7 +239,7 @@ public:
private:
friend class ::tst_fileutils;
void setPath(QStringView path);
void setFromString(const QString &filepath);
void setFromString(QStringView filepath);
DeviceFileAccess *fileAccess() const;
[[nodiscard]] QString encodedHost() const;