mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +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:
parent
21a574f6d2
commit
5e77517e6e
Notes:
sideshowbarker
2024-07-19 06:09:11 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5e77517e6e7
2 changed files with 21 additions and 2 deletions
|
@ -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;
|
||||
};
|
||||
|
|
13
AK/String.h
13
AK/String.h
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue