mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-16 22:42:18 +00:00
LibWeb: Move CSS unicode-ranges parsing code into a common helper
This commit is contained in:
parent
5f6495fb29
commit
de98c122d1
Notes:
sideshowbarker
2024-07-16 23:34:44 +09:00
Author: https://github.com/ADKaster
Commit: de98c122d1
Pull-request: https://github.com/SerenityOS/serenity/pull/24278
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/kalenikaliaksandr
2 changed files with 20 additions and 16 deletions
|
@ -2137,6 +2137,22 @@ Optional<Gfx::UnicodeRange> Parser::parse_unicode_range(StringView text)
|
||||||
return make_valid_unicode_range(start_value, end_value);
|
return make_valid_unicode_range(start_value, end_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<Gfx::UnicodeRange> Parser::parse_unicode_ranges(TokenStream<ComponentValue>& tokens)
|
||||||
|
{
|
||||||
|
Vector<Gfx::UnicodeRange> unicode_ranges;
|
||||||
|
auto range_token_lists = parse_a_comma_separated_list_of_component_values(tokens);
|
||||||
|
for (auto& range_tokens : range_token_lists) {
|
||||||
|
TokenStream range_token_stream { range_tokens };
|
||||||
|
auto maybe_unicode_range = parse_unicode_range(range_token_stream);
|
||||||
|
if (!maybe_unicode_range.has_value()) {
|
||||||
|
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: unicode-range format invalid; discarding.");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
unicode_ranges.append(maybe_unicode_range.release_value());
|
||||||
|
}
|
||||||
|
return unicode_ranges;
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_dimension_value(TokenStream<ComponentValue>& tokens)
|
RefPtr<StyleValue> Parser::parse_dimension_value(TokenStream<ComponentValue>& tokens)
|
||||||
{
|
{
|
||||||
auto dimension = parse_dimension(tokens.peek_token());
|
auto dimension = parse_dimension(tokens.peek_token());
|
||||||
|
@ -4526,22 +4542,9 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (declaration.name().equals_ignoring_ascii_case("unicode-range"sv)) {
|
if (declaration.name().equals_ignoring_ascii_case("unicode-range"sv)) {
|
||||||
Vector<Gfx::UnicodeRange> unicode_ranges;
|
TokenStream token_stream { declaration.values() };
|
||||||
bool unicode_range_invalid = false;
|
auto unicode_ranges = parse_unicode_ranges(token_stream);
|
||||||
TokenStream all_tokens { declaration.values() };
|
if (unicode_ranges.is_empty())
|
||||||
auto range_token_lists = parse_a_comma_separated_list_of_component_values(all_tokens);
|
|
||||||
for (auto& range_tokens : range_token_lists) {
|
|
||||||
TokenStream range_token_stream { range_tokens };
|
|
||||||
auto maybe_unicode_range = parse_unicode_range(range_token_stream);
|
|
||||||
if (!maybe_unicode_range.has_value()) {
|
|
||||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face unicode-range format invalid; discarding.");
|
|
||||||
unicode_range_invalid = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
unicode_ranges.append(maybe_unicode_range.release_value());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unicode_range_invalid || unicode_ranges.is_empty())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
unicode_range = move(unicode_ranges);
|
unicode_range = move(unicode_ranges);
|
||||||
|
|
|
@ -190,6 +190,7 @@ private:
|
||||||
Optional<Ratio> parse_ratio(TokenStream<ComponentValue>&);
|
Optional<Ratio> parse_ratio(TokenStream<ComponentValue>&);
|
||||||
Optional<Gfx::UnicodeRange> parse_unicode_range(TokenStream<ComponentValue>&);
|
Optional<Gfx::UnicodeRange> parse_unicode_range(TokenStream<ComponentValue>&);
|
||||||
Optional<Gfx::UnicodeRange> parse_unicode_range(StringView);
|
Optional<Gfx::UnicodeRange> parse_unicode_range(StringView);
|
||||||
|
Vector<Gfx::UnicodeRange> parse_unicode_ranges(TokenStream<ComponentValue>&);
|
||||||
Optional<GridSize> parse_grid_size(ComponentValue const&);
|
Optional<GridSize> parse_grid_size(ComponentValue const&);
|
||||||
Optional<GridMinMax> parse_min_max(Vector<ComponentValue> const&);
|
Optional<GridMinMax> parse_min_max(Vector<ComponentValue> const&);
|
||||||
Optional<GridRepeat> parse_repeat(Vector<ComponentValue> const&);
|
Optional<GridRepeat> parse_repeat(Vector<ComponentValue> const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue