1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2019-10-28 18:47:48 +01:00
parent fe83d5087b
commit 01c6088789
3 changed files with 43 additions and 0 deletions

View file

@ -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());
}
}