Utils: add FilePath::(complete)suffix

The same as FilePath::(complete)baseName avoid some toFileInfo.

Change-Id: Id1901ce2a4bef675215a9e020280df1c846df405
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2021-06-04 09:13:49 +02:00
parent eafc52cf1e
commit aa8d2dc2d1
7 changed files with 37 additions and 8 deletions

View File

@@ -787,6 +787,34 @@ QString FilePath::completeBaseName() const
return name.left(name.lastIndexOf('.'));
}
/// \returns the suffix (extension) of the file.
///
/// The suffix consists of all characters in the file after
/// (but not including) the last '.'.
QString FilePath::suffix() const
{
const QString &name = fileName();
const int index = name.lastIndexOf('.');
if (index >= 0)
return name.mid(index + 1);
return {};
}
/// \returns the complete suffix (extension) of the file.
///
/// The complete suffix consists of all characters in the file after
/// (but not including) the first '.'.
QString FilePath::completeSuffix() const
{
const QString &name = fileName();
const int index = name.indexOf('.');
if (index >= 0)
return name.mid(index + 1);
return {};
}
void FilePath::setScheme(const QString &scheme)
{
QTC_CHECK(!scheme.contains('/'));