Port QDir, QFile from QStringRef to QStringView
Task-number: QTBUG-84319 Change-Id: I7feb5c12eb5a8504c34292e0da75332b5ba9ef20 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
5caf7ef3b1
commit
4d31ddf573
|
|
@ -177,7 +177,7 @@ inline QStringList QDirPrivate::splitFilters(const QString &nameFilter, QChar se
|
|||
{
|
||||
if (sep.isNull())
|
||||
sep = getFilterSepChar(nameFilter);
|
||||
const QVector<QStringRef> split = nameFilter.splitRef(sep);
|
||||
const auto split = QStringView{nameFilter}.split(sep);
|
||||
QStringList ret;
|
||||
ret.reserve(split.size());
|
||||
for (const auto &e : split)
|
||||
|
|
@ -777,7 +777,7 @@ QString QDir::filePath(const QString &fileName) const
|
|||
if (fileName.startsWith(QLatin1Char('/')) || fileName.startsWith(QLatin1Char('\\'))) {
|
||||
// Handle the "absolute except for drive" case (i.e. \blah not c:\blah):
|
||||
const int drive = drivePrefixLength(ret);
|
||||
return drive > 0 ? ret.leftRef(drive) % fileName : fileName;
|
||||
return drive > 0 ? QStringView{ret}.left(drive) % fileName : fileName;
|
||||
}
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
|
|
@ -810,7 +810,7 @@ QString QDir::absoluteFilePath(const QString &fileName) const
|
|||
// Combine absoluteDirPath's drive with fileName
|
||||
const int drive = drivePrefixLength(absoluteDirPath);
|
||||
if (Q_LIKELY(drive))
|
||||
return absoluteDirPath.leftRef(drive) % fileName;
|
||||
return QStringView{absoluteDirPath}.left(drive) % fileName;
|
||||
|
||||
qWarning("Base directory's drive is not a letter: %s",
|
||||
qUtf8Printable(QDir::toNativeSeparators(absoluteDirPath)));
|
||||
|
|
@ -861,7 +861,6 @@ QString QDir::relativeFilePath(const QString &fileName) const
|
|||
const auto dirElts = dir.tokenize(QLatin1Char('/'), Qt::SkipEmptyParts);
|
||||
const auto fileElts = file.tokenize(QLatin1Char('/'), Qt::SkipEmptyParts);
|
||||
|
||||
|
||||
const auto dend = dirElts.end();
|
||||
const auto fend = fileElts.end();
|
||||
auto dit = dirElts.begin();
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ QString QFileSystemEngine::slowCanonicalized(const QString &path)
|
|||
if (separatorPos != -1) {
|
||||
if (fi.isDir() && !target.endsWith(slash))
|
||||
target.append(slash);
|
||||
target.append(tmpPath.midRef(separatorPos));
|
||||
target.append(QStringView{tmpPath}.mid(separatorPos));
|
||||
}
|
||||
tmpPath = QDir::cleanPath(target);
|
||||
separatorPos = 0;
|
||||
|
|
@ -156,7 +156,7 @@ static bool _q_resolveEntryAndCreateLegacyEngine_recursive(QFileSystemEntry &ent
|
|||
|
||||
const QStringList &paths = QDir::searchPaths(filePath.left(prefixSeparator));
|
||||
for (int i = 0; i < paths.count(); i++) {
|
||||
entry = QFileSystemEntry(QDir::cleanPath(paths.at(i) % QLatin1Char('/') % filePath.midRef(prefixSeparator + 1)));
|
||||
entry = QFileSystemEntry(QDir::cleanPath(paths.at(i) % QLatin1Char('/') % QStringView{filePath}.mid(prefixSeparator + 1)));
|
||||
// Recurse!
|
||||
if (_q_resolveEntryAndCreateLegacyEngine_recursive(entry, data, engine, true))
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ static QString readSymLink(const QFileSystemEntry &link)
|
|||
result = result.mid(4);
|
||||
// cut off UNC in addition when the link points at a UNC share
|
||||
// in which case we need to prepend another backslash to get \\server\share
|
||||
if (result.leftRef(3) == QLatin1String("UNC")) {
|
||||
if (QStringView{result}.left(3) == QLatin1String("UNC")) {
|
||||
result.replace(0, 3, QLatin1Char('\\'));
|
||||
}
|
||||
}
|
||||
|
|
@ -378,7 +378,7 @@ static QString readLink(const QFileSystemEntry &link)
|
|||
static bool uncShareExists(const QString &server)
|
||||
{
|
||||
// This code assumes the UNC path is always like \\?\UNC\server...
|
||||
const QVector<QStringRef> parts = server.splitRef(QLatin1Char('\\'), Qt::SkipEmptyParts);
|
||||
const auto parts = QStringView{server}.split(QLatin1Char('\\'), Qt::SkipEmptyParts);
|
||||
if (parts.count() >= 3) {
|
||||
QStringList shares;
|
||||
if (QFileSystemEngine::uncListSharesOnServer(QLatin1String("\\\\") + parts.at(2), &shares))
|
||||
|
|
@ -1195,7 +1195,7 @@ bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool remo
|
|||
if (removeEmptyParents) {
|
||||
dirName = QDir::toNativeSeparators(QDir::cleanPath(dirName));
|
||||
for (int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) {
|
||||
const QStringRef chunkRef = dirName.leftRef(slash);
|
||||
const auto chunkRef = QStringView{dirName}.left(slash);
|
||||
if (chunkRef.length() == 2 && chunkRef.at(0).isLetter() && chunkRef.at(1) == QLatin1Char(':'))
|
||||
break;
|
||||
const QString chunk = chunkRef.toString();
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ static bool isUncRoot(const QString &server)
|
|||
if (idx == -1 || idx + 1 == localPath.length())
|
||||
return true;
|
||||
|
||||
return localPath.rightRef(localPath.length() - idx - 1).trimmed().isEmpty();
|
||||
return QStringView{localPath}.right(localPath.length() - idx - 1).trimmed().isEmpty();
|
||||
}
|
||||
|
||||
static inline QString fixIfRelativeUncPath(const QString &path)
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa
|
|||
FINDEX_SEARCH_OPS(searchOps), 0, dwAdditionalFlags);
|
||||
if (findFileHandle == INVALID_HANDLE_VALUE) {
|
||||
if (nativePath.startsWith(QLatin1String("\\\\?\\UNC\\"))) {
|
||||
const QVector<QStringRef> parts = nativePath.splitRef(QLatin1Char('\\'), Qt::SkipEmptyParts);
|
||||
const auto parts = QStringView{nativePath}.split(QLatin1Char('\\'), Qt::SkipEmptyParts);
|
||||
if (parts.count() == 4 && QFileSystemEngine::uncListSharesOnServer(
|
||||
QLatin1String("\\\\") + parts.at(2), &uncShares)) {
|
||||
if (uncShares.isEmpty())
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths)
|
|||
|
||||
if (Q_UNLIKELY(on.startsWith(QLatin1String("_qt_autotest_force_engine_")))) {
|
||||
// Autotest override case - use the explicitly selected engine only
|
||||
const QStringRef forceName = on.midRef(26);
|
||||
const auto forceName = QStringView{on}.mid(26);
|
||||
if (forceName == QLatin1String("poller")) {
|
||||
qCDebug(lcWatcher, "QFileSystemWatcher: skipping native engine, using only polling engine");
|
||||
d_func()->initPollerEngine();
|
||||
|
|
|
|||
Loading…
Reference in New Issue