summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-08-06 05:31:37 +0300
committerLinus Groh <mail@linusgroh.de>2022-08-30 00:50:15 +0100
commit13c8695523d94db72d19b65a5d0dd5e2a66b2e6e (patch)
tree8a618526ab14cfdb9a8e942c759159c9e5f4e610 /AK
parent123cdfa1f1a42b438ea1f14cb20844489ecaa35e (diff)
downloadserenity-13c8695523d94db72d19b65a5d0dd5e2a66b2e6e.zip
AK: Add find_first_split_view() helper for StringView container
Similar to the find_last_split_view() helper, but in this helper we search for the first split view instead of the last one.
Diffstat (limited to 'AK')
-rw-r--r--AK/StringView.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/AK/StringView.h b/AK/StringView.h
index f75786bc70..f08ac13525 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -140,6 +140,14 @@ public:
return substring_view(begin.release_value() + 1);
}
+ [[nodiscard]] StringView find_first_split_view(char separator) const
+ {
+ auto needle_begin = find(separator);
+ if (!needle_begin.has_value())
+ return *this;
+ return substring_view(0, needle_begin.release_value());
+ }
+
template<VoidFunction<StringView> Callback>
void for_each_split_view(char separator, bool keep_empty, Callback callback) const
{