1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +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

@ -96,17 +96,17 @@ void SearchPanel::search(StringView query)
// FIXME: Handle JSON parsing errors
auto const& json_place = json_places.at(i).as_object();
MapWidget::LatLng latlng = { json_place.get_byte_string("lat"sv).release_value().to_double().release_value(),
json_place.get_byte_string("lon"sv).release_value().to_double().release_value() };
MapWidget::LatLng latlng = { json_place.get_byte_string("lat"sv).release_value().to_number<double>().release_value(),
json_place.get_byte_string("lon"sv).release_value().to_number<double>().release_value() };
String name = MUST(String::formatted("{}\n{:.5}, {:.5}", json_place.get_byte_string("display_name"sv).release_value(), latlng.latitude, latlng.longitude));
// Calculate the right zoom level for bounding box
auto const& json_boundingbox = json_place.get_array("boundingbox"sv);
MapWidget::LatLngBounds bounds = {
{ json_boundingbox->at(0).as_string().to_double().release_value(),
json_boundingbox->at(2).as_string().to_double().release_value() },
{ json_boundingbox->at(1).as_string().to_double().release_value(),
json_boundingbox->at(3).as_string().to_double().release_value() }
{ json_boundingbox->at(0).as_string().to_number<double>().release_value(),
json_boundingbox->at(2).as_string().to_number<double>().release_value() },
{ json_boundingbox->at(1).as_string().to_number<double>().release_value(),
json_boundingbox->at(3).as_string().to_number<double>().release_value() }
};
m_places.append({ name, latlng, bounds.get_zoom() });