mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 01:29:17 +00:00
LibWeb: Support multiple values in :lang()
selector
Parse them, and also don't give up completely if the first language listed doesn't match an element.
This commit is contained in:
parent
39cba61c2d
commit
12a2750d1e
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/AtkinsSJ
Commit: 12a2750d1e
Pull-request: https://github.com/SerenityOS/serenity/pull/20596
5 changed files with 63 additions and 7 deletions
|
@ -44,13 +44,14 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector
|
|||
// FIXME: This is ad-hoc. Implement a proper language range matching algorithm as recommended by BCP47.
|
||||
for (auto const& language : languages) {
|
||||
if (language.is_empty())
|
||||
return false;
|
||||
continue;
|
||||
if (language == "*"sv)
|
||||
return true;
|
||||
if (!element_language.to_string().contains('-'))
|
||||
return Infra::is_ascii_case_insensitive_match(element_language, language);
|
||||
if (!element_language.to_string().contains('-') && Infra::is_ascii_case_insensitive_match(element_language, language))
|
||||
return true;
|
||||
auto parts = element_language.to_string().split_limit('-', 2).release_value_but_fixme_should_propagate_errors();
|
||||
return Infra::is_ascii_case_insensitive_match(parts[0], language);
|
||||
if (Infra::is_ascii_case_insensitive_match(parts[0], language))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue