mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-16 16:12:53 +00:00
AK: Add an AK::find
helper to return a reference to the found value
This is often more convenient than dealing with iterators. This commit includes a couple conversions to find_value as examples.
This commit is contained in:
parent
9cab5dc0c9
commit
7f37a8f60f
Notes:
github-actions[bot]
2025-04-06 11:46:22 +00:00
Author: https://github.com/trflynn89
Commit: 7f37a8f60f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4237
5 changed files with 34 additions and 30 deletions
|
@ -30,28 +30,16 @@ ReadonlySpan<SearchEngine> search_engines()
|
|||
|
||||
Optional<SearchEngine const&> find_search_engine_by_name(StringView name)
|
||||
{
|
||||
auto it = AK::find_if(builtin_search_engines.begin(), builtin_search_engines.end(),
|
||||
[&](auto const& engine) {
|
||||
return engine.name == name;
|
||||
});
|
||||
|
||||
if (it == builtin_search_engines.end())
|
||||
return {};
|
||||
|
||||
return *it;
|
||||
return find_value(builtin_search_engines, [&](auto const& engine) {
|
||||
return engine.name == name;
|
||||
});
|
||||
}
|
||||
|
||||
Optional<SearchEngine const&> find_search_engine_by_query_url(StringView query_url)
|
||||
{
|
||||
auto it = AK::find_if(builtin_search_engines.begin(), builtin_search_engines.end(),
|
||||
[&](auto const& engine) {
|
||||
return engine.query_url == query_url;
|
||||
});
|
||||
|
||||
if (it == builtin_search_engines.end())
|
||||
return {};
|
||||
|
||||
return *it;
|
||||
return find_value(builtin_search_engines, [&](auto const& engine) {
|
||||
return engine.query_url == query_url;
|
||||
});
|
||||
}
|
||||
|
||||
String format_search_query_for_display(StringView query_url, StringView query)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue