mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +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:
parent
a4ecc65398
commit
e2e7c4d574
155 changed files with 397 additions and 412 deletions
|
@ -1276,22 +1276,22 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
|
|||
// a. Let monthMV be 1.
|
||||
// 9. Else,
|
||||
// a. Let monthMV be ! ToIntegerOrInfinity(CodePointsToString(month)).
|
||||
auto month_mv = *month.value_or("1"sv).to_uint<u8>();
|
||||
auto month_mv = *month.value_or("1"sv).to_number<u8>();
|
||||
|
||||
// 10. If day is empty, then
|
||||
// a. Let dayMV be 1.
|
||||
// 11. Else,
|
||||
// a. Let dayMV be ! ToIntegerOrInfinity(CodePointsToString(day)).
|
||||
auto day_mv = *day.value_or("1"sv).to_uint<u8>();
|
||||
auto day_mv = *day.value_or("1"sv).to_number<u8>();
|
||||
|
||||
// 12. Let hourMV be ! ToIntegerOrInfinity(CodePointsToString(hour)).
|
||||
auto hour_mv = *hour.value_or("0"sv).to_uint<u8>();
|
||||
auto hour_mv = *hour.value_or("0"sv).to_number<u8>();
|
||||
|
||||
// 13. Let minuteMV be ! ToIntegerOrInfinity(CodePointsToString(minute)).
|
||||
auto minute_mv = *minute.value_or("0"sv).to_uint<u8>();
|
||||
auto minute_mv = *minute.value_or("0"sv).to_number<u8>();
|
||||
|
||||
// 14. Let secondMV be ! ToIntegerOrInfinity(CodePointsToString(second)).
|
||||
auto second_mv = *second.value_or("0"sv).to_uint<u8>();
|
||||
auto second_mv = *second.value_or("0"sv).to_number<u8>();
|
||||
|
||||
// 15. If secondMV is 60, then
|
||||
if (second_mv == 60) {
|
||||
|
@ -1532,19 +1532,19 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_seconds_part = parse_result->duration_seconds_fraction;
|
||||
|
||||
// 4. Let yearsMV be ! ToIntegerOrInfinity(CodePointsToString(years)).
|
||||
auto years = years_part.value_or("0"sv).to_double().release_value();
|
||||
auto years = years_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 5. Let monthsMV be ! ToIntegerOrInfinity(CodePointsToString(months)).
|
||||
auto months = months_part.value_or("0"sv).to_double().release_value();
|
||||
auto months = months_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 6. Let weeksMV be ! ToIntegerOrInfinity(CodePointsToString(weeks)).
|
||||
auto weeks = weeks_part.value_or("0"sv).to_double().release_value();
|
||||
auto weeks = weeks_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 7. Let daysMV be ! ToIntegerOrInfinity(CodePointsToString(days)).
|
||||
auto days = days_part.value_or("0"sv).to_double().release_value();
|
||||
auto days = days_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 8. Let hoursMV be ! ToIntegerOrInfinity(CodePointsToString(hours)).
|
||||
auto hours = hours_part.value_or("0"sv).to_double().release_value();
|
||||
auto hours = hours_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
double minutes;
|
||||
|
||||
|
@ -1561,12 +1561,12 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_hours_scale = (double)f_hours_digits.length();
|
||||
|
||||
// d. Let minutesMV be ! ToIntegerOrInfinity(fHoursDigits) / 10^fHoursScale × 60.
|
||||
minutes = f_hours_digits.to_double().release_value() / pow(10., f_hours_scale) * 60;
|
||||
minutes = f_hours_digits.to_number<double>().release_value() / pow(10., f_hours_scale) * 60;
|
||||
}
|
||||
// 10. Else,
|
||||
else {
|
||||
// a. Let minutesMV be ! ToIntegerOrInfinity(CodePointsToString(minutes)).
|
||||
minutes = minutes_part.value_or("0"sv).to_double().release_value();
|
||||
minutes = minutes_part.value_or("0"sv).to_number<double>().release_value();
|
||||
}
|
||||
|
||||
double seconds;
|
||||
|
@ -1584,12 +1584,12 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_minutes_scale = (double)f_minutes_digits.length();
|
||||
|
||||
// d. Let secondsMV be ! ToIntegerOrInfinity(fMinutesDigits) / 10^fMinutesScale × 60.
|
||||
seconds = f_minutes_digits.to_double().release_value() / pow(10, f_minutes_scale) * 60;
|
||||
seconds = f_minutes_digits.to_number<double>().release_value() / pow(10, f_minutes_scale) * 60;
|
||||
}
|
||||
// 12. Else if seconds is not empty, then
|
||||
else if (seconds_part.has_value()) {
|
||||
// a. Let secondsMV be ! ToIntegerOrInfinity(CodePointsToString(seconds)).
|
||||
seconds = seconds_part.value_or("0"sv).to_double().release_value();
|
||||
seconds = seconds_part.value_or("0"sv).to_number<double>().release_value();
|
||||
}
|
||||
// 13. Else,
|
||||
else {
|
||||
|
@ -1608,7 +1608,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_seconds_scale = (double)f_seconds_digits.length();
|
||||
|
||||
// c. Let millisecondsMV be ! ToIntegerOrInfinity(fSecondsDigits) / 10^fSecondsScale × 1000.
|
||||
milliseconds = f_seconds_digits.to_double().release_value() / pow(10, f_seconds_scale) * 1000;
|
||||
milliseconds = f_seconds_digits.to_number<double>().release_value() / pow(10, f_seconds_scale) * 1000;
|
||||
}
|
||||
// 15. Else,
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue