Skip to content

Commit 0259804

Browse files
gmtatcl3
authored andcommitted
LibWeb: Add CSS::Parser::parse_dashed_ident()
1 parent ae3bda9 commit 0259804

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Libraries/LibWeb/CSS/Parser/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ class Parser {
354354
RefPtr<CSSStyleValue const> parse_calculated_value(ComponentValue const&);
355355
Optional<FlyString> parse_custom_ident(TokenStream<ComponentValue>&, ReadonlySpan<StringView> blacklist);
356356
RefPtr<CustomIdentStyleValue const> parse_custom_ident_value(TokenStream<ComponentValue>&, ReadonlySpan<StringView> blacklist);
357+
Optional<FlyString> parse_dashed_ident(TokenStream<ComponentValue>&);
357358
// NOTE: Implemented in generated code. (GenerateCSSMathFunctions.cpp)
358359
RefPtr<CalculationNode const> parse_math_function(Function const&, CalculationContext const&);
359360
RefPtr<CalculationNode const> parse_a_calc_function_node(Function const&, CalculationContext const&);

Libraries/LibWeb/CSS/Parser/ValueParsing.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,6 +3307,19 @@ RefPtr<CustomIdentStyleValue const> Parser::parse_custom_ident_value(TokenStream
33073307
return nullptr;
33083308
}
33093309

3310+
// https://drafts.csswg.org/css-values-4/#typedef-dashed-ident
3311+
Optional<FlyString> Parser::parse_dashed_ident(TokenStream<ComponentValue>& tokens)
3312+
{
3313+
// The <dashed-ident> production is a <custom-ident>, with all the case-sensitivity that implies, with the
3314+
// additional restriction that it must start with two dashes (U+002D HYPHEN-MINUS).
3315+
auto transaction = tokens.begin_transaction();
3316+
auto custom_ident = parse_custom_ident(tokens, {});
3317+
if (!custom_ident.has_value() || !custom_ident->starts_with_bytes("--"sv))
3318+
return {};
3319+
transaction.commit();
3320+
return custom_ident;
3321+
}
3322+
33103323
// https://www.w3.org/TR/css-grid-2/#typedef-track-breadth
33113324
Optional<GridSize> Parser::parse_grid_track_breadth(TokenStream<ComponentValue>& tokens)
33123325
{

0 commit comments

Comments
 (0)