QFileDialog: refactor a static helper
- Fix narrowing conversion warnings - Don't use an out of bounds index with QStringView::mid(), which happened when view.size() was used as an index - Use sliced() Change-Id: Ia9bf62887ffb6ddd2458c9e46d33e8cfe0ee2b66 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ef53352dbc
commit
821a4234d0
@ -1134,20 +1134,28 @@ Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path)
|
|||||||
{
|
{
|
||||||
if (!path.startsWith(u'~'))
|
if (!path.startsWith(u'~'))
|
||||||
return path;
|
return path;
|
||||||
int separatorPosition = path.indexOf(QDir::separator());
|
|
||||||
if (separatorPosition < 0)
|
if (path.size() == 1) // '~'
|
||||||
separatorPosition = path.size();
|
return QDir::homePath();
|
||||||
if (separatorPosition == 1) {
|
|
||||||
return QDir::homePath() + QStringView{path}.mid(1);
|
QStringView sv(path);
|
||||||
} else {
|
const qsizetype sepIndex = sv.indexOf(QDir::separator());
|
||||||
|
if (sepIndex == 1) // '~/' or '~/a/b/c'
|
||||||
|
return QDir::homePath() + sv.sliced(1);
|
||||||
|
|
||||||
#if defined(Q_OS_VXWORKS) || defined(Q_OS_INTEGRITY)
|
#if defined(Q_OS_VXWORKS) || defined(Q_OS_INTEGRITY)
|
||||||
const QString homePath = QDir::homePath();
|
if (sepIndex == -1)
|
||||||
|
return QDir::homePath();
|
||||||
|
return QDir::homePath() + sv.sliced(sepIndex);
|
||||||
#else
|
#else
|
||||||
const QByteArray userName = QStringView{path}.mid(1, separatorPosition - 1).toLocal8Bit();
|
const qsizetype userNameLen = sepIndex != -1 ? sepIndex - strlen("~") // '~user/a/b'
|
||||||
QString homePath = homeDirFromPasswdEntry(path, userName);
|
: path.size() - strlen("~"); // '~user'
|
||||||
#endif
|
const QByteArray userName = sv.sliced(1, userNameLen).toLocal8Bit();
|
||||||
return homePath + QStringView{path}.mid(separatorPosition);
|
QString homePath = homeDirFromPasswdEntry(path, userName);
|
||||||
}
|
if (sepIndex == -1)
|
||||||
|
return homePath;
|
||||||
|
return homePath + sv.sliced(sepIndex);
|
||||||
|
#endif // defined(Q_OS_VXWORKS) || defined(Q_OS_INTEGRITY)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user