summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorHendiadyoin1 <leon.a@serenityos.org>2022-06-18 18:35:36 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-15 12:42:43 +0200
commit154871834b60a6979bf945610e2032d8b606479e (patch)
tree283fd0725ff4ee07e7bf5f50ffa8afd78870869a /AK
parent96276c87cf9704afb518f405e56bf6fb1090332d (diff)
downloadserenity-154871834b60a6979bf945610e2032d8b606479e.zip
AK: Add a helper to get the last split-group
Diffstat (limited to 'AK')
-rw-r--r--AK/String.h2
-rw-r--r--AK/StringView.h8
2 files changed, 10 insertions, 0 deletions
diff --git a/AK/String.h b/AK/String.h
index e245e5ffd4..29682bc5ef 100644
--- a/AK/String.h
+++ b/AK/String.h
@@ -159,6 +159,8 @@ public:
using SearchDirection = StringUtils::SearchDirection;
[[nodiscard]] Optional<size_t> find_any_of(StringView needles, SearchDirection direction) const { return StringUtils::find_any_of(*this, needles, direction); }
+ [[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
+
[[nodiscard]] String substring(size_t start, size_t length) const;
[[nodiscard]] String substring(size_t start) const;
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
diff --git a/AK/StringView.h b/AK/StringView.h
index 457fefbf63..17f0623f8c 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -127,6 +127,14 @@ public:
[[nodiscard]] Vector<StringView> split_view_if(Function<bool(char)> const& predicate, bool keep_empty = false) const;
+ [[nodiscard]] StringView find_last_split_view(char separator) const
+ {
+ auto begin = find_last(separator);
+ if (!begin.has_value())
+ return *this;
+ return substring_view(begin.release_value() + 1);
+ }
+
template<VoidFunction<StringView> Callback>
void for_each_split_view(char separator, bool keep_empty, Callback callback) const
{