mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:37: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
|
@ -500,11 +500,7 @@ void ArgsParser::add_option(I& value, char const* help_string, char const* long_
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView view) -> ErrorOr<bool> {
|
||||
Optional<I> opt;
|
||||
if constexpr (IsSigned<I>)
|
||||
opt = view.to_int<I>();
|
||||
else
|
||||
opt = view.to_uint<I>();
|
||||
Optional<I> opt = view.to_number<I>();
|
||||
value = opt.value_or(0);
|
||||
return opt.has_value();
|
||||
},
|
||||
|
@ -530,7 +526,7 @@ void ArgsParser::add_option(double& value, char const* help_string, char const*
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
auto opt = s.to_double();
|
||||
auto opt = s.to_number<double>();
|
||||
value = opt.value_or(0.0);
|
||||
return opt.has_value();
|
||||
},
|
||||
|
@ -548,7 +544,7 @@ void ArgsParser::add_option(Optional<double>& value, char const* help_string, ch
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
value = s.to_double();
|
||||
value = s.to_number<double>();
|
||||
return value.has_value();
|
||||
},
|
||||
hide_mode,
|
||||
|
@ -565,7 +561,7 @@ void ArgsParser::add_option(Optional<size_t>& value, char const* help_string, ch
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
value = AK::StringUtils::convert_to_uint<size_t>(s);
|
||||
value = s.to_number<size_t>();
|
||||
return value.has_value();
|
||||
},
|
||||
hide_mode,
|
||||
|
@ -676,11 +672,7 @@ void ArgsParser::add_positional_argument(I& value, char const* help_string, char
|
|||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](StringView view) -> ErrorOr<bool> {
|
||||
Optional<I> opt;
|
||||
if constexpr (IsSigned<I>)
|
||||
opt = view.to_int<I>();
|
||||
else
|
||||
opt = view.to_uint<I>();
|
||||
Optional<I> opt = view.to_number<I>();
|
||||
value = opt.value_or(0);
|
||||
return opt.has_value();
|
||||
},
|
||||
|
@ -705,7 +697,7 @@ void ArgsParser::add_positional_argument(double& value, char const* help_string,
|
|||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
auto opt = s.to_double();
|
||||
auto opt = s.to_number<double>();
|
||||
value = opt.value_or(0.0);
|
||||
return opt.has_value();
|
||||
}
|
||||
|
|
|
@ -55,10 +55,7 @@ public:
|
|||
if (!has_key(group, key))
|
||||
return default_value;
|
||||
|
||||
if constexpr (IsSigned<T>)
|
||||
return read_entry(group, key, "").to_int<T>().value_or(default_value);
|
||||
else
|
||||
return read_entry(group, key, "").to_uint<T>().value_or(default_value);
|
||||
return read_entry(group, key, "").to_number<T>().value_or(default_value);
|
||||
}
|
||||
|
||||
void write_entry(ByteString const& group, ByteString const& key, ByteString const& value);
|
||||
|
|
|
@ -209,7 +209,7 @@ ErrorOr<bool> Process::is_being_debugged()
|
|||
auto const parts = line.split_view(':');
|
||||
if (parts.size() < 2 || parts[0] != "TracerPid"sv)
|
||||
continue;
|
||||
auto tracer_pid = parts[1].to_uint<u32>();
|
||||
auto tracer_pid = parts[1].to_number<u32>();
|
||||
return (tracer_pid != 0UL);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -27,7 +27,7 @@ static void parse_sockets_from_system_server()
|
|||
for (auto const socket : StringView { sockets, strlen(sockets) }.split_view(';')) {
|
||||
auto params = socket.split_view(':');
|
||||
VERIFY(params.size() == 2);
|
||||
s_overtaken_sockets.set(params[0].to_byte_string(), params[1].to_int().value());
|
||||
s_overtaken_sockets.set(params[0].to_byte_string(), params[1].to_number<int>().value());
|
||||
}
|
||||
|
||||
s_overtaken_sockets_parsed = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue