Browse Source

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.
Liav A 2 years ago
parent
commit
13c8695523
1 changed files with 8 additions and 0 deletions
  1. 8 0
      AK/StringView.h

+ 8 - 0
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
     {