LibWeb: Clean up Range::to_string()

No functional changes.
This commit is contained in:
Jelle Raaijmakers 2025-09-04 14:10:18 +02:00 committed by Tim Flynn
commit 12cec1bdb3
Notes: github-actions[bot] 2025-09-12 19:35:42 +00:00

View file

@ -556,29 +556,24 @@ Utf16String Range::to_string() const
// 2. If thiss start node is thiss end node and it is a Text node, // 2. If thiss start node is thiss end node and it is a Text node,
// then return the substring of that Text nodes data beginning at thiss start offset and ending at thiss end offset. // then return the substring of that Text nodes data beginning at thiss start offset and ending at thiss end offset.
if (start_container() == end_container() && is<Text>(*start_container())) { auto* start_text = as_if<Text>(*start_container());
auto const& text = static_cast<Text const&>(*start_container()); if (start_text && start_container() == end_container())
return MUST(text.substring_data(start_offset(), end_offset() - start_offset())); return MUST(start_text->substring_data(start_offset(), end_offset() - start_offset()));
}
// 3. If thiss start node is a Text node, then append the substring of that nodes data from thiss start offset until the end to s. // 3. If thiss start node is a Text node, then append the substring of that nodes data from thiss start offset until the end to s.
if (is<Text>(*start_container())) { if (start_text)
auto const& text = static_cast<Text const&>(*start_container()); builder.append(MUST(start_text->substring_data(start_offset(), start_text->length_in_utf16_code_units() - start_offset())));
builder.append(MUST(text.substring_data(start_offset(), text.length_in_utf16_code_units() - start_offset())));
}
// 4. Append the concatenation of the data of all Text nodes that are contained in this, in tree order, to s. // 4. Append the concatenation of the data of all Text nodes that are contained in this, in tree order, to s.
for_each_contained([&](GC::Ref<DOM::Node> node) { for_each_contained([&](GC::Ref<Node> node) {
if (is<Text>(*node)) if (auto* text_node = as_if<Text>(*node))
builder.append(static_cast<Text const&>(*node).data()); builder.append(text_node->data());
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
// 5. If thiss end node is a Text node, then append the substring of that nodes data from its start until thiss end offset to s. // 5. If thiss end node is a Text node, then append the substring of that nodes data from its start until thiss end offset to s.
if (is<Text>(*end_container())) { if (auto* end_text = as_if<Text>(*end_container()))
auto const& text = static_cast<Text const&>(*end_container()); builder.append(MUST(end_text->substring_data(0, end_offset())));
builder.append(MUST(text.substring_data(0, end_offset())));
}
// 6. Return s. // 6. Return s.
return builder.to_utf16_string(); return builder.to_utf16_string();