mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +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
|
@ -133,7 +133,7 @@ public:
|
|||
arg = arg.substring_view(1);
|
||||
}
|
||||
|
||||
auto maybe_value = arg.to_uint<T>();
|
||||
auto maybe_value = arg.to_number<T>();
|
||||
if (!maybe_value.has_value())
|
||||
return Error::from_errno(EINVAL);
|
||||
|
||||
|
@ -192,7 +192,7 @@ public:
|
|||
MaxDepthCommand(char const* arg)
|
||||
{
|
||||
auto max_depth_string = StringView { arg, strlen(arg) };
|
||||
auto maybe_max_depth = max_depth_string.to_uint<u32>();
|
||||
auto maybe_max_depth = max_depth_string.to_number<u32>();
|
||||
if (!maybe_max_depth.has_value())
|
||||
fatal_error("-maxdepth: '{}' is not a valid non-negative integer", arg);
|
||||
|
||||
|
@ -210,7 +210,7 @@ public:
|
|||
MinDepthCommand(char const* arg)
|
||||
{
|
||||
auto min_depth_string = StringView { arg, strlen(arg) };
|
||||
auto maybe_min_depth = min_depth_string.to_uint<u32>();
|
||||
auto maybe_min_depth = min_depth_string.to_number<u32>();
|
||||
if (!maybe_min_depth.has_value())
|
||||
fatal_error("-mindepth: '{}' is not a valid non-negative integer", arg);
|
||||
|
||||
|
@ -296,7 +296,7 @@ public:
|
|||
m_uid = passwd->pw_uid;
|
||||
} else {
|
||||
// Attempt to parse it as decimal UID.
|
||||
auto number = StringView { arg, strlen(arg) }.to_uint<uid_t>();
|
||||
auto number = StringView { arg, strlen(arg) }.to_number<uid_t>();
|
||||
if (!number.has_value())
|
||||
fatal_error("Invalid user: \033[1m{}", arg);
|
||||
m_uid = number.value();
|
||||
|
@ -320,7 +320,7 @@ public:
|
|||
m_gid = gr->gr_gid;
|
||||
} else {
|
||||
// Attempt to parse it as decimal GID.
|
||||
auto number = StringView { arg, strlen(arg) }.to_uint<gid_t>();
|
||||
auto number = StringView { arg, strlen(arg) }.to_number<gid_t>();
|
||||
if (!number.has_value())
|
||||
fatal_error("Invalid group: \033[1m{}", arg);
|
||||
m_gid = number.value();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue