Utils: Add prefixRemoved to FilePath

Helper to create a prefix-cut FilePath.

Change-Id: I4f827fb9975a38d9be794ab27bc103c7fd9ffd00
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2024-09-23 14:11:36 +02:00
parent d73fa51271
commit d71efc1850
2 changed files with 8 additions and 0 deletions

View File

@@ -1949,6 +1949,13 @@ std::optional<FilePath> FilePath::tailRemoved(const QString &str) const
return {};
}
std::optional<FilePath> 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);

View File

@@ -140,6 +140,7 @@ public:
[[nodiscard]] FilePath pathAppended(const QString &str) const;
[[nodiscard]] FilePath stringAppended(const QString &str) const;
[[nodiscard]] std::optional<FilePath> tailRemoved(const QString &str) const;
[[nodiscard]] std::optional<FilePath> prefixRemoved(const QString &str) const;
bool startsWith(const QString &s) const;
bool endsWith(const QString &s) const;
bool contains(const QString &s) const;