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:
Timothy Flynn
2024-05-31 15:51:40 -04:00
committed by Andreas Kling
parent cf6aa77816
commit fe3fde2411
5 changed files with 188 additions and 0 deletions

View File

@@ -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 {};
}
}