AK: Remove superfluous check from Utf16View::equals_ignoring_case()

Returning true if both lengths are 0 is already handled by the default
case.
This commit is contained in:
Jelle Raaijmakers 2025-06-10 15:17:59 +02:00 committed by Jelle Raaijmakers
commit 7d7f6fa494
Notes: github-actions[bot] 2025-06-13 13:10:57 +00:00
2 changed files with 15 additions and 2 deletions

View file

@ -344,8 +344,6 @@ size_t Utf16View::calculate_length_in_code_points() const
bool Utf16View::equals_ignoring_case(Utf16View const& other) const bool Utf16View::equals_ignoring_case(Utf16View const& other) const
{ {
if (length_in_code_units() == 0)
return other.length_in_code_units() == 0;
if (length_in_code_units() != other.length_in_code_units()) if (length_in_code_units() != other.length_in_code_units())
return false; return false;

View file

@ -307,6 +307,21 @@ TEST_CASE(decode_invalid_utf16)
} }
} }
TEST_CASE(equals_ignoring_case)
{
auto string1 = MUST(AK::utf8_to_utf16("foobar"sv));
auto string2 = MUST(AK::utf8_to_utf16("FooBar"sv));
EXPECT(Utf16View { string1 }.equals_ignoring_case(Utf16View { string2 }));
string1 = MUST(AK::utf8_to_utf16(""sv));
string2 = MUST(AK::utf8_to_utf16(""sv));
EXPECT(Utf16View { string1 }.equals_ignoring_case(Utf16View { string2 }));
string1 = MUST(AK::utf8_to_utf16(""sv));
string2 = MUST(AK::utf8_to_utf16("FooBar"sv));
EXPECT(!Utf16View { string1 }.equals_ignoring_case(Utf16View { string2 }));
}
TEST_CASE(substring_view) TEST_CASE(substring_view)
{ {
auto string = MUST(AK::utf8_to_utf16("Привет 😀"sv)); auto string = MUST(AK::utf8_to_utf16("Привет 😀"sv));