1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

Everywhere: Use to_number<T> instead of to_{int,uint,float,double}

In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
This commit is contained in:
Shannon Booth 2023-12-23 15:59:14 +13:00 committed by Andreas Kling
parent a4ecc65398
commit e2e7c4d574
155 changed files with 397 additions and 412 deletions

View file

@ -647,7 +647,7 @@ Vector<PatternPartition> partition_number_pattern(VM& vm, NumberFormat& number_f
else if ((part.starts_with("unitIdentifier:"sv)) && (number_format.style() == NumberFormat::Style::Unit)) {
// Note: Our implementation combines "unitPrefix" and "unitSuffix" into one field, "unitIdentifier".
auto identifier_index = part.substring_view("unitIdentifier:"sv.length()).to_uint();
auto identifier_index = part.substring_view("unitIdentifier:"sv.length()).to_number<unsigned>();
VERIFY(identifier_index.has_value());
// i. Let unit be numberFormat.[[Unit]].
@ -862,7 +862,7 @@ Vector<PatternPartition> partition_notation_sub_pattern(NumberFormat& number_for
else if (part.starts_with("compactIdentifier:"sv)) {
// Note: Our implementation combines "compactSymbol" and "compactName" into one field, "compactIdentifier".
auto identifier_index = part.substring_view("compactIdentifier:"sv.length()).to_uint();
auto identifier_index = part.substring_view("compactIdentifier:"sv.length()).to_number<unsigned>();
VERIFY(identifier_index.has_value());
// 1. Let compactSymbol be an ILD string representing exponent in short form, which may depend on x in languages having different plural forms. The implementation must be able to provide this string, or else the pattern would not have a "{compactSymbol}" placeholder.
@ -1034,7 +1034,7 @@ static RawPrecisionResult to_raw_precision_function(MathematicalValue const& num
result.number = result.number.divided_by(10);
if (mode == PreferredResult::GreaterThanNumber && digit.to_uint().value() != 0)
if (mode == PreferredResult::GreaterThanNumber && digit.to_number<unsigned>().value() != 0)
result.number = result.number.plus(1);
}
@ -1183,7 +1183,7 @@ static RawFixedResult to_raw_fixed_function(MathematicalValue const& number, int
result.number = result.number.multiplied_by(10);
if (mode == PreferredResult::GreaterThanNumber && digit.to_uint().value() != 0)
if (mode == PreferredResult::GreaterThanNumber && digit.to_number<unsigned>().value() != 0)
result.number = result.number.plus(1);
}