1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +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:
Shannon Booth 2023-12-23 15:59:14 +13:00 committed by Andreas Kling
parent a4ecc65398
commit e2e7c4d574
155 changed files with 397 additions and 412 deletions

View file

@ -316,7 +316,7 @@ Vector<NonnullOwnPtr<KString>> CommandLine::userspace_init_args() const
UNMAP_AFTER_INIT size_t CommandLine::switch_to_tty() const
{
auto const default_tty = lookup("switch_to_tty"sv).value_or("1"sv);
auto switch_tty_number = default_tty.to_uint();
auto switch_tty_number = default_tty.to_number<unsigned>();
if (switch_tty_number.has_value() && switch_tty_number.value() >= 1) {
return switch_tty_number.value() - 1;
}

View file

@ -248,7 +248,7 @@ UNMAP_AFTER_INIT Optional<unsigned> StorageManagement::extract_boot_device_parti
PANIC("StorageManagement: Invalid root boot parameter.");
}
auto parameter_number = parameter_view.substring_view(partition_number_prefix.length()).to_uint<unsigned>();
auto parameter_number = parameter_view.substring_view(partition_number_prefix.length()).to_number<unsigned>();
if (!parameter_number.has_value()) {
PANIC("StorageManagement: Invalid root boot parameter.");
}
@ -268,7 +268,7 @@ UNMAP_AFTER_INIT Array<unsigned, 3> StorageManagement::extract_boot_device_addre
return;
if (parts_count > 2)
return;
auto parameter_number = parameter_view.to_uint<unsigned>();
auto parameter_number = parameter_view.to_number<unsigned>();
if (!parameter_number.has_value()) {
parse_failure = true;
return;

View file

@ -70,7 +70,7 @@ ErrorOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
if (name == "." || name == "..")
return *this;
auto pty_index = name.to_uint();
auto pty_index = name.to_number<unsigned>();
if (!pty_index.has_value())
return ENOENT;

View file

@ -159,7 +159,7 @@ ErrorOr<NonnullRefPtr<Inode>> ProcFSInode::lookup_as_root_directory(StringView n
if (name == "self"sv)
return procfs().get_inode({ fsid(), 2 });
auto pid = name.to_uint<unsigned>();
auto pid = name.to_number<unsigned>();
if (!pid.has_value())
return ESRCH;
auto actual_pid = pid.value();

View file

@ -79,7 +79,7 @@ ErrorOr<void> Process::traverse_stacks_directory(FileSystemID fsid, Function<Err
ErrorOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(ProcFS& procfs, StringView name) const
{
auto maybe_needle = name.to_uint();
auto maybe_needle = name.to_number<unsigned>();
if (!maybe_needle.has_value())
return ENOENT;
auto needle = maybe_needle.release_value();
@ -120,7 +120,7 @@ ErrorOr<void> Process::traverse_children_directory(FileSystemID fsid, Function<E
ErrorOr<NonnullRefPtr<Inode>> Process::lookup_children_directory(ProcFS& procfs, StringView name) const
{
auto maybe_pid = name.to_uint();
auto maybe_pid = name.to_number<unsigned>();
if (!maybe_pid.has_value())
return ENOENT;
@ -173,7 +173,7 @@ ErrorOr<void> Process::traverse_file_descriptions_directory(FileSystemID fsid, F
ErrorOr<NonnullRefPtr<Inode>> Process::lookup_file_descriptions_directory(ProcFS& procfs, StringView name) const
{
auto maybe_index = name.to_uint();
auto maybe_index = name.to_number<unsigned>();
if (!maybe_index.has_value())
return ENOENT;