diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 55e0d8fb273..b6cef68bdee 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -248,10 +248,15 @@ QString FilePath::nativePath() const return data; } -QString FilePath::fileName() const +QStringView FilePath::fileNameView() const { const QStringView fp = pathView(); - return fp.mid(fp.lastIndexOf('/') + 1).toString(); + return fp.mid(fp.lastIndexOf('/') + 1); +} + +QString FilePath::fileName() const +{ + return fileNameView().toString(); } QString FilePath::fileNameWithPathComponents(int pathComponents) const @@ -313,17 +318,22 @@ QString FilePath::completeBaseName() const /// (but not including) the last '.'. In case of ".ui.qml" it will /// be treated as one suffix. -QString FilePath::suffix() const +QStringView FilePath::suffixView() const { - const QString &name = fileName(); - if (name.endsWith(".ui.qml")) - return "ui.qml"; + const QStringView name = fileNameView(); + if (name.endsWith(u".ui.qml")) + return u"ui.qml"; const int index = name.lastIndexOf('.'); if (index >= 0) return name.mid(index + 1); return {}; } +QString FilePath::suffix() const +{ + return suffixView().toString(); +} + /// \returns the complete suffix (extension) of the file. /// /// The complete suffix consists of all characters in the file after @@ -572,7 +582,7 @@ static FilePaths appendExeExtensions(const Environment &env, const FilePath &exe if (executable.osType() == OsTypeWindows) { // Check all the executable extensions on windows: // PATHEXT is only used if the executable has no extension - if (executable.suffix().isEmpty()) { + if (executable.suffixView().isEmpty()) { const QStringList extensions = env.expandedValueForKey("PATHEXT").split(';'); for (const QString &ext : extensions) diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 429be2619c8..2e0f45b29d7 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -81,11 +81,13 @@ public: void setParts(const QStringView scheme, const QStringView host, const QStringView path); QString fileName() const; + QStringView fileNameView() const; QString fileNameWithPathComponents(int pathComponents) const; QString baseName() const; QString completeBaseName() const; QString suffix() const; + QStringView suffixView() const; QString completeSuffix() const; [[nodiscard]] FilePath pathAppended(const QString &str) const;