mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +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
|
@ -652,7 +652,7 @@ static ErrorOr<void> parse_week_data(ByteString core_path, CLDR& cldr)
|
|||
auto const& weekend_end_object = week_data_object.get_object("weekendEnd"sv).value();
|
||||
|
||||
minimum_days_object.for_each_member([&](auto const& region, auto const& value) {
|
||||
auto minimum_days = value.as_string().template to_uint<u8>();
|
||||
auto minimum_days = value.as_string().template to_number<u8>();
|
||||
cldr.minimum_days.set(region, *minimum_days);
|
||||
|
||||
if (!cldr.minimum_days_regions.contains_slow(region))
|
||||
|
@ -1279,7 +1279,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
|||
auto symbol_lists = create_symbol_lists(2);
|
||||
|
||||
auto append_symbol = [&](auto& symbols, auto const& key, auto symbol) {
|
||||
if (auto key_index = key.to_uint(); key_index.has_value())
|
||||
if (auto key_index = key.template to_number<unsigned>(); key_index.has_value())
|
||||
symbols[*key_index] = cldr.unique_strings.ensure(move(symbol));
|
||||
};
|
||||
|
||||
|
@ -1303,7 +1303,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
|||
auto symbol_lists = create_symbol_lists(12);
|
||||
|
||||
auto append_symbol = [&](auto& symbols, auto const& key, auto symbol) {
|
||||
auto key_index = key.to_uint().value() - 1;
|
||||
auto key_index = key.template to_number<unsigned>().value() - 1;
|
||||
symbols[key_index] = cldr.unique_strings.ensure(move(symbol));
|
||||
};
|
||||
|
||||
|
@ -1611,7 +1611,7 @@ static ErrorOr<void> parse_day_periods(ByteString core_path, CLDR& cldr)
|
|||
VERIFY(time.substring_view(hour_end_index) == ":00"sv);
|
||||
|
||||
auto hour = time.substring_view(0, hour_end_index);
|
||||
return hour.template to_uint<u8>().value();
|
||||
return hour.template to_number<u8>().value();
|
||||
};
|
||||
|
||||
auto parse_day_period = [&](auto const& symbol, auto const& ranges) -> Optional<DayPeriod> {
|
||||
|
|
|
@ -441,7 +441,7 @@ static ErrorOr<void> parse_number_systems(ByteString locale_numbers_path, CLDR&
|
|||
auto patterns = value.as_string().split(';');
|
||||
NumberFormat format {};
|
||||
|
||||
if (auto type = split_key[0].template to_uint<u64>(); type.has_value()) {
|
||||
if (auto type = split_key[0].template to_number<u64>(); type.has_value()) {
|
||||
VERIFY(*type % 10 == 0);
|
||||
format.magnitude = static_cast<u8>(log10(*type));
|
||||
|
||||
|
@ -580,7 +580,7 @@ static ErrorOr<void> parse_number_systems(ByteString locale_numbers_path, CLDR&
|
|||
locale.number_systems.append(system_index);
|
||||
}
|
||||
|
||||
locale.minimum_grouping_digits = minimum_grouping_digits.template to_uint<u8>().value();
|
||||
locale.minimum_grouping_digits = minimum_grouping_digits.template to_number<u8>().value();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@ static Relation parse_relation(StringView relation)
|
|||
auto symbol = lhs.substring_view(0, *index);
|
||||
VERIFY(symbol.length() == 1);
|
||||
|
||||
auto modulus = lhs.substring_view(*index + modulus_operator.length()).to_uint();
|
||||
auto modulus = lhs.substring_view(*index + modulus_operator.length()).to_number<unsigned>();
|
||||
VERIFY(modulus.has_value());
|
||||
|
||||
parsed.symbol = symbol[0];
|
||||
|
@ -257,15 +257,15 @@ static Relation parse_relation(StringView relation)
|
|||
|
||||
rhs.for_each_split_view(set_operator, SplitBehavior::Nothing, [&](auto set) {
|
||||
if (auto index = set.find(range_operator); index.has_value()) {
|
||||
auto range_begin = set.substring_view(0, *index).to_uint();
|
||||
auto range_begin = set.substring_view(0, *index).template to_number<unsigned>();
|
||||
VERIFY(range_begin.has_value());
|
||||
|
||||
auto range_end = set.substring_view(*index + range_operator.length()).to_uint();
|
||||
auto range_end = set.substring_view(*index + range_operator.length()).template to_number<unsigned>();
|
||||
VERIFY(range_end.has_value());
|
||||
|
||||
parsed.comparators.empend(Array { *range_begin, *range_end });
|
||||
} else {
|
||||
auto value = set.to_uint();
|
||||
auto value = set.template to_number<unsigned>();
|
||||
VERIFY(value.has_value());
|
||||
|
||||
parsed.comparators.empend(*value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue