1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00

LibWeb: Implement spec-compliant integer parsing

We have code inside LibWeb that uses the
`AK::StringUtils::convert_to_uint`and `AK::StringUtils::convert_to_int`
methods for parsing integers. This works well for the most part, but
according to the spec, trailing characters are allowed and should be
ignored, but this is not how the `StringUtil` methods are implemented.

This patch adds two new methods named `parse_integer` and
`parse_non_negative_integer` inside the `Web::HTML` namespace that uses
`StringUtils` under the hood but adds a bit more logic to make it spec
compliant.
This commit is contained in:
Jonatan Klemets 2023-07-23 19:38:04 +03:00 committed by Sam Atkins
parent ebc5b33b77
commit 9812031a02
5 changed files with 208 additions and 0 deletions

View file

@ -0,0 +1,18 @@
/*
* Copyright (c) 2023, Jonatan Klemets <jonatan.r.klemets@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/String.h>
namespace Web::HTML {
Optional<i32> parse_integer(StringView string);
Optional<u32> parse_non_negative_integer(StringView string);
}