1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

AK+Everywhere: Replace URL::paths() with path_segment_at_index()

This allows accessing and looping over the path segments in a URL
without necessarily allocating a new vector if you want them percent
decoded too (which path_segment_at_index() has an option for).
This commit is contained in:
MacDue 2023-04-13 23:29:51 +01:00 committed by Andreas Kling
parent 35612c6a7f
commit 5db1eb9961
Notes: sideshowbarker 2024-07-16 21:23:42 +09:00
6 changed files with 28 additions and 21 deletions

View file

@ -70,11 +70,10 @@ ErrorOr<NonnullRefPtr<Node const>> Node::try_find_from_help_url(URL const& url)
{
if (url.host() != "man")
return Error::from_string_view("Bad help operation"sv);
if (url.paths().size() < 2)
if (url.path_segment_count() < 2)
return Error::from_string_view("Bad help page URL"sv);
auto paths = url.paths();
auto const section = paths.take_first();
auto const section = url.path_segment_at_index(0);
auto maybe_section_number = section.to_uint();
if (!maybe_section_number.has_value())
return Error::from_string_view("Bad section number"sv);
@ -84,16 +83,16 @@ ErrorOr<NonnullRefPtr<Node const>> Node::try_find_from_help_url(URL const& url)
NonnullRefPtr<Node const> current_node = sections[section_number - 1];
while (!paths.is_empty()) {
auto next_path_segment = TRY(String::from_deprecated_string(paths.take_first()));
for (size_t i = 1; i < url.path_segment_count(); i++) {
auto children = TRY(current_node->children());
for (auto const& child : children) {
if (TRY(child->name()) == next_path_segment) {
if (TRY(child->name()) == url.path_segment_at_index(i).view()) {
current_node = child;
break;
}
}
}
return current_node;
}