From d71efc1850f87c803dc6acb917aa07f7bbef0e21 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 23 Sep 2024 14:11:36 +0200 Subject: [PATCH] Utils: Add prefixRemoved to FilePath Helper to create a prefix-cut FilePath. Change-Id: I4f827fb9975a38d9be794ab27bc103c7fd9ffd00 Reviewed-by: hjk --- src/libs/utils/filepath.cpp | 7 +++++++ src/libs/utils/filepath.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 8252825d9e9..d52b6fea04c 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -1949,6 +1949,13 @@ std::optional FilePath::tailRemoved(const QString &str) const return {}; } +std::optional FilePath::prefixRemoved(const QString &str) const +{ + if (pathView().startsWith(str)) + return withNewPath(pathView().mid(str.size()).toString()); + return {}; +} + QDateTime FilePath::lastModified() const { return fileAccess()->lastModified(*this); diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 8c24e956fff..dd0e4c9f4c3 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -140,6 +140,7 @@ public: [[nodiscard]] FilePath pathAppended(const QString &str) const; [[nodiscard]] FilePath stringAppended(const QString &str) const; [[nodiscard]] std::optional tailRemoved(const QString &str) const; + [[nodiscard]] std::optional prefixRemoved(const QString &str) const; bool startsWith(const QString &s) const; bool endsWith(const QString &s) const; bool contains(const QString &s) const;