From cf0899f44094e4481a1ac207af9e94239647fb81 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 14 Jan 2023 10:17:32 -0500 Subject: [PATCH] AK: Add String::contains --- AK/String.cpp | 10 ++++++++++ AK/String.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/AK/String.cpp b/AK/String.cpp index ed0f8d4bb67..88a3c5d4fbd 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -339,6 +339,16 @@ ErrorOr String::reverse() const return builder.to_string(); } +bool String::contains(StringView needle, CaseSensitivity case_sensitivity) const +{ + return StringUtils::contains(bytes_as_string_view(), needle, case_sensitivity); +} + +bool String::contains(char needle, CaseSensitivity case_sensitivity) const +{ + return contains(StringView { &needle, 1 }, case_sensitivity); +} + bool String::is_short_string() const { return has_short_string_bit(reinterpret_cast(m_data)); diff --git a/AK/String.h b/AK/String.h index 54b3996e311..ce4de09bde6 100644 --- a/AK/String.h +++ b/AK/String.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -92,6 +93,9 @@ public: return (this->operator==(forward(strings)) || ...); } + [[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] u32 hash() const; template