mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
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
This commit is contained in:
parent
8bb4409a5d
commit
ec67b1ac32
1 changed files with 28 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue