diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-28 18:47:48 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-28 19:08:48 +0100 |
commit | 01c6088789281005150e39d651aac5078efe477a (patch) | |
tree | 18a628942c69da0e5d9fd393d334601a4f706425 /AK | |
parent | fe83d5087bbec8efcce159daa07930abe94838c4 (diff) | |
download | serenity-01c6088789281005150e39d651aac5078efe477a.zip |
AK: Add String::contains(String)
This is just a wrapper around strstr() for now. There are many better
ways to search for a string within a string, but I'm just adding a nice
API at the moment. :^)
Diffstat (limited to 'AK')
-rw-r--r-- | AK/String.cpp | 10 | ||||
-rwxr-xr-x | AK/String.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/AK/String.cpp b/AK/String.cpp index d20193685f..0b97b0da83 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -3,6 +3,10 @@ #include <AK/StringBuilder.h> #include <stdarg.h> +#ifdef KERNEL +extern "C" char* strstr(const char* haystack, const char* needle); +#endif + namespace AK { bool String::operator==(const String& other) const @@ -313,4 +317,10 @@ bool String::match_helper(const StringView& mask) const return (mask_ptr == mask_end) && !*string_ptr; } +bool String::contains(const String& needle) const +{ + return strstr(characters(), needle.characters()); +} + } + diff --git a/AK/String.h b/AK/String.h index 0db5751810..486d2e381e 100755 --- a/AK/String.h +++ b/AK/String.h @@ -110,6 +110,8 @@ public: return m_impl->to_uppercase(); } + bool contains(const String&) const; + Vector<String> split_limit(char separator, int limit) const; Vector<String> split(char separator) const; String substring(int start, int length) const; |