mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +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
Notes:
sideshowbarker
2024-07-18 19:18:07 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/ec67b1ac32d Pull-request: https://github.com/SerenityOS/serenity/pull/6534 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
|
@ -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…
Reference in a new issue