mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:07:34 +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
|
@ -26,19 +26,19 @@ static ErrorOr<ApprovalDate> parse_approval_date(StringView date)
|
|||
if (parts.size() != 3)
|
||||
return Error::from_string_literal("Failed to parse approval date parts (mm/dd/yyyy)");
|
||||
|
||||
auto month = parts[0].to_uint();
|
||||
auto month = parts[0].to_number<unsigned>();
|
||||
if (!month.has_value())
|
||||
return Error::from_string_literal("Failed to parse month from approval date");
|
||||
if (month.value() == 0 || month.value() > 12)
|
||||
return Error::from_string_literal("Invalid month in approval date");
|
||||
|
||||
auto day = parts[1].to_uint();
|
||||
auto day = parts[1].to_number<unsigned>();
|
||||
if (!day.has_value())
|
||||
return Error::from_string_literal("Failed to parse day from approval date");
|
||||
if (day.value() == 0 || day.value() > 31)
|
||||
return Error::from_string_literal("Invalid day in approval date");
|
||||
|
||||
auto year = parts[2].to_uint();
|
||||
auto year = parts[2].to_number<unsigned>();
|
||||
if (!year.has_value())
|
||||
return Error::from_string_literal("Failed to parse year from approval date");
|
||||
if (year.value() < 1900 || year.value() > 2999)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue