mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-07 05:31:25 -07:00
Add fast way of removing suggested extension
This commit is contained in:
parent
293479a1f2
commit
1e45b7f50b
4 changed files with 12 additions and 7 deletions
|
@ -149,13 +149,13 @@ QString Path::extension() const
|
|||
|
||||
const int slashIndex = m_pathStr.lastIndexOf(QLatin1Char('/'));
|
||||
const auto filename = QStringView(m_pathStr).mid(slashIndex + 1);
|
||||
const int dotIndex = filename.lastIndexOf(QLatin1Char('.'));
|
||||
const int dotIndex = filename.lastIndexOf(QLatin1Char('.'), -2);
|
||||
return ((dotIndex == -1) ? QString() : filename.mid(dotIndex).toString());
|
||||
}
|
||||
|
||||
bool Path::hasExtension(const QString &ext) const
|
||||
{
|
||||
Q_ASSERT(ext.startsWith(QLatin1Char('.')));
|
||||
Q_ASSERT(ext.startsWith(QLatin1Char('.')) && (ext.size() >= 2));
|
||||
|
||||
return m_pathStr.endsWith(ext, Qt::CaseInsensitive);
|
||||
}
|
||||
|
@ -183,6 +183,12 @@ void Path::removeExtension()
|
|||
m_pathStr.chop(extension().size());
|
||||
}
|
||||
|
||||
void Path::removeExtension(const QString &ext)
|
||||
{
|
||||
if (hasExtension(ext))
|
||||
m_pathStr.chop(ext.size());
|
||||
}
|
||||
|
||||
QString Path::data() const
|
||||
{
|
||||
return m_pathStr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue