mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 19:04:58 +00:00
AK+LibUnicode: Implement a case-insensitive variant of find_byte_offset
The existing String::find_byte_offset is case-sensitive. This variant allows performing searches using Unicode-aware case folding.
This commit is contained in:
committed by
Andreas Kling
parent
cf6aa77816
commit
fe3fde2411
@@ -47,4 +47,14 @@ bool String::equals_ignoring_case(String const& other) const
|
||||
return Unicode::equals_ignoring_case(code_points(), other.code_points());
|
||||
}
|
||||
|
||||
Optional<size_t> String::find_byte_offset_ignoring_case(StringView needle, size_t from_byte_offset) const
|
||||
{
|
||||
auto haystack = code_points().substring_view(from_byte_offset);
|
||||
|
||||
if (auto index = Unicode::find_ignoring_case(haystack, Utf8View { needle }); index.has_value())
|
||||
return *index + from_byte_offset;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user