From 97cea9e61cbd88705d1ac573039659079b2fe356 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 12 Jul 2020 13:36:48 -0400 Subject: [PATCH] AK: Give String::index_of() an optional second "start" argument --- AK/String.cpp | 4 ++-- AK/String.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AK/String.cpp b/AK/String.cpp index 0a2a05d13ba..bcb10d2d793 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -311,13 +311,13 @@ bool String::contains(const String& needle) const return strstr(characters(), needle.characters()); } -Optional String::index_of(const String& needle) const +Optional String::index_of(const String& needle, size_t start) const { if (is_null() || needle.is_null()) return {}; const char* self_characters = characters(); - const char* result = strstr(self_characters, needle.characters()); + const char* result = strstr(self_characters + start, needle.characters()); if (!result) return {}; return Optional { result - self_characters }; diff --git a/AK/String.h b/AK/String.h index 9432c18de68..ac107f1016a 100644 --- a/AK/String.h +++ b/AK/String.h @@ -124,7 +124,7 @@ public: bool equals_ignoring_case(const StringView&) const; bool contains(const String&) const; - Optional index_of(const String&) const; + Optional index_of(const String&, size_t start = 0) const; Vector split_limit(char separator, size_t limit, bool keep_empty = false) const; Vector split(char separator, bool keep_empty = false) const;