AK+LibJS+LibWeb+LibRegex: Replace AK::Utf16Data with AK::Utf16String

This commit is contained in:
Timothy Flynn 2025-07-09 14:13:38 -04:00 committed by Tim Flynn
parent a43cb15e81
commit 9582895759
Notes: github-actions[bot] 2025-07-18 16:46:53 +00:00
22 changed files with 101 additions and 222 deletions

View file

@ -6158,8 +6158,7 @@ Vector<GC::Root<Range>> Document::find_matching_text(String const& query, CaseSe
if (text_blocks.is_empty())
return {};
auto utf16_query = MUST(AK::utf8_to_utf16(query));
Utf16View query_view { utf16_query };
auto utf16_query = Utf16String::from_utf8(query);
Vector<GC::Root<Range>> matches;
for (auto const& text_block : text_blocks) {
@ -6169,8 +6168,8 @@ Vector<GC::Root<Range>> Document::find_matching_text(String const& query, CaseSe
auto* match_start_position = text_block.positions.data();
while (true) {
auto match_index = case_sensitivity == CaseSensitivity::CaseInsensitive
? text_view.find_code_unit_offset_ignoring_case(query_view, offset)
: text_view.find_code_unit_offset(query_view, offset);
? text_view.find_code_unit_offset_ignoring_case(utf16_query, offset)
: text_view.find_code_unit_offset(utf16_query, offset);
if (!match_index.has_value())
break;
@ -6181,15 +6180,15 @@ Vector<GC::Root<Range>> Document::find_matching_text(String const& query, CaseSe
auto& start_dom_node = match_start_position->dom_node;
auto* match_end_position = match_start_position;
for (; i < text_block.positions.size() - 1 && (match_index.value() + query_view.length_in_code_units() > text_block.positions[i + 1].start_offset); ++i)
for (; i < text_block.positions.size() - 1 && (match_index.value() + utf16_query.length_in_code_units() > text_block.positions[i + 1].start_offset); ++i)
match_end_position = &text_block.positions[i + 1];
auto& end_dom_node = match_end_position->dom_node;
auto end_position = match_index.value() + query_view.length_in_code_units() - match_end_position->start_offset;
auto end_position = match_index.value() + utf16_query.length_in_code_units() - match_end_position->start_offset;
matches.append(Range::create(start_dom_node, start_position, end_dom_node, end_position));
match_start_position = match_end_position;
offset = match_index.value() + query_view.length_in_code_units() + 1;
offset = match_index.value() + utf16_query.length_in_code_units() + 1;
if (offset >= text_view.length_in_code_units())
break;
}