1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 04: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:
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

@ -358,7 +358,7 @@ ByteString deduplicate_destination_file_name(ByteString const& destination)
auto last_hyphen_index = title_without_counter.find_last('-');
if (last_hyphen_index.has_value()) {
auto counter_string = title_without_counter.substring_view(*last_hyphen_index + 1);
auto last_counter = counter_string.to_uint();
auto last_counter = counter_string.to_number<unsigned>();
if (last_counter.has_value()) {
next_counter = *last_counter + 1;
title_without_counter = title_without_counter.substring_view(0, *last_hyphen_index);

View file

@ -397,7 +397,7 @@ bool Launcher::open_file_url(const URL& url)
url.query()->bytes_as_string_view().for_each_split_view('&', SplitBehavior::Nothing, [&](auto parameter) {
auto pair = parameter.split_view('=');
if (pair.size() == 2 && pair[0] == "line_number") {
auto line = pair[1].to_int();
auto line = pair[1].template to_number<int>();
if (line.has_value())
// TextEditor uses file:line:col to open a file at a specific line number
filepath = ByteString::formatted("{}:{}", filepath, line.value());

View file

@ -339,7 +339,7 @@ void QuickLaunchWidget::load_entries(bool save)
auto value = Config::read_string(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES, name);
auto values = value.split(':');
config_entries.append({ values[0].to_int().release_value(), values[1] });
config_entries.append({ values[0].to_number<int>().release_value(), values[1] });
}
quick_sort(config_entries, [](ConfigEntry const& a, ConfigEntry const& b) {

View file

@ -150,7 +150,7 @@ static ErrorOr<Web::DOM::Element*, Web::WebDriver::Error> get_known_connected_el
{
// NOTE: The whole concept of "connected elements" is not implemented yet. See get_or_create_a_web_element_reference().
// For now the element is only represented by its ID.
auto element = element_id.to_int();
auto element = element_id.to_number<int>();
if (!element.has_value())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Element ID is not an integer");
@ -197,7 +197,7 @@ static ErrorOr<Web::DOM::ShadowRoot*, Web::WebDriver::Error> get_known_shadow_ro
{
// NOTE: The whole concept of "known shadow roots" is not implemented yet. See get_or_create_a_shadow_root_reference().
// For now the shadow root is only represented by its ID.
auto shadow_root = shadow_id.to_int();
auto shadow_root = shadow_id.to_number<int>();
if (!shadow_root.has_value())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Shadow ID is not an integer");

View file

@ -39,7 +39,7 @@ Client::~Client() = default;
ErrorOr<NonnullRefPtr<Session>, Web::WebDriver::Error> Client::find_session_with_id(StringView session_id)
{
auto session_id_or_error = session_id.to_uint<>();
auto session_id_or_error = session_id.to_number<unsigned>();
if (!session_id_or_error.has_value())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");