forked from qt-creator/qt-creator
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:
@@ -810,17 +810,16 @@ void FilePath::setPath(QStringView path)
|
|||||||
setParts(scheme(), host(), 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 qtcDevSlash(u"__qtc_devices__/");
|
||||||
static const QStringView colonSlashSlash(u"://");
|
static const QStringView colonSlashSlash(u"://");
|
||||||
|
|
||||||
const QChar slash('/');
|
const QChar slash('/');
|
||||||
const QStringView fileNameView(fileName);
|
|
||||||
|
|
||||||
bool startsWithQtcSlashDev = false;
|
bool startsWithQtcSlashDev = false;
|
||||||
QStringView withoutQtcDeviceRoot = fileNameView;
|
QStringView withoutQtcDeviceRoot = fileNameView;
|
||||||
if (fileNameView.startsWith('/') && fileNameView.mid(1).startsWith(qtcDevSlash)) {
|
if (fileNameView.startsWith(slash) && fileNameView.mid(1).startsWith(qtcDevSlash)) {
|
||||||
startsWithQtcSlashDev = true;
|
startsWithQtcSlashDev = true;
|
||||||
withoutQtcDeviceRoot = withoutQtcDeviceRoot.mid(1 + qtcDevSlash.size());
|
withoutQtcDeviceRoot = withoutQtcDeviceRoot.mid(1 + qtcDevSlash.size());
|
||||||
} else if (fileNameView.size() > 3 && isWindowsDriveLetter(fileNameView.at(0))
|
} else if (fileNameView.size() > 3 && isWindowsDriveLetter(fileNameView.at(0))
|
||||||
@@ -847,22 +846,23 @@ void FilePath::setFromString(const QString &fileName)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setParts({}, {}, fileName);
|
setParts({}, {}, fileNameView);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int firstSlash = fileName.indexOf(slash);
|
const int firstSlash = fileNameView.indexOf(slash);
|
||||||
const int schemeEnd = fileName.indexOf(colonSlashSlash);
|
const int schemeEnd = fileNameView.indexOf(colonSlashSlash);
|
||||||
if (schemeEnd != -1 && schemeEnd < firstSlash) {
|
if (schemeEnd != -1 && schemeEnd < firstSlash) {
|
||||||
// This is a pseudo Url, we can't use QUrl here sadly.
|
// This is a pseudo Url, we can't use QUrl here sadly.
|
||||||
const QString scheme = fileName.left(schemeEnd);
|
const QStringView scheme = fileNameView.left(schemeEnd);
|
||||||
const int hostEnd = fileName.indexOf(slash, schemeEnd + 3);
|
const int hostEnd = fileNameView.indexOf(slash, schemeEnd + 3);
|
||||||
const QString host = decodeHost(fileName.mid(schemeEnd + 3, hostEnd - schemeEnd - 3));
|
const QString host = decodeHost(
|
||||||
setParts(scheme, host, hostEnd != -1 ? QStringView(fileName).mid(hostEnd) : QStringView());
|
fileNameView.mid(schemeEnd + 3, hostEnd - schemeEnd - 3).toString());
|
||||||
|
setParts(scheme, host, hostEnd != -1 ? fileNameView.mid(hostEnd) : QStringView());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setParts({}, {}, fileName);
|
setParts({}, {}, fileNameView);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceFileAccess *FilePath::fileAccess() const
|
DeviceFileAccess *FilePath::fileAccess() const
|
||||||
|
@@ -55,7 +55,7 @@ class QTCREATOR_UTILS_EXPORT FilePath
|
|||||||
public:
|
public:
|
||||||
FilePath();
|
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 fromString(const QString &filepath);
|
||||||
[[nodiscard]] static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension);
|
[[nodiscard]] static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension);
|
||||||
@@ -239,7 +239,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class ::tst_fileutils;
|
friend class ::tst_fileutils;
|
||||||
void setPath(QStringView path);
|
void setPath(QStringView path);
|
||||||
void setFromString(const QString &filepath);
|
void setFromString(QStringView filepath);
|
||||||
DeviceFileAccess *fileAccess() const;
|
DeviceFileAccess *fileAccess() const;
|
||||||
|
|
||||||
[[nodiscard]] QString encodedHost() const;
|
[[nodiscard]] QString encodedHost() const;
|
||||||
|
Reference in New Issue
Block a user