AK: Add String::equals_ignoring_case(StringView)
This commit is contained in:
parent
413618454b
commit
e3c0e75055
Notes:
sideshowbarker
2024-07-19 10:49:31 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e3c0e750556
2 changed files with 21 additions and 0 deletions
|
@ -7,6 +7,13 @@
|
||||||
extern "C" char* strstr(const char* haystack, const char* needle);
|
extern "C" char* strstr(const char* haystack, const char* needle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline char to_lowercase(char c)
|
||||||
|
{
|
||||||
|
if (c >= 'A' && c <= 'Z')
|
||||||
|
return c | 0x20;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
bool String::operator==(const String& other) const
|
bool String::operator==(const String& other) const
|
||||||
|
@ -322,5 +329,17 @@ bool String::contains(const String& needle) const
|
||||||
return strstr(characters(), needle.characters());
|
return strstr(characters(), needle.characters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool String::equals_ignoring_case(const StringView& other) const
|
||||||
|
{
|
||||||
|
if (other.m_impl == impl())
|
||||||
|
return true;
|
||||||
|
if (length() != other.length())
|
||||||
|
return false;
|
||||||
|
for (size_t i = 0; i < length(); ++i) {
|
||||||
|
if (::to_lowercase(characters()[i]) != ::to_lowercase(other.characters_without_null_termination()[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -110,6 +110,8 @@ public:
|
||||||
return m_impl->to_uppercase();
|
return m_impl->to_uppercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool equals_ignoring_case(const StringView&) const;
|
||||||
|
|
||||||
bool contains(const String&) const;
|
bool contains(const String&) const;
|
||||||
|
|
||||||
Vector<String> split_limit(char separator, size_t limit) const;
|
Vector<String> split_limit(char separator, size_t limit) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue