diff options
author | David Schulz <[email protected]> | 2021-06-04 09:13:49 +0200 |
---|---|---|
committer | David Schulz <[email protected]> | 2021-06-04 09:32:52 +0000 |
commit | aa8d2dc2d1ec7575fe9a8fc1170e97cd7f7c951d (patch) | |
tree | 5eab1cc3400481b978b0b883f81a751250e32bb7 /src/libs/utils/fileutils.cpp | |
parent | eafc52cf1e1f01caf3aaeb5869cd9acf7f4ae4b9 (diff) |
Utils: add FilePath::(complete)suffix
The same as FilePath::(complete)baseName avoid some toFileInfo.
Change-Id: Id1901ce2a4bef675215a9e020280df1c846df405
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/libs/utils/fileutils.cpp')
-rw-r--r-- | src/libs/utils/fileutils.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 647318a2e52..71bfd96aff5 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -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('/')); |