AK: Add StringView::find_first/last_of

These methods search from the beginning or end of a string for the
first character in the input StringView and returns the position in
the string of the first match. Note that this is not a substring match.
Each comes with single char overloads for efficiency.
This commit is contained in:
Andrew Kaster 2020-05-02 12:21:20 -06:00 committed by Andreas Kling
commit 3eb3c2477f
Notes: sideshowbarker 2024-07-19 07:00:18 +09:00
3 changed files with 91 additions and 0 deletions

View file

@ -79,6 +79,12 @@ public:
bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
bool contains(char) const;
Optional<size_t> find_first_of(char) const;
Optional<size_t> find_first_of(const StringView&) const;
Optional<size_t> find_last_of(char) const;
Optional<size_t> find_last_of(const StringView&) const;
StringView substring_view(size_t start, size_t length) const;
Vector<StringView> split_view(char, bool keep_empty = false) const;