diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 66bdfe3d765..c38c80d182f 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -1575,6 +1575,23 @@ FilePath FilePath::withNewMappedPath(const FilePath &newPath) const return res; } +/*! + Returns a path with the \a n characters of the local path removed. + Example usage: + \code + backup = FilePath("/tmp/example.txt.backup"); + real = backup.chopped(7); + assert(real == FilePath("/tmp/example.txt")) + \endcode +*/ + +FilePath FilePath::chopped(int n) const +{ + FilePath res; + res.setParts(scheme(), host(), path().chopped(n)); + return res; +} + /*! Returns a FilePath with local path \a newPath on the same device as the current object. diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 2264e3761a2..24048a84fce 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -168,6 +168,7 @@ public: [[nodiscard]] FilePaths devicePathEnvironmentVariable() const; [[nodiscard]] FilePath withNewPath(const QString &newPath) const; [[nodiscard]] FilePath withNewMappedPath(const FilePath &newPath) const; + [[nodiscard]] FilePath chopped(int n) const; using IterateDirCallback = std::variant<