mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 08:48:57 +00:00
LibWeb: Clean up Range::to_string()
No functional changes.
This commit is contained in:
parent
75d41859fd
commit
12cec1bdb3
Notes:
github-actions[bot]
2025-09-12 19:35:42 +00:00
Author: https://github.com/gmta
Commit: 12cec1bdb3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6169
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/trflynn89
1 changed files with 10 additions and 15 deletions
|
@ -556,29 +556,24 @@ Utf16String Range::to_string() const
|
||||||
|
|
||||||
// 2. If this’s start node is this’s end node and it is a Text node,
|
// 2. If this’s start node is this’s end node and it is a Text node,
|
||||||
// then return the substring of that Text node’s data beginning at this’s start offset and ending at this’s end offset.
|
// then return the substring of that Text node’s data beginning at this’s start offset and ending at this’s 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 this’s start node is a Text node, then append the substring of that node’s data from this’s start offset until the end to s.
|
// 3. If this’s start node is a Text node, then append the substring of that node’s data from this’s 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 this’s end node is a Text node, then append the substring of that node’s data from its start until this’s end offset to s.
|
// 5. If this’s end node is a Text node, then append the substring of that node’s data from its start until this’s 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();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue