1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-05 20:54:44 +00:00

AK: Add String::is_one_of(...)

This allows you to compare a string against an arbitrary number of
other strings with a single call.
This commit is contained in:
Andreas Kling 2020-05-25 12:36:41 +02:00
parent 21a574f6d2
commit 5e77517e6e
2 changed files with 21 additions and 2 deletions

View File

@ -88,6 +88,16 @@ public:
static void did_destroy_impl(Badge<StringImpl>, StringImpl&);
bool is_one_of() { return false; }
template<typename T, typename... Rest>
bool is_one_of(const T& string, Rest... rest)
{
if (string == *this)
return true;
return is_one_of(rest...);
}
private:
RefPtr<StringImpl> m_impl;
};

View File

@ -58,9 +58,9 @@ class String {
public:
using ConstIterator = const char*;
~String() {}
~String() { }
String() {}
String() { }
String(const StringView&);
String(const String& other)
@ -224,6 +224,15 @@ public:
int replace(const String& needle, const String& replacement, bool all_occurences = false);
bool is_one_of() { return false; }
template<typename T, typename... Rest>
bool is_one_of(const T& string, Rest... rest)
{
if (string == *this)
return true;
return is_one_of(rest...);
}
private:
RefPtr<StringImpl> m_impl;
};