mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:17:46 +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
|
@ -298,14 +298,14 @@ Result<void, int> apply_modes(size_t parameter_count, char** raw_parameters, ter
|
|||
parameters.append(StringView { raw_parameters[i], strlen(raw_parameters[i]) });
|
||||
|
||||
auto parse_baud = [&](size_t idx) -> Optional<speed_t> {
|
||||
auto maybe_numeric_value = parameters[idx].to_uint<uint32_t>();
|
||||
auto maybe_numeric_value = parameters[idx].to_number<uint32_t>();
|
||||
if (maybe_numeric_value.has_value())
|
||||
return numeric_value_to_speed(maybe_numeric_value.value());
|
||||
return {};
|
||||
};
|
||||
|
||||
auto parse_number = [&](size_t idx) -> Optional<cc_t> {
|
||||
return parameters[idx].to_uint<cc_t>();
|
||||
return parameters[idx].to_number<cc_t>();
|
||||
};
|
||||
|
||||
auto looks_like_stty_readable = [&](size_t idx) {
|
||||
|
@ -355,7 +355,7 @@ Result<void, int> apply_modes(size_t parameter_count, char** raw_parameters, ter
|
|||
}
|
||||
return value;
|
||||
} else if (is_ascii_digit(parameters[idx][0])) {
|
||||
auto maybe_value = parameters[idx].to_uint<cc_t>();
|
||||
auto maybe_value = parameters[idx].to_number<cc_t>();
|
||||
if (!maybe_value.has_value()) {
|
||||
warnln("Invalid decimal character code {}", parameters[idx]);
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue