mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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&);
|
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:
|
private:
|
||||||
RefPtr<StringImpl> m_impl;
|
RefPtr<StringImpl> m_impl;
|
||||||
};
|
};
|
||||||
|
|
|
@ -224,6 +224,15 @@ public:
|
||||||
|
|
||||||
int replace(const String& needle, const String& replacement, bool all_occurences = false);
|
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:
|
private:
|
||||||
RefPtr<StringImpl> m_impl;
|
RefPtr<StringImpl> m_impl;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue