mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
AK: Add Utf16View::find_code_unit_offset(_ignoring_case)
This commit is contained in:
parent
7d7f6fa494
commit
cc0a28ee7d
Notes:
github-actions[bot]
2025-06-13 13:10:51 +00:00
Author: https://github.com/gmta
Commit: cc0a28ee7d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5067
Reviewed-by: https://github.com/tcl3
Reviewed-by: https://github.com/trflynn89
3 changed files with 62 additions and 0 deletions
|
@ -281,6 +281,32 @@ Utf16View Utf16View::unicode_substring_view(size_t code_point_offset, size_t cod
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Optional<size_t> Utf16View::find_code_unit_offset(Utf16View const& needle, size_t start_offset) const
|
||||
{
|
||||
return m_code_units.index_of(needle.m_code_units, start_offset);
|
||||
}
|
||||
|
||||
Optional<size_t> Utf16View::find_code_unit_offset_ignoring_case(Utf16View const& needle, size_t start_offset) const
|
||||
{
|
||||
Checked maximum_offset { start_offset };
|
||||
maximum_offset += needle.length_in_code_units();
|
||||
if (maximum_offset.has_overflow() || maximum_offset.value() > length_in_code_units())
|
||||
return {};
|
||||
|
||||
if (needle.is_empty())
|
||||
return start_offset;
|
||||
|
||||
size_t index = start_offset;
|
||||
while (index <= length_in_code_units() - needle.length_in_code_units()) {
|
||||
Utf16View const slice { m_code_units.slice(index, needle.length_in_code_units()) };
|
||||
if (slice.equals_ignoring_case(needle))
|
||||
return index;
|
||||
index += slice.begin().length_in_code_units();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool Utf16View::starts_with(Utf16View const& needle) const
|
||||
{
|
||||
if (needle.is_empty())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue