diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-02-22 12:10:48 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-24 08:04:25 +0100 |
commit | f76a54181988d2d5213424061e8ef79e54659404 (patch) | |
tree | e35b62a1c551ea94e7abf0aa669920a0f83819cd /Userland/Libraries/LibWeb/CSS/Parser | |
parent | 608bfac2a9dfa5f54a4584f044de2fa6eb2aaec2 (diff) | |
download | serenity-f76a54181988d2d5213424061e8ef79e54659404.zip |
LibWeb: Move length-unit-from-string code into Length
This means the units are defined in a single place instead of two.
Also removed the verify that we didn't produce a bogus % dimension token
in the Tokenizer, since this has never happened and the parser is not a
tokenizer test suite. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/Parser')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 16a943f7c0..a7653f18b9 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2165,45 +2165,9 @@ Optional<Parser::Dimension> Parser::parse_dimension(StyleComponentValueRule cons if (component_value.is(Token::Type::Dimension)) { float numeric_value = component_value.token().dimension_value(); auto unit_string = component_value.token().dimension_unit(); - Optional<Length::Type> length_type; - - if (unit_string.equals_ignoring_case("px"sv)) { - length_type = Length::Type::Px; - } else if (unit_string.equals_ignoring_case("pt"sv)) { - length_type = Length::Type::Pt; - } else if (unit_string.equals_ignoring_case("pc"sv)) { - length_type = Length::Type::Pc; - } else if (unit_string.equals_ignoring_case("mm"sv)) { - length_type = Length::Type::Mm; - } else if (unit_string.equals_ignoring_case("rem"sv)) { - length_type = Length::Type::Rem; - } else if (unit_string.equals_ignoring_case("em"sv)) { - length_type = Length::Type::Em; - } else if (unit_string.equals_ignoring_case("ex"sv)) { - length_type = Length::Type::Ex; - } else if (unit_string.equals_ignoring_case("ch"sv)) { - length_type = Length::Type::Ch; - } else if (unit_string.equals_ignoring_case("vw"sv)) { - length_type = Length::Type::Vw; - } else if (unit_string.equals_ignoring_case("vh"sv)) { - length_type = Length::Type::Vh; - } else if (unit_string.equals_ignoring_case("vmax"sv)) { - length_type = Length::Type::Vmax; - } else if (unit_string.equals_ignoring_case("vmin"sv)) { - length_type = Length::Type::Vmin; - } else if (unit_string.equals_ignoring_case("cm"sv)) { - length_type = Length::Type::Cm; - } else if (unit_string.equals_ignoring_case("in"sv)) { - length_type = Length::Type::In; - } else if (unit_string.equals_ignoring_case("Q"sv)) { - length_type = Length::Type::Q; - } else if (unit_string.equals_ignoring_case("%"sv)) { - // A number followed by `%` must always result in a Percentage token. - VERIFY_NOT_REACHED(); - } - if (length_type.has_value()) - return Length { numeric_value, length_type.value() }; + if (auto length_type = Length::unit_from_name(unit_string); length_type.has_value()) + return Length { numeric_value, length_type.release_value() }; } if (component_value.is(Token::Type::Percentage)) |