aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2023-12-22 09:39:13 +0100
committerhjk <hjk@qt.io>2024-01-08 15:07:19 +0000
commitc56bd22afd551ea8782270866f6d24981b0d4c39 (patch)
treec3ca0ffc6659dc9656c4ebe3615e7edbb8bd6c7e
parent60d1838220717ed51e67f0da934c3e35e3089600 (diff)
Utils: Introduce a FilePath::chopped() convenience function
Change-Id: I5fd813af83d58e62e026b3764d3d4378429c2162 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r--src/libs/utils/filepath.cpp17
-rw-r--r--src/libs/utils/filepath.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp
index 66bdfe3d76..c38c80d182 100644
--- a/src/libs/utils/filepath.cpp
+++ b/src/libs/utils/filepath.cpp
@@ -1576,6 +1576,23 @@ FilePath FilePath::withNewMappedPath(const FilePath &newPath) const
}
/*!
+ 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 2264e3761a..24048a84fc 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<