Improve path extension handling

PR #16867.
This commit is contained in:
Vladimir Golovnev 2022-04-14 09:43:07 +03:00 committed by GitHub
parent 669b67e666
commit 7377974731
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 15 deletions

View file

@ -151,7 +151,7 @@ QString Path::extension() const
return ((dotIndex == -1) ? QString() : filename.mid(dotIndex).toString());
}
bool Path::hasExtension(const QString &ext) const
bool Path::hasExtension(const QStringView ext) const
{
Q_ASSERT(ext.startsWith(u'.') && (ext.size() >= 2));
@ -186,12 +186,17 @@ Path Path::removedExtension() const
return createUnchecked(m_pathStr.chopped(extension().size()));
}
void Path::removeExtension(const QString &ext)
void Path::removeExtension(const QStringView ext)
{
if (hasExtension(ext))
m_pathStr.chop(ext.size());
}
Path Path::removedExtension(const QStringView ext) const
{
return (hasExtension(ext) ? createUnchecked(m_pathStr.chopped(ext.size())) : *this);
}
QString Path::data() const
{
return m_pathStr;