From ec67b1ac32d9796a3198febc67f9526333011696 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 21 Apr 2021 16:03:01 +0300 Subject: [PATCH] LibWeb: Implement scientific notation parsing in PathDataParser This was required by webkit.org and is based on the following spec: https://svgwg.org/svg2-draft/paths.html#PathDataBNF --- .../Libraries/LibWeb/SVG/SVGPathElement.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index d97bc13852..82ebfda45d 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -390,8 +390,34 @@ float PathDataParser::parse_fractional_constant() float PathDataParser::parse_number() { auto number = parse_fractional_constant(); - if (match('e') || match('E')) - TODO(); + + if (!match('e') && !match('E')) + return number; + consume(); + + auto exponent_sign = parse_sign(); + + StringBuilder exponent_builder; + while (!done() && isdigit(ch())) + exponent_builder.append(consume()); + VERIFY(exponent_builder.length() > 0); + + auto exponent = exponent_builder.to_string().to_int().value(); + + // Fast path: If the number is 0, there's no point in computing the exponentiation. + if (number == 0) + return number; + + if (exponent_sign < 0) { + for (int i = 0; i < exponent; ++i) { + number /= 10; + } + } else if (exponent_sign > 0) { + for (int i = 0; i < exponent; ++i) { + number *= 10; + } + } + return number; }