mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 01:05:08 +00:00
LibWeb: Add basic parse floating point number function
This commit is contained in:
parent
3175557cb8
commit
761d824b72
5 changed files with 42 additions and 32 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <AK/GenericLexer.h>
|
||||
#include <LibWeb/HTML/Numbers.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -79,4 +80,16 @@ Optional<u32> parse_non_negative_integer(StringView string)
|
|||
return static_cast<u32>(optional_value.value());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values
|
||||
Optional<double> parse_floating_point_number(StringView string)
|
||||
{
|
||||
// FIXME: Implement spec compliant floating point number parsing
|
||||
auto maybe_double = MUST(String::from_utf8(string)).to_number<double>(TrimWhitespace::Yes);
|
||||
if (!maybe_double.has_value())
|
||||
return {};
|
||||
if (!isfinite(maybe_double.value()))
|
||||
return {};
|
||||
return maybe_double.value();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue