mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:37: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
|
@ -90,7 +90,7 @@ inline ErrorOr<void> TarInputStream::for_each_extended_header(F func)
|
|||
Optional<size_t> length_end_index = file_contents.find(' ');
|
||||
if (!length_end_index.has_value())
|
||||
return Error::from_string_literal("Malformed extended header: No length found.");
|
||||
Optional<unsigned int> length = file_contents.substring_view(0, length_end_index.value()).to_uint();
|
||||
Optional<unsigned> length = file_contents.substring_view(0, length_end_index.value()).to_number<unsigned>();
|
||||
if (!length.has_value())
|
||||
return Error::from_string_literal("Malformed extended header: Could not parse length.");
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ static bool parse_grpdb_entry(char* buffer, size_t buffer_size, struct group& gr
|
|||
auto& gid_string = parts[2];
|
||||
StringView members_string = parts[3];
|
||||
|
||||
auto gid = gid_string.to_uint();
|
||||
auto gid = gid_string.to_number<gid_t>();
|
||||
if (!gid.has_value()) {
|
||||
warnln("parse_grpdb_entry(): Malformed GID on line {}", s_line_number);
|
||||
return false;
|
||||
|
|
|
@ -767,7 +767,7 @@ static bool fill_getproto_buffers(char const* line, ssize_t read)
|
|||
}
|
||||
__getproto_name_buffer = split_line[0];
|
||||
|
||||
auto number = split_line[1].to_int();
|
||||
auto number = split_line[1].to_number<int>();
|
||||
if (!number.has_value())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -88,12 +88,12 @@ static bool parse_pwddb_entry(char* raw_line, struct passwd& passwd_entry)
|
|||
auto& dir = parts[5];
|
||||
auto& shell = parts[6];
|
||||
|
||||
auto uid = uid_string.to_uint();
|
||||
auto uid = uid_string.to_number<uid_t>();
|
||||
if (!uid.has_value()) {
|
||||
dbgln("getpwent(): Malformed UID on line {}", s_line_number);
|
||||
return false;
|
||||
}
|
||||
auto gid = gid_string.to_uint();
|
||||
auto gid = gid_string.to_number<gid_t>();
|
||||
if (!gid.has_value()) {
|
||||
dbgln("getpwent(): Malformed GID on line {}", s_line_number);
|
||||
return false;
|
||||
|
|
|
@ -410,7 +410,7 @@ extern "C" int vsscanf(char const* input, char const* format, va_list ap)
|
|||
[[maybe_unused]] int width_specifier = 0;
|
||||
if (format_lexer.next_is(isdigit)) {
|
||||
auto width_digits = format_lexer.consume_while([](char c) { return isdigit(c); });
|
||||
width_specifier = width_digits.to_int().value();
|
||||
width_specifier = width_digits.to_number<int>().value();
|
||||
// FIXME: Actually use width specifier
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
auto& expire_string = parts[7];
|
||||
auto& flag_string = parts[8];
|
||||
|
||||
auto lstchg = lstchg_string.to_int();
|
||||
auto lstchg = lstchg_string.to_number<int>();
|
||||
if (!lstchg.has_value()) {
|
||||
dbgln("getspent(): Malformed lstchg on line {}", s_line_number);
|
||||
return false;
|
||||
|
@ -87,7 +87,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
|
||||
if (min_string.is_empty())
|
||||
min_string = "-1"sv;
|
||||
auto min_value = min_string.to_int();
|
||||
auto min_value = min_string.to_number<int>();
|
||||
if (!min_value.has_value()) {
|
||||
dbgln("getspent(): Malformed min value on line {}", s_line_number);
|
||||
return false;
|
||||
|
@ -95,7 +95,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
|
||||
if (max_string.is_empty())
|
||||
max_string = "-1"sv;
|
||||
auto max_value = max_string.to_int();
|
||||
auto max_value = max_string.to_number<int>();
|
||||
if (!max_value.has_value()) {
|
||||
dbgln("getspent(): Malformed max value on line {}", s_line_number);
|
||||
return false;
|
||||
|
@ -103,7 +103,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
|
||||
if (warn_string.is_empty())
|
||||
warn_string = "-1"sv;
|
||||
auto warn = warn_string.to_int();
|
||||
auto warn = warn_string.to_number<int>();
|
||||
if (!warn.has_value()) {
|
||||
dbgln("getspent(): Malformed warn on line {}", s_line_number);
|
||||
return false;
|
||||
|
@ -111,7 +111,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
|
||||
if (inact_string.is_empty())
|
||||
inact_string = "-1"sv;
|
||||
auto inact = inact_string.to_int();
|
||||
auto inact = inact_string.to_number<int>();
|
||||
if (!inact.has_value()) {
|
||||
dbgln("getspent(): Malformed inact on line {}", s_line_number);
|
||||
return false;
|
||||
|
@ -119,7 +119,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
|
||||
if (expire_string.is_empty())
|
||||
expire_string = "-1"sv;
|
||||
auto expire = expire_string.to_int();
|
||||
auto expire = expire_string.to_number<int>();
|
||||
if (!expire.has_value()) {
|
||||
dbgln("getspent(): Malformed expire on line {}", s_line_number);
|
||||
return false;
|
||||
|
@ -127,7 +127,7 @@ static bool parse_shadow_entry(ByteString const& line)
|
|||
|
||||
if (flag_string.is_empty())
|
||||
flag_string = "0"sv;
|
||||
auto flag = flag_string.to_int();
|
||||
auto flag = flag_string.to_number<int>();
|
||||
if (!flag.has_value()) {
|
||||
dbgln("getspent(): Malformed flag on line {}", s_line_number);
|
||||
return false;
|
||||
|
|
|
@ -161,31 +161,31 @@ ErrorOr<NonnullOwnPtr<GoCommand>> GoCommand::from_string(StringView command)
|
|||
go_command->ponder = true;
|
||||
} else if (tokens[i] == "wtime") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->wtime = tokens[i].to_int().value();
|
||||
go_command->wtime = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "btime") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->btime = tokens[i].to_int().value();
|
||||
go_command->btime = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "winc") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->winc = tokens[i].to_int().value();
|
||||
go_command->winc = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "binc") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->binc = tokens[i].to_int().value();
|
||||
go_command->binc = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "movestogo") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->movestogo = tokens[i].to_int().value();
|
||||
go_command->movestogo = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "depth") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->depth = tokens[i].to_int().value();
|
||||
go_command->depth = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "nodes") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->nodes = tokens[i].to_int().value();
|
||||
go_command->nodes = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "mate") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->mate = tokens[i].to_int().value();
|
||||
go_command->mate = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "movetime") {
|
||||
VERIFY(i++ < tokens.size());
|
||||
go_command->movetime = tokens[i].to_int().value();
|
||||
go_command->movetime = tokens[i].to_number<int>().value();
|
||||
} else if (tokens[i] == "infinite") {
|
||||
go_command->infinite = true;
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ ErrorOr<NonnullOwnPtr<InfoCommand>> InfoCommand::from_string(StringView command)
|
|||
auto info_command = TRY(try_make<InfoCommand>());
|
||||
|
||||
auto parse_integer_token = [](StringView value_token) -> ErrorOr<int> {
|
||||
auto value_as_integer = value_token.to_int();
|
||||
auto value_as_integer = value_token.to_number<int>();
|
||||
if (!value_as_integer.has_value())
|
||||
return Error::from_string_literal("Expected integer token");
|
||||
|
||||
|
|
|
@ -500,11 +500,7 @@ void ArgsParser::add_option(I& value, char const* help_string, char const* long_
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView view) -> ErrorOr<bool> {
|
||||
Optional<I> opt;
|
||||
if constexpr (IsSigned<I>)
|
||||
opt = view.to_int<I>();
|
||||
else
|
||||
opt = view.to_uint<I>();
|
||||
Optional<I> opt = view.to_number<I>();
|
||||
value = opt.value_or(0);
|
||||
return opt.has_value();
|
||||
},
|
||||
|
@ -530,7 +526,7 @@ void ArgsParser::add_option(double& value, char const* help_string, char const*
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
auto opt = s.to_double();
|
||||
auto opt = s.to_number<double>();
|
||||
value = opt.value_or(0.0);
|
||||
return opt.has_value();
|
||||
},
|
||||
|
@ -548,7 +544,7 @@ void ArgsParser::add_option(Optional<double>& value, char const* help_string, ch
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
value = s.to_double();
|
||||
value = s.to_number<double>();
|
||||
return value.has_value();
|
||||
},
|
||||
hide_mode,
|
||||
|
@ -565,7 +561,7 @@ void ArgsParser::add_option(Optional<size_t>& value, char const* help_string, ch
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
value = AK::StringUtils::convert_to_uint<size_t>(s);
|
||||
value = s.to_number<size_t>();
|
||||
return value.has_value();
|
||||
},
|
||||
hide_mode,
|
||||
|
@ -676,11 +672,7 @@ void ArgsParser::add_positional_argument(I& value, char const* help_string, char
|
|||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](StringView view) -> ErrorOr<bool> {
|
||||
Optional<I> opt;
|
||||
if constexpr (IsSigned<I>)
|
||||
opt = view.to_int<I>();
|
||||
else
|
||||
opt = view.to_uint<I>();
|
||||
Optional<I> opt = view.to_number<I>();
|
||||
value = opt.value_or(0);
|
||||
return opt.has_value();
|
||||
},
|
||||
|
@ -705,7 +697,7 @@ void ArgsParser::add_positional_argument(double& value, char const* help_string,
|
|||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](StringView s) -> ErrorOr<bool> {
|
||||
auto opt = s.to_double();
|
||||
auto opt = s.to_number<double>();
|
||||
value = opt.value_or(0.0);
|
||||
return opt.has_value();
|
||||
}
|
||||
|
|
|
@ -55,10 +55,7 @@ public:
|
|||
if (!has_key(group, key))
|
||||
return default_value;
|
||||
|
||||
if constexpr (IsSigned<T>)
|
||||
return read_entry(group, key, "").to_int<T>().value_or(default_value);
|
||||
else
|
||||
return read_entry(group, key, "").to_uint<T>().value_or(default_value);
|
||||
return read_entry(group, key, "").to_number<T>().value_or(default_value);
|
||||
}
|
||||
|
||||
void write_entry(ByteString const& group, ByteString const& key, ByteString const& value);
|
||||
|
|
|
@ -209,7 +209,7 @@ ErrorOr<bool> Process::is_being_debugged()
|
|||
auto const parts = line.split_view(':');
|
||||
if (parts.size() < 2 || parts[0] != "TracerPid"sv)
|
||||
continue;
|
||||
auto tracer_pid = parts[1].to_uint<u32>();
|
||||
auto tracer_pid = parts[1].to_number<u32>();
|
||||
return (tracer_pid != 0UL);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -27,7 +27,7 @@ static void parse_sockets_from_system_server()
|
|||
for (auto const socket : StringView { sockets, strlen(sockets) }.split_view(';')) {
|
||||
auto params = socket.split_view(':');
|
||||
VERIFY(params.size() == 2);
|
||||
s_overtaken_sockets.set(params[0].to_byte_string(), params[1].to_int().value());
|
||||
s_overtaken_sockets.set(params[0].to_byte_string(), params[1].to_number<int>().value());
|
||||
}
|
||||
|
||||
s_overtaken_sockets_parsed = true;
|
||||
|
|
|
@ -123,16 +123,16 @@ Optional<Core::DateTime> parse_utc_time(StringView time)
|
|||
{
|
||||
// YYMMDDhhmm[ss]Z or YYMMDDhhmm[ss](+|-)hhmm
|
||||
GenericLexer lexer(time);
|
||||
auto year_in_century = lexer.consume(2).to_uint();
|
||||
auto month = lexer.consume(2).to_uint();
|
||||
auto day = lexer.consume(2).to_uint();
|
||||
auto hour = lexer.consume(2).to_uint();
|
||||
auto minute = lexer.consume(2).to_uint();
|
||||
auto year_in_century = lexer.consume(2).to_number<unsigned>();
|
||||
auto month = lexer.consume(2).to_number<unsigned>();
|
||||
auto day = lexer.consume(2).to_number<unsigned>();
|
||||
auto hour = lexer.consume(2).to_number<unsigned>();
|
||||
auto minute = lexer.consume(2).to_number<unsigned>();
|
||||
Optional<unsigned> seconds, offset_hours, offset_minutes;
|
||||
[[maybe_unused]] bool negative_offset = false;
|
||||
|
||||
if (lexer.next_is(is_any_of("0123456789"sv))) {
|
||||
seconds = lexer.consume(2).to_uint();
|
||||
seconds = lexer.consume(2).to_number<unsigned>();
|
||||
if (!seconds.has_value()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -142,8 +142,8 @@ Optional<Core::DateTime> parse_utc_time(StringView time)
|
|||
lexer.consume();
|
||||
} else if (lexer.next_is(is_any_of("+-"sv))) {
|
||||
negative_offset = lexer.consume() == '-';
|
||||
offset_hours = lexer.consume(2).to_uint();
|
||||
offset_minutes = lexer.consume(2).to_uint();
|
||||
offset_hours = lexer.consume(2).to_number<unsigned>();
|
||||
offset_minutes = lexer.consume(2).to_number<unsigned>();
|
||||
if (!offset_hours.has_value() || !offset_minutes.has_value()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -171,10 +171,10 @@ Optional<Core::DateTime> parse_generalized_time(StringView time)
|
|||
{
|
||||
// YYYYMMDDhh[mm[ss[.fff]]] or YYYYMMDDhh[mm[ss[.fff]]]Z or YYYYMMDDhh[mm[ss[.fff]]](+|-)hhmm
|
||||
GenericLexer lexer(time);
|
||||
auto year = lexer.consume(4).to_uint();
|
||||
auto month = lexer.consume(2).to_uint();
|
||||
auto day = lexer.consume(2).to_uint();
|
||||
auto hour = lexer.consume(2).to_uint();
|
||||
auto year = lexer.consume(4).to_number<unsigned>();
|
||||
auto month = lexer.consume(2).to_number<unsigned>();
|
||||
auto day = lexer.consume(2).to_number<unsigned>();
|
||||
auto hour = lexer.consume(2).to_number<unsigned>();
|
||||
Optional<unsigned> minute, seconds, milliseconds, offset_hours, offset_minutes;
|
||||
[[maybe_unused]] bool negative_offset = false;
|
||||
if (!lexer.is_eof()) {
|
||||
|
@ -182,7 +182,7 @@ Optional<Core::DateTime> parse_generalized_time(StringView time)
|
|||
goto done_parsing;
|
||||
|
||||
if (!lexer.next_is(is_any_of("+-"sv))) {
|
||||
minute = lexer.consume(2).to_uint();
|
||||
minute = lexer.consume(2).to_number<unsigned>();
|
||||
if (!minute.has_value()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ Optional<Core::DateTime> parse_generalized_time(StringView time)
|
|||
}
|
||||
|
||||
if (!lexer.next_is(is_any_of("+-"sv))) {
|
||||
seconds = lexer.consume(2).to_uint();
|
||||
seconds = lexer.consume(2).to_number<unsigned>();
|
||||
if (!seconds.has_value()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ Optional<Core::DateTime> parse_generalized_time(StringView time)
|
|||
}
|
||||
|
||||
if (lexer.consume_specific('.')) {
|
||||
milliseconds = lexer.consume(3).to_uint();
|
||||
milliseconds = lexer.consume(3).to_number<unsigned>();
|
||||
if (!milliseconds.has_value()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -210,8 +210,8 @@ Optional<Core::DateTime> parse_generalized_time(StringView time)
|
|||
|
||||
if (lexer.next_is(is_any_of("+-"sv))) {
|
||||
negative_offset = lexer.consume() == '-';
|
||||
offset_hours = lexer.consume(2).to_uint();
|
||||
offset_minutes = lexer.consume(2).to_uint();
|
||||
offset_hours = lexer.consume(2).to_number<unsigned>();
|
||||
offset_minutes = lexer.consume(2).to_number<unsigned>();
|
||||
if (!offset_hours.has_value() || !offset_minutes.has_value()) {
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ bool Parser::consume_line_number(size_t& number)
|
|||
{
|
||||
auto line = consume_while(is_ascii_digit);
|
||||
|
||||
auto maybe_number = line.to_uint<size_t>();
|
||||
auto maybe_number = line.to_number<size_t>();
|
||||
if (!maybe_number.has_value())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ void AbstractTableView::set_visible_columns(StringView column_names)
|
|||
column_header().set_section_visible(column, false);
|
||||
|
||||
column_names.for_each_split_view(',', SplitBehavior::Nothing, [&, this](StringView column_id_string) {
|
||||
if (auto column = column_id_string.to_int(); column.has_value()) {
|
||||
if (auto column = column_id_string.to_number<int>(); column.has_value()) {
|
||||
column_header().set_section_visible(column.value(), true);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -79,23 +79,23 @@ RefPtr<Gfx::Bitmap> Clipboard::DataAndType::as_bitmap() const
|
|||
if (mime_type != "image/x-serenityos")
|
||||
return nullptr;
|
||||
|
||||
auto width = metadata.get("width").value_or("0").to_uint();
|
||||
auto width = metadata.get("width").value_or("0").to_number<unsigned>();
|
||||
if (!width.has_value() || width.value() == 0)
|
||||
return nullptr;
|
||||
|
||||
auto height = metadata.get("height").value_or("0").to_uint();
|
||||
auto height = metadata.get("height").value_or("0").to_number<unsigned>();
|
||||
if (!height.has_value() || height.value() == 0)
|
||||
return nullptr;
|
||||
|
||||
auto scale = metadata.get("scale").value_or("0").to_uint();
|
||||
auto scale = metadata.get("scale").value_or("0").to_number<unsigned>();
|
||||
if (!scale.has_value() || scale.value() == 0)
|
||||
return nullptr;
|
||||
|
||||
auto pitch = metadata.get("pitch").value_or("0").to_uint();
|
||||
auto pitch = metadata.get("pitch").value_or("0").to_number<unsigned>();
|
||||
if (!pitch.has_value() || pitch.value() == 0)
|
||||
return nullptr;
|
||||
|
||||
auto format = metadata.get("format").value_or("0").to_uint();
|
||||
auto format = metadata.get("format").value_or("0").to_number<unsigned>();
|
||||
if (!format.has_value() || format.value() == 0)
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ SpinBox::SpinBox()
|
|||
if (!weak_this)
|
||||
return;
|
||||
|
||||
auto value = m_editor->text().to_uint();
|
||||
auto value = m_editor->text().to_number<unsigned>();
|
||||
if (!value.has_value() && m_editor->text().length() > 0)
|
||||
m_editor->do_delete();
|
||||
};
|
||||
|
@ -81,7 +81,7 @@ void SpinBox::set_value_from_current_text()
|
|||
if (m_editor->text().is_empty())
|
||||
return;
|
||||
|
||||
auto value = m_editor->text().to_int();
|
||||
auto value = m_editor->text().to_number<int>();
|
||||
if (value.has_value())
|
||||
set_value(value.value());
|
||||
else
|
||||
|
|
|
@ -35,7 +35,7 @@ ValueSlider::ValueSlider(Gfx::Orientation orientation, String suffix)
|
|||
ByteString value = m_textbox->text();
|
||||
if (value.ends_with(m_suffix, AK::CaseSensitivity::CaseInsensitive))
|
||||
value = value.substring_view(0, value.length() - m_suffix.bytes_as_string_view().length());
|
||||
auto integer_value = value.to_int();
|
||||
auto integer_value = value.to_number<int>();
|
||||
if (integer_value.has_value())
|
||||
AbstractSlider::set_value(integer_value.value());
|
||||
};
|
||||
|
|
|
@ -120,10 +120,7 @@ public:
|
|||
[](FloatingPoint auto v) { return (T)v; },
|
||||
[](Detail::Boolean v) -> T { return v.value ? 1 : 0; },
|
||||
[](ByteString const& v) {
|
||||
if constexpr (IsUnsigned<T>)
|
||||
return v.to_uint<T>().value_or(0u);
|
||||
else
|
||||
return v.to_int<T>().value_or(0);
|
||||
return v.to_number<T>().value_or(0);
|
||||
},
|
||||
[](Enum auto const&) -> T { return 0; },
|
||||
[](OneOf<Gfx::IntPoint, Gfx::IntRect, Gfx::IntSize, Color, NonnullRefPtr<Gfx::Font const>, NonnullRefPtr<Gfx::Bitmap const>, GUI::Icon> auto const&) -> T { return 0; });
|
||||
|
|
|
@ -142,10 +142,10 @@ void Window::show()
|
|||
auto parts = StringView { launch_origin_rect_string, strlen(launch_origin_rect_string) }.split_view(',');
|
||||
if (parts.size() == 4) {
|
||||
launch_origin_rect = Gfx::IntRect {
|
||||
parts[0].to_int().value_or(0),
|
||||
parts[1].to_int().value_or(0),
|
||||
parts[2].to_int().value_or(0),
|
||||
parts[3].to_int().value_or(0),
|
||||
parts[0].to_number<int>().value_or(0),
|
||||
parts[1].to_number<int>().value_or(0),
|
||||
parts[2].to_number<int>().value_or(0),
|
||||
parts[3].to_number<int>().value_or(0),
|
||||
};
|
||||
}
|
||||
unsetenv("__libgui_launch_origin_rect");
|
||||
|
|
|
@ -167,7 +167,7 @@ void Job::on_socket_connected()
|
|||
auto first_part = view.substring_view(0, space_index);
|
||||
auto second_part = view.substring_view(space_index + 1);
|
||||
|
||||
auto status = first_part.to_uint();
|
||||
auto status = first_part.to_number<unsigned>();
|
||||
if (!status.has_value()) {
|
||||
dbgln("Job: Expected numeric status code");
|
||||
m_state = State::Failed;
|
||||
|
|
|
@ -49,9 +49,9 @@ static Optional<Color> parse_rgb_color(StringView string)
|
|||
if (parts.size() != 3)
|
||||
return {};
|
||||
|
||||
auto r = parts[0].to_double().map(AK::clamp_to<u8, double>);
|
||||
auto g = parts[1].to_double().map(AK::clamp_to<u8, double>);
|
||||
auto b = parts[2].to_double().map(AK::clamp_to<u8, double>);
|
||||
auto r = parts[0].to_number<double>().map(AK::clamp_to<u8, double>);
|
||||
auto g = parts[1].to_number<double>().map(AK::clamp_to<u8, double>);
|
||||
auto b = parts[2].to_number<double>().map(AK::clamp_to<u8, double>);
|
||||
|
||||
if (!r.has_value() || !g.has_value() || !b.has_value())
|
||||
return {};
|
||||
|
@ -70,9 +70,9 @@ static Optional<Color> parse_rgba_color(StringView string)
|
|||
if (parts.size() != 4)
|
||||
return {};
|
||||
|
||||
auto r = parts[0].to_double().map(AK::clamp_to<u8, double>);
|
||||
auto g = parts[1].to_double().map(AK::clamp_to<u8, double>);
|
||||
auto b = parts[2].to_double().map(AK::clamp_to<u8, double>);
|
||||
auto r = parts[0].to_number<double>().map(AK::clamp_to<u8, double>);
|
||||
auto g = parts[1].to_number<double>().map(AK::clamp_to<u8, double>);
|
||||
auto b = parts[2].to_number<double>().map(AK::clamp_to<u8, double>);
|
||||
|
||||
double alpha = 0;
|
||||
auto alpha_str = parts[3].trim_whitespace();
|
||||
|
|
|
@ -37,7 +37,7 @@ CursorParams CursorParams::parse_from_filename(StringView cursor_path, Gfx::IntP
|
|||
}
|
||||
if (k == i)
|
||||
return {};
|
||||
auto parsed_number = params_str.substring_view(i, k - i).to_uint();
|
||||
auto parsed_number = params_str.substring_view(i, k - i).to_number<unsigned>();
|
||||
if (!parsed_number.has_value())
|
||||
return {};
|
||||
i = k;
|
||||
|
|
|
@ -180,9 +180,9 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
|
|||
if (it == m_private->full_name_to_font_map.end()) {
|
||||
auto parts = name.split_view(" "sv);
|
||||
if (parts.size() >= 4) {
|
||||
auto slope = parts.take_last().to_int().value_or(0);
|
||||
auto weight = parts.take_last().to_int().value_or(0);
|
||||
auto size = parts.take_last().to_int().value_or(0);
|
||||
auto slope = parts.take_last().to_number<int>().value_or(0);
|
||||
auto weight = parts.take_last().to_number<int>().value_or(0);
|
||||
auto size = parts.take_last().to_number<int>().value_or(0);
|
||||
auto family = MUST(String::join(' ', parts));
|
||||
return get(family, size, weight, Gfx::FontWidth::Normal, slope);
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
|
|||
commit_and_advance_to(current_header.value, next_state);
|
||||
|
||||
if (current_header.name.equals_ignoring_ascii_case("Content-Length"sv))
|
||||
content_length = current_header.value.to_uint();
|
||||
content_length = current_header.value.to_number<unsigned>();
|
||||
|
||||
headers.append(move(current_header));
|
||||
break;
|
||||
|
|
|
@ -263,7 +263,7 @@ void Job::on_socket_connected()
|
|||
auto http_minor_version = parse_ascii_digit(parts[0][7]);
|
||||
m_legacy_connection = http_major_version < 1 || (http_major_version == 1 && http_minor_version == 0);
|
||||
|
||||
auto code = parts[1].to_uint();
|
||||
auto code = parts[1].to_number<unsigned>();
|
||||
if (!code.has_value()) {
|
||||
dbgln("Job: Expected numeric HTTP status");
|
||||
return deferred_invoke([this] { did_fail(Core::NetworkJob::Error::ProtocolFailed); });
|
||||
|
@ -312,7 +312,7 @@ void Job::on_socket_connected()
|
|||
// We've reached the end of the headers, there's a possibility that the server
|
||||
// responds with nothing (content-length = 0 with normal encoding); if that's the case,
|
||||
// quit early as we won't be reading anything anyway.
|
||||
if (auto result = m_headers.get("Content-Length"sv).value_or(""sv).to_uint(); result.has_value()) {
|
||||
if (auto result = m_headers.get("Content-Length"sv).value_or(""sv).to_number<unsigned>(); result.has_value()) {
|
||||
if (result.value() == 0 && !m_headers.get("Transfer-Encoding"sv).value_or(""sv).view().trim_whitespace().equals_ignoring_ascii_case("chunked"sv))
|
||||
return finish_up();
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ void Job::on_socket_connected()
|
|||
dbgln_if(JOB_DEBUG, "Content-Encoding {} detected, cannot stream output :(", value);
|
||||
m_can_stream_response = false;
|
||||
} else if (name.equals_ignoring_ascii_case("Content-Length"sv)) {
|
||||
auto length = value.to_uint<u64>();
|
||||
auto length = value.to_number<u64>();
|
||||
if (length.has_value())
|
||||
m_content_length = length.value();
|
||||
}
|
||||
|
|
|
@ -123,8 +123,8 @@ Optional<unsigned> Parser::try_parse_number()
|
|||
|
||||
auto number = StringView(m_buffer.data() + m_position - number_matched, number_matched);
|
||||
|
||||
dbgln_if(IMAP_PARSER_DEBUG, "p: {}, ret \"{}\"", m_position, number.to_uint());
|
||||
return number.to_uint();
|
||||
dbgln_if(IMAP_PARSER_DEBUG, "p: {}, ret \"{}\"", m_position, number.to_number<unsigned>());
|
||||
return number.to_number<unsigned>();
|
||||
}
|
||||
|
||||
ErrorOr<unsigned> Parser::parse_number()
|
||||
|
|
|
@ -1199,7 +1199,7 @@ CanonicalIndex canonical_numeric_index_string(PropertyKey const& property_key, C
|
|||
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
|
||||
|
||||
// 2. Let n be ! ToNumber(argument).
|
||||
auto maybe_double = argument.to_double(AK::TrimWhitespace::No);
|
||||
auto maybe_double = argument.to_number<double>(AK::TrimWhitespace::No);
|
||||
if (!maybe_double.has_value())
|
||||
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
|
||||
|
||||
|
|
|
@ -377,7 +377,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
|
|||
return NumericLimits<i64>::max();
|
||||
|
||||
// FIXME: Can we do this without string conversion?
|
||||
return value.to_base_deprecated(10).to_int<i64>().value();
|
||||
return value.to_base_deprecated(10).to_number<i64>().value();
|
||||
}
|
||||
|
||||
// 21.4.1.20 GetNamedTimeZoneEpochNanoseconds ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/ecma262/#sec-getnamedtimezoneepochnanoseconds
|
||||
|
|
|
@ -647,7 +647,7 @@ Vector<PatternPartition> partition_number_pattern(VM& vm, NumberFormat& number_f
|
|||
else if ((part.starts_with("unitIdentifier:"sv)) && (number_format.style() == NumberFormat::Style::Unit)) {
|
||||
// Note: Our implementation combines "unitPrefix" and "unitSuffix" into one field, "unitIdentifier".
|
||||
|
||||
auto identifier_index = part.substring_view("unitIdentifier:"sv.length()).to_uint();
|
||||
auto identifier_index = part.substring_view("unitIdentifier:"sv.length()).to_number<unsigned>();
|
||||
VERIFY(identifier_index.has_value());
|
||||
|
||||
// i. Let unit be numberFormat.[[Unit]].
|
||||
|
@ -862,7 +862,7 @@ Vector<PatternPartition> partition_notation_sub_pattern(NumberFormat& number_for
|
|||
else if (part.starts_with("compactIdentifier:"sv)) {
|
||||
// Note: Our implementation combines "compactSymbol" and "compactName" into one field, "compactIdentifier".
|
||||
|
||||
auto identifier_index = part.substring_view("compactIdentifier:"sv.length()).to_uint();
|
||||
auto identifier_index = part.substring_view("compactIdentifier:"sv.length()).to_number<unsigned>();
|
||||
VERIFY(identifier_index.has_value());
|
||||
|
||||
// 1. Let compactSymbol be an ILD string representing exponent in short form, which may depend on x in languages having different plural forms. The implementation must be able to provide this string, or else the pattern would not have a "{compactSymbol}" placeholder.
|
||||
|
@ -1034,7 +1034,7 @@ static RawPrecisionResult to_raw_precision_function(MathematicalValue const& num
|
|||
|
||||
result.number = result.number.divided_by(10);
|
||||
|
||||
if (mode == PreferredResult::GreaterThanNumber && digit.to_uint().value() != 0)
|
||||
if (mode == PreferredResult::GreaterThanNumber && digit.to_number<unsigned>().value() != 0)
|
||||
result.number = result.number.plus(1);
|
||||
}
|
||||
|
||||
|
@ -1183,7 +1183,7 @@ static RawFixedResult to_raw_fixed_function(MathematicalValue const& number, int
|
|||
|
||||
result.number = result.number.multiplied_by(10);
|
||||
|
||||
if (mode == PreferredResult::GreaterThanNumber && digit.to_uint().value() != 0)
|
||||
if (mode == PreferredResult::GreaterThanNumber && digit.to_number<unsigned>().value() != 0)
|
||||
result.number = result.number.plus(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ PluralRules::PluralRules(Object& prototype)
|
|||
::Locale::PluralOperands get_operands(StringView string)
|
||||
{
|
||||
// 1.Let n be ! ToNumber(s).
|
||||
auto number = string.to_double(AK::TrimWhitespace::Yes).release_value();
|
||||
auto number = string.to_number<double>(AK::TrimWhitespace::Yes).release_value();
|
||||
|
||||
// 2. Assert: n is finite.
|
||||
VERIFY(isfinite(number));
|
||||
|
@ -57,7 +57,7 @@ PluralRules::PluralRules(Object& prototype)
|
|||
return static_cast<u64>(fabs(value));
|
||||
},
|
||||
[](StringView value) {
|
||||
auto value_as_int = value.template to_int<i64>().value();
|
||||
auto value_as_int = value.template to_number<i64>().value();
|
||||
return static_cast<u64>(value_as_int);
|
||||
});
|
||||
|
||||
|
@ -65,7 +65,7 @@ PluralRules::PluralRules(Object& prototype)
|
|||
auto fraction_digit_count = fraction_slice.length();
|
||||
|
||||
// 8. Let f be ! ToNumber(fracSlice).
|
||||
auto fraction = fraction_slice.is_empty() ? 0u : fraction_slice.template to_uint<u64>().value();
|
||||
auto fraction = fraction_slice.is_empty() ? 0u : fraction_slice.template to_number<u64>().value();
|
||||
|
||||
// 9. Let significantFracSlice be the value of fracSlice stripped of trailing "0".
|
||||
auto significant_fraction_slice = fraction_slice.trim("0"sv, TrimMode::Right);
|
||||
|
@ -74,7 +74,7 @@ PluralRules::PluralRules(Object& prototype)
|
|||
auto significant_fraction_digit_count = significant_fraction_slice.length();
|
||||
|
||||
// 11. Let significantFrac be ! ToNumber(significantFracSlice).
|
||||
auto significant_fraction = significant_fraction_slice.is_empty() ? 0u : significant_fraction_slice.template to_uint<u64>().value();
|
||||
auto significant_fraction = significant_fraction_slice.is_empty() ? 0u : significant_fraction_slice.template to_number<u64>().value();
|
||||
|
||||
// 12. Return a new Record { [[Number]]: abs(n), [[IntegerDigits]]: i, [[FractionDigits]]: f, [[NumberOfFractionDigits]]: fracDigitCount, [[FractionDigitsWithoutTrailing]]: significantFrac, [[NumberOfFractionDigitsWithoutTrailing]]: significantFracDigitCount }.
|
||||
return ::Locale::PluralOperands {
|
||||
|
|
|
@ -136,7 +136,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
auto property_index = m_string.to_uint(TrimWhitespace::No);
|
||||
auto property_index = m_string.to_number<unsigned>(TrimWhitespace::No);
|
||||
if (!property_index.has_value() || property_index.value() == NumericLimits<u32>::max()) {
|
||||
m_string_may_be_number = false;
|
||||
return false;
|
||||
|
|
|
@ -1276,22 +1276,22 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
|
|||
// a. Let monthMV be 1.
|
||||
// 9. Else,
|
||||
// a. Let monthMV be ! ToIntegerOrInfinity(CodePointsToString(month)).
|
||||
auto month_mv = *month.value_or("1"sv).to_uint<u8>();
|
||||
auto month_mv = *month.value_or("1"sv).to_number<u8>();
|
||||
|
||||
// 10. If day is empty, then
|
||||
// a. Let dayMV be 1.
|
||||
// 11. Else,
|
||||
// a. Let dayMV be ! ToIntegerOrInfinity(CodePointsToString(day)).
|
||||
auto day_mv = *day.value_or("1"sv).to_uint<u8>();
|
||||
auto day_mv = *day.value_or("1"sv).to_number<u8>();
|
||||
|
||||
// 12. Let hourMV be ! ToIntegerOrInfinity(CodePointsToString(hour)).
|
||||
auto hour_mv = *hour.value_or("0"sv).to_uint<u8>();
|
||||
auto hour_mv = *hour.value_or("0"sv).to_number<u8>();
|
||||
|
||||
// 13. Let minuteMV be ! ToIntegerOrInfinity(CodePointsToString(minute)).
|
||||
auto minute_mv = *minute.value_or("0"sv).to_uint<u8>();
|
||||
auto minute_mv = *minute.value_or("0"sv).to_number<u8>();
|
||||
|
||||
// 14. Let secondMV be ! ToIntegerOrInfinity(CodePointsToString(second)).
|
||||
auto second_mv = *second.value_or("0"sv).to_uint<u8>();
|
||||
auto second_mv = *second.value_or("0"sv).to_number<u8>();
|
||||
|
||||
// 15. If secondMV is 60, then
|
||||
if (second_mv == 60) {
|
||||
|
@ -1532,19 +1532,19 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_seconds_part = parse_result->duration_seconds_fraction;
|
||||
|
||||
// 4. Let yearsMV be ! ToIntegerOrInfinity(CodePointsToString(years)).
|
||||
auto years = years_part.value_or("0"sv).to_double().release_value();
|
||||
auto years = years_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 5. Let monthsMV be ! ToIntegerOrInfinity(CodePointsToString(months)).
|
||||
auto months = months_part.value_or("0"sv).to_double().release_value();
|
||||
auto months = months_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 6. Let weeksMV be ! ToIntegerOrInfinity(CodePointsToString(weeks)).
|
||||
auto weeks = weeks_part.value_or("0"sv).to_double().release_value();
|
||||
auto weeks = weeks_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 7. Let daysMV be ! ToIntegerOrInfinity(CodePointsToString(days)).
|
||||
auto days = days_part.value_or("0"sv).to_double().release_value();
|
||||
auto days = days_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
// 8. Let hoursMV be ! ToIntegerOrInfinity(CodePointsToString(hours)).
|
||||
auto hours = hours_part.value_or("0"sv).to_double().release_value();
|
||||
auto hours = hours_part.value_or("0"sv).to_number<double>().release_value();
|
||||
|
||||
double minutes;
|
||||
|
||||
|
@ -1561,12 +1561,12 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_hours_scale = (double)f_hours_digits.length();
|
||||
|
||||
// d. Let minutesMV be ! ToIntegerOrInfinity(fHoursDigits) / 10^fHoursScale × 60.
|
||||
minutes = f_hours_digits.to_double().release_value() / pow(10., f_hours_scale) * 60;
|
||||
minutes = f_hours_digits.to_number<double>().release_value() / pow(10., f_hours_scale) * 60;
|
||||
}
|
||||
// 10. Else,
|
||||
else {
|
||||
// a. Let minutesMV be ! ToIntegerOrInfinity(CodePointsToString(minutes)).
|
||||
minutes = minutes_part.value_or("0"sv).to_double().release_value();
|
||||
minutes = minutes_part.value_or("0"sv).to_number<double>().release_value();
|
||||
}
|
||||
|
||||
double seconds;
|
||||
|
@ -1584,12 +1584,12 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_minutes_scale = (double)f_minutes_digits.length();
|
||||
|
||||
// d. Let secondsMV be ! ToIntegerOrInfinity(fMinutesDigits) / 10^fMinutesScale × 60.
|
||||
seconds = f_minutes_digits.to_double().release_value() / pow(10, f_minutes_scale) * 60;
|
||||
seconds = f_minutes_digits.to_number<double>().release_value() / pow(10, f_minutes_scale) * 60;
|
||||
}
|
||||
// 12. Else if seconds is not empty, then
|
||||
else if (seconds_part.has_value()) {
|
||||
// a. Let secondsMV be ! ToIntegerOrInfinity(CodePointsToString(seconds)).
|
||||
seconds = seconds_part.value_or("0"sv).to_double().release_value();
|
||||
seconds = seconds_part.value_or("0"sv).to_number<double>().release_value();
|
||||
}
|
||||
// 13. Else,
|
||||
else {
|
||||
|
@ -1608,7 +1608,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, StringV
|
|||
auto f_seconds_scale = (double)f_seconds_digits.length();
|
||||
|
||||
// c. Let millisecondsMV be ! ToIntegerOrInfinity(fSecondsDigits) / 10^fSecondsScale × 1000.
|
||||
milliseconds = f_seconds_digits.to_double().release_value() / pow(10, f_seconds_scale) * 1000;
|
||||
milliseconds = f_seconds_digits.to_number<double>().release_value() / pow(10, f_seconds_scale) * 1000;
|
||||
}
|
||||
// 15. Else,
|
||||
else {
|
||||
|
|
|
@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_seconds_getter)
|
|||
auto [s, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 });
|
||||
|
||||
// 5. Return 𝔽(s).
|
||||
return Value((double)s.to_base_deprecated(10).to_int<i64>().value());
|
||||
return Value((double)s.to_base_deprecated(10).to_number<i64>().value());
|
||||
}
|
||||
|
||||
// 8.3.4 get Temporal.Instant.prototype.epochMilliseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochmilliseconds
|
||||
|
@ -86,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_milliseconds_getter)
|
|||
auto [ms, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 });
|
||||
|
||||
// 5. Return 𝔽(ms).
|
||||
return Value((double)ms.to_base_deprecated(10).to_int<i64>().value());
|
||||
return Value((double)ms.to_base_deprecated(10).to_number<i64>().value());
|
||||
}
|
||||
|
||||
// 8.3.5 get Temporal.Instant.prototype.epochMicroseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochmicroseconds
|
||||
|
|
|
@ -360,7 +360,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_seconds_getter)
|
|||
auto s = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 }).quotient;
|
||||
|
||||
// 5. Return 𝔽(s).
|
||||
return Value((double)s.to_base_deprecated(10).to_int<i64>().value());
|
||||
return Value((double)s.to_base_deprecated(10).to_number<i64>().value());
|
||||
}
|
||||
|
||||
// 6.3.16 get Temporal.ZonedDateTime.prototype.epochMilliseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochmilliseconds
|
||||
|
@ -377,7 +377,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_milliseconds_getter)
|
|||
auto ms = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 }).quotient;
|
||||
|
||||
// 5. Return 𝔽(ms).
|
||||
return Value((double)ms.to_base_deprecated(10).to_int<i64>().value());
|
||||
return Value((double)ms.to_base_deprecated(10).to_number<i64>().value());
|
||||
}
|
||||
|
||||
// 6.3.17 get Temporal.ZonedDateTime.prototype.epochMicroseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochmicroseconds
|
||||
|
|
|
@ -677,7 +677,7 @@ double string_to_number(StringView string)
|
|||
return bigint.to_double();
|
||||
}
|
||||
|
||||
auto maybe_double = text.to_double(AK::TrimWhitespace::No);
|
||||
auto maybe_double = text.to_number<double>(AK::TrimWhitespace::No);
|
||||
if (!maybe_double.has_value())
|
||||
return NAN;
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ double Token::double_value() const
|
|||
}
|
||||
}
|
||||
// This should always be a valid double
|
||||
return value_string.to_double().release_value();
|
||||
return value_string.to_number<double>().release_value();
|
||||
}
|
||||
|
||||
static u32 hex2int(char x)
|
||||
|
|
|
@ -263,7 +263,7 @@ ErrorOr<Vector<Editor::HistoryEntry>> Editor::try_load_history(StringView path)
|
|||
Vector<HistoryEntry> history;
|
||||
for (auto& str : hist.split_view("\n\n"sv)) {
|
||||
auto it = str.find("::"sv).value_or(0);
|
||||
auto time = str.substring_view(0, it).to_int<time_t>().value_or(0);
|
||||
auto time = str.substring_view(0, it).to_number<time_t>().value_or(0);
|
||||
auto string = str.substring_view(it == 0 ? it : it + 2);
|
||||
history.append({ string, time });
|
||||
}
|
||||
|
@ -945,7 +945,7 @@ ErrorOr<void> Editor::handle_read_event()
|
|||
m_state = m_previous_free_state;
|
||||
auto is_in_paste = m_state == InputState::Paste;
|
||||
for (auto& parameter : ByteString::copy(csi_parameter_bytes).split(';')) {
|
||||
if (auto value = parameter.to_uint(); value.has_value())
|
||||
if (auto value = parameter.to_number<unsigned>(); value.has_value())
|
||||
csi_parameters.append(value.value());
|
||||
else
|
||||
csi_parameters.append(0);
|
||||
|
@ -2140,7 +2140,7 @@ Result<Vector<size_t, 2>, Editor::Error> Editor::vt_dsr()
|
|||
continue;
|
||||
}
|
||||
if (c == ';') {
|
||||
auto maybe_row = StringView { coordinate_buffer.data(), coordinate_buffer.size() }.to_uint();
|
||||
auto maybe_row = StringView { coordinate_buffer.data(), coordinate_buffer.size() }.to_number<unsigned>();
|
||||
if (!maybe_row.has_value())
|
||||
has_error = true;
|
||||
row = maybe_row.value_or(1u);
|
||||
|
@ -2166,7 +2166,7 @@ Result<Vector<size_t, 2>, Editor::Error> Editor::vt_dsr()
|
|||
continue;
|
||||
}
|
||||
if (c == 'R') {
|
||||
auto maybe_column = StringView { coordinate_buffer.data(), coordinate_buffer.size() }.to_uint();
|
||||
auto maybe_column = StringView { coordinate_buffer.data(), coordinate_buffer.size() }.to_number<unsigned>();
|
||||
if (!maybe_column.has_value())
|
||||
has_error = true;
|
||||
col = maybe_column.value_or(1u);
|
||||
|
|
|
@ -88,7 +88,7 @@ ErrorOr<NonnullRefPtr<Node const>> Node::try_find_from_help_url(URL const& url)
|
|||
return Error::from_string_view("Bad help page URL"sv);
|
||||
|
||||
auto const section = url.path_segment_at_index(0);
|
||||
auto maybe_section_number = section.to_uint();
|
||||
auto maybe_section_number = section.to_number<unsigned>();
|
||||
if (!maybe_section_number.has_value())
|
||||
return Error::from_string_view("Bad section number"sv);
|
||||
auto section_number = maybe_section_number.value();
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Manual {
|
|||
|
||||
ErrorOr<NonnullRefPtr<SectionNode>> SectionNode::try_create_from_number(StringView section)
|
||||
{
|
||||
auto maybe_section_number = section.to_uint<u32>();
|
||||
auto maybe_section_number = section.to_number<u32>();
|
||||
if (!maybe_section_number.has_value())
|
||||
return Error::from_string_literal("Section is not a number");
|
||||
auto section_number = maybe_section_number.release_value();
|
||||
|
|
|
@ -121,7 +121,7 @@ OwnPtr<List> List::parse(LineIterator& lines)
|
|||
continue;
|
||||
if (ch == '.' || ch == ')')
|
||||
if (i + 1 < line.length() && line[i + 1] == ' ') {
|
||||
auto maybe_start_number = line.substring_view(offset, i - offset).to_uint<size_t>();
|
||||
auto maybe_start_number = line.substring_view(offset, i - offset).to_number<size_t>();
|
||||
if (!maybe_start_number.has_value())
|
||||
break;
|
||||
if (first)
|
||||
|
|
|
@ -643,7 +643,7 @@ NonnullOwnPtr<Text::Node> Text::parse_link(Vector<Token>::ConstIterator& tokens)
|
|||
|
||||
auto width_string = dimensions.substring_view(1, *dimension_seperator - 1);
|
||||
if (!width_string.is_empty()) {
|
||||
auto width = width_string.to_int();
|
||||
auto width = width_string.to_number<int>();
|
||||
if (!width.has_value())
|
||||
return false;
|
||||
image_width = width;
|
||||
|
@ -652,7 +652,7 @@ NonnullOwnPtr<Text::Node> Text::parse_link(Vector<Token>::ConstIterator& tokens)
|
|||
auto height_start = *dimension_seperator + 1;
|
||||
if (height_start < dimensions.length()) {
|
||||
auto height_string = dimensions.substring_view(height_start);
|
||||
auto height = height_string.to_int();
|
||||
auto height = height_string.to_number<int>();
|
||||
if (!height.has_value())
|
||||
return false;
|
||||
image_height = height;
|
||||
|
|
|
@ -127,7 +127,7 @@ PDFErrorOr<Vector<ByteBuffer>> PS1FontProgram::parse_subroutines(Reader& reader)
|
|||
return error("Array index out of bounds");
|
||||
|
||||
if (isdigit(entry[0])) {
|
||||
auto maybe_encrypted_size = entry.to_int();
|
||||
auto maybe_encrypted_size = entry.to_number<int>();
|
||||
if (!maybe_encrypted_size.has_value())
|
||||
return error("Malformed array");
|
||||
auto rd = TRY(parse_word(reader));
|
||||
|
@ -191,7 +191,7 @@ PDFErrorOr<float> PS1FontProgram::parse_float(Reader& reader)
|
|||
|
||||
PDFErrorOr<int> PS1FontProgram::parse_int(Reader& reader)
|
||||
{
|
||||
auto maybe_int = TRY(parse_word(reader)).to_int();
|
||||
auto maybe_int = TRY(parse_word(reader)).to_number<int>();
|
||||
if (!maybe_int.has_value())
|
||||
return error("Invalid int");
|
||||
return maybe_int.value();
|
||||
|
|
|
@ -135,7 +135,7 @@ public:
|
|||
continue;
|
||||
}
|
||||
auto number = lexer.consume_while(isdigit);
|
||||
if (auto index = number.to_uint(); index.has_value() && result.n_capture_groups >= index.value()) {
|
||||
if (auto index = number.to_number<unsigned>(); index.has_value() && result.n_capture_groups >= index.value()) {
|
||||
builder.append(result.capture_group_matches[i][index.value() - 1].view.to_byte_string());
|
||||
} else {
|
||||
builder.appendff("\\{}", number);
|
||||
|
|
|
@ -415,7 +415,7 @@ bool PosixBasicParser::parse_simple_re(ByteCode& bytecode, size_t& match_length_
|
|||
size_t value = 0;
|
||||
while (match(TokenType::Char)) {
|
||||
auto c = m_parser_state.current_token.value().substring_view(0, 1);
|
||||
auto c_value = c.to_uint();
|
||||
auto c_value = c.to_number<unsigned>();
|
||||
if (!c_value.has_value())
|
||||
break;
|
||||
value *= 10;
|
||||
|
@ -615,7 +615,7 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_repetition_symbol(ByteCode& byteco
|
|||
number_builder.append(consume().value());
|
||||
}
|
||||
|
||||
auto maybe_minimum = number_builder.to_byte_string().to_uint();
|
||||
auto maybe_minimum = number_builder.to_byte_string().to_number<unsigned>();
|
||||
if (!maybe_minimum.has_value())
|
||||
return set_error(Error::InvalidBraceContent);
|
||||
|
||||
|
@ -644,7 +644,7 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_repetition_symbol(ByteCode& byteco
|
|||
number_builder.append(consume().value());
|
||||
}
|
||||
if (!number_builder.is_empty()) {
|
||||
auto value = number_builder.to_byte_string().to_uint();
|
||||
auto value = number_builder.to_byte_string().to_number<unsigned>();
|
||||
if (!value.has_value() || minimum > value.value() || *value > s_maximum_repetition_count)
|
||||
return set_error(Error::InvalidBraceContent);
|
||||
|
||||
|
@ -1206,7 +1206,7 @@ StringView ECMA262Parser::read_digits_as_string(ReadDigitsInitialZeroState initi
|
|||
|
||||
if (hex && !AK::StringUtils::convert_to_uint_from_hex(c).has_value())
|
||||
break;
|
||||
if (!hex && !c.to_uint().has_value())
|
||||
if (!hex && !c.to_number<unsigned>().has_value())
|
||||
break;
|
||||
|
||||
offset += consume().value().length();
|
||||
|
@ -1226,7 +1226,7 @@ Optional<unsigned> ECMA262Parser::read_digits(ECMA262Parser::ReadDigitsInitialZe
|
|||
return {};
|
||||
if (hex)
|
||||
return AK::StringUtils::convert_to_uint_from_hex(str);
|
||||
return str.to_uint();
|
||||
return str.to_number<unsigned>();
|
||||
}
|
||||
|
||||
bool ECMA262Parser::parse_quantifier(ByteCode& stack, size_t& match_length_minimum, ParseFlags flags)
|
||||
|
@ -1304,7 +1304,7 @@ bool ECMA262Parser::parse_interval_quantifier(Optional<u64>& repeat_min, Optiona
|
|||
auto low_bound_string = read_digits_as_string();
|
||||
chars_consumed += low_bound_string.length();
|
||||
|
||||
auto low_bound = low_bound_string.to_uint<u64>();
|
||||
auto low_bound = low_bound_string.to_number<u64>();
|
||||
|
||||
if (!low_bound.has_value()) {
|
||||
if (!m_should_use_browser_extended_grammar && done())
|
||||
|
@ -1320,7 +1320,7 @@ bool ECMA262Parser::parse_interval_quantifier(Optional<u64>& repeat_min, Optiona
|
|||
consume();
|
||||
++chars_consumed;
|
||||
auto high_bound_string = read_digits_as_string();
|
||||
auto high_bound = high_bound_string.to_uint<u64>();
|
||||
auto high_bound = high_bound_string.to_number<u64>();
|
||||
if (high_bound.has_value()) {
|
||||
repeat_max = high_bound.value();
|
||||
chars_consumed += high_bound_string.length();
|
||||
|
@ -1587,7 +1587,7 @@ bool ECMA262Parser::parse_character_escape(Vector<CompareTypeAndValuePair>& comp
|
|||
bool ECMA262Parser::parse_atom_escape(ByteCode& stack, size_t& match_length_minimum, ParseFlags flags)
|
||||
{
|
||||
if (auto escape_str = read_digits_as_string(ReadDigitsInitialZeroState::Disallow); !escape_str.is_empty()) {
|
||||
if (auto escape = escape_str.to_uint(); escape.has_value()) {
|
||||
if (auto escape = escape_str.to_number<unsigned>(); escape.has_value()) {
|
||||
// See if this is a "back"-reference (we've already parsed the group it refers to)
|
||||
auto maybe_length = m_parser_state.capture_group_minimum_lengths.get(escape.value());
|
||||
if (maybe_length.has_value()) {
|
||||
|
|
|
@ -129,7 +129,7 @@ static ErrorOr<bool> should_launch_server(ByteString const& pid_path)
|
|||
return contents.release_error();
|
||||
}
|
||||
|
||||
pid = StringView { contents.value() }.to_int<pid_t>();
|
||||
pid = StringView { contents.value() }.to_number<pid_t>();
|
||||
}
|
||||
|
||||
if (!pid.has_value()) {
|
||||
|
|
|
@ -241,7 +241,7 @@ Optional<double> Value::to_double() const
|
|||
return {};
|
||||
|
||||
return m_value->visit(
|
||||
[](ByteString const& value) -> Optional<double> { return value.to_double(); },
|
||||
[](ByteString const& value) -> Optional<double> { return value.to_number<double>(); },
|
||||
[](Integer auto value) -> Optional<double> { return static_cast<double>(value); },
|
||||
[](double value) -> Optional<double> { return value; },
|
||||
[](bool value) -> Optional<double> { return static_cast<double>(value); },
|
||||
|
|
|
@ -87,10 +87,7 @@ public:
|
|||
|
||||
return m_value->visit(
|
||||
[](ByteString const& value) -> Optional<T> {
|
||||
if constexpr (IsSigned<T>)
|
||||
return value.to_int<T>();
|
||||
else
|
||||
return value.to_uint<T>();
|
||||
return value.to_number<T>();
|
||||
},
|
||||
[](Integer auto value) -> Optional<T> {
|
||||
if (!AK::is_within_range<T>(value))
|
||||
|
|
|
@ -52,7 +52,7 @@ Optional<FlatPtr> kernel_base()
|
|||
|
||||
auto kernel_base_str = ByteString { file_content.value(), NoChomp };
|
||||
using AddressType = u64;
|
||||
auto maybe_kernel_base = kernel_base_str.to_uint<AddressType>();
|
||||
auto maybe_kernel_base = kernel_base_str.to_number<AddressType>();
|
||||
if (!maybe_kernel_base.has_value()) {
|
||||
s_kernel_base_state = KernelBaseState::Invalid;
|
||||
return {};
|
||||
|
|
|
@ -1248,7 +1248,7 @@ void Terminal::execute_osc_sequence(OscParameters parameters, u8 last_byte)
|
|||
return;
|
||||
}
|
||||
|
||||
auto command_number = stringview_ify(0).to_uint();
|
||||
auto command_number = stringview_ify(0).to_number<unsigned>();
|
||||
if (!command_number.has_value()) {
|
||||
unimplemented_osc_sequence(parameters, last_byte);
|
||||
return;
|
||||
|
@ -1288,9 +1288,9 @@ void Terminal::execute_osc_sequence(OscParameters parameters, u8 last_byte)
|
|||
if (parameters.size() < 2)
|
||||
dbgln("Atttempted to set window progress but gave too few parameters");
|
||||
else if (parameters.size() == 2)
|
||||
m_client.set_window_progress(stringview_ify(1).to_int().value_or(-1), 0);
|
||||
m_client.set_window_progress(stringview_ify(1).to_number<int>().value_or(-1), 0);
|
||||
else
|
||||
m_client.set_window_progress(stringview_ify(1).to_int().value_or(-1), stringview_ify(2).to_int().value_or(0));
|
||||
m_client.set_window_progress(stringview_ify(1).to_number<int>().value_or(-1), stringview_ify(2).to_number<int>().value_or(0));
|
||||
break;
|
||||
default:
|
||||
unimplemented_osc_sequence(parameters, last_byte);
|
||||
|
|
|
@ -3858,7 +3858,7 @@ ByteString Validator::Errors::find_instruction_name(SourceLocation const& locati
|
|||
if (!index.has_value() || !end_index.has_value())
|
||||
return ByteString::formatted("{}", location);
|
||||
|
||||
auto opcode = location.function_name().substring_view(index.value() + 1, end_index.value() - index.value() - 1).to_uint();
|
||||
auto opcode = location.function_name().substring_view(index.value() + 1, end_index.value() - index.value() - 1).to_number<unsigned>();
|
||||
if (!opcode.has_value())
|
||||
return ByteString::formatted("{}", location);
|
||||
|
||||
|
|
|
@ -99,14 +99,14 @@ Optional<i32> AriaData::parse_integer(Optional<String> const& value)
|
|||
{
|
||||
if (!value.has_value())
|
||||
return {};
|
||||
return value->bytes_as_string_view().to_int();
|
||||
return value->bytes_as_string_view().to_number<i32>();
|
||||
}
|
||||
|
||||
Optional<f64> AriaData::parse_number(Optional<String> const& value)
|
||||
{
|
||||
if (!value.has_value())
|
||||
return {};
|
||||
return value->bytes_as_string_view().to_double(TrimWhitespace::Yes);
|
||||
return value->to_number<double>(TrimWhitespace::Yes);
|
||||
}
|
||||
|
||||
Optional<String> AriaData::aria_active_descendant_or_default() const
|
||||
|
|
|
@ -835,7 +835,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
if (is_ndashdigit_dimension(first_value)) {
|
||||
auto const& dimension = first_value.token();
|
||||
int a = dimension.dimension_value_int();
|
||||
auto maybe_b = dimension.dimension_unit().bytes_as_string_view().substring_view(1).to_int();
|
||||
auto maybe_b = dimension.dimension_unit().bytes_as_string_view().substring_view(1).to_number<int>();
|
||||
if (maybe_b.has_value()) {
|
||||
transaction.commit();
|
||||
return Selector::SimpleSelector::ANPlusBPattern { a, maybe_b.value() };
|
||||
|
@ -845,7 +845,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
}
|
||||
// <dashndashdigit-ident>
|
||||
if (is_dashndashdigit_ident(first_value)) {
|
||||
auto maybe_b = first_value.token().ident().bytes_as_string_view().substring_view(2).to_int();
|
||||
auto maybe_b = first_value.token().ident().bytes_as_string_view().substring_view(2).to_number<int>();
|
||||
if (maybe_b.has_value()) {
|
||||
transaction.commit();
|
||||
return Selector::SimpleSelector::ANPlusBPattern { -1, maybe_b.value() };
|
||||
|
@ -958,7 +958,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
|
||||
// '+'?† <ndashdigit-ident>
|
||||
if (is_ndashdigit_ident(first_after_plus)) {
|
||||
auto maybe_b = first_after_plus.token().ident().bytes_as_string_view().substring_view(1).to_int();
|
||||
auto maybe_b = first_after_plus.token().ident().bytes_as_string_view().substring_view(1).to_number<int>();
|
||||
if (maybe_b.has_value()) {
|
||||
transaction.commit();
|
||||
return Selector::SimpleSelector::ANPlusBPattern { 1, maybe_b.value() };
|
||||
|
|
|
@ -578,7 +578,7 @@ double Tokenizer::convert_a_string_to_a_number(StringView string)
|
|||
{
|
||||
// FIXME: We already found the whole part, fraction part and exponent during
|
||||
// validation, we could probably skip
|
||||
return string.to_double(AK::TrimWhitespace::No).release_value();
|
||||
return string.to_number<double>(AK::TrimWhitespace::No).release_value();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-syntax-3/#consume-name
|
||||
|
|
|
@ -167,7 +167,7 @@ void on_max_age_attribute(ParsedCookie& parsed_cookie, StringView attribute_valu
|
|||
return;
|
||||
|
||||
// Let delta-seconds be the attribute-value converted to an integer.
|
||||
if (auto delta_seconds = attribute_value.to_int(); delta_seconds.has_value()) {
|
||||
if (auto delta_seconds = attribute_value.to_number<int>(); delta_seconds.has_value()) {
|
||||
if (*delta_seconds <= 0) {
|
||||
// If delta-seconds is less than or equal to zero (0), let expiry-time be the earliest representable date and time.
|
||||
parsed_cookie.expiry_time_from_max_age_attribute = UnixDateTime::earliest();
|
||||
|
@ -251,7 +251,7 @@ Optional<UnixDateTime> parse_date_time(StringView date_string)
|
|||
if (!all_of(token, isdigit))
|
||||
return false;
|
||||
|
||||
if (auto converted = token.to_uint(); converted.has_value()) {
|
||||
if (auto converted = token.to_number<unsigned>(); converted.has_value()) {
|
||||
result = *converted;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -342,11 +342,11 @@ ErrorOr<HeaderList::ExtractLengthResult> HeaderList::extract_length() const
|
|||
}
|
||||
|
||||
// 5. If candidateValue is the empty string or has a code point that is not an ASCII digit, then return null.
|
||||
// NOTE: to_uint does this for us.
|
||||
// NOTE: to_number does this for us.
|
||||
// 6. Return candidateValue, interpreted as decimal number.
|
||||
// NOTE: The spec doesn't say anything about trimming here, so we don't trim. If it contains a space, step 5 will cause us to return null.
|
||||
// FIXME: This will return an empty Optional if it cannot fit into a u64, is this correct?
|
||||
auto conversion_result = AK::StringUtils::convert_to_uint<u64>(candidate_value.value(), TrimWhitespace::No);
|
||||
auto conversion_result = candidate_value.value().to_number<u64>(TrimWhitespace::No);
|
||||
if (!conversion_result.has_value())
|
||||
return Empty {};
|
||||
return ExtractLengthResult { conversion_result.release_value() };
|
||||
|
@ -851,7 +851,7 @@ Optional<RangeHeaderValue> parse_single_range_header_value(ReadonlyBytes value)
|
|||
auto range_start = lexer.consume_while(is_ascii_digit);
|
||||
|
||||
// 5. Let rangeStartValue be rangeStart, interpreted as decimal number, if rangeStart is not the empty string; otherwise null.
|
||||
auto range_start_value = range_start.to_uint<u64>();
|
||||
auto range_start_value = range_start.to_number<u64>();
|
||||
|
||||
// 6. If the code point at position within data is not U+002D (-), then return failure.
|
||||
// 7. Advance position by 1.
|
||||
|
@ -862,7 +862,7 @@ Optional<RangeHeaderValue> parse_single_range_header_value(ReadonlyBytes value)
|
|||
auto range_end = lexer.consume_while(is_ascii_digit);
|
||||
|
||||
// 9. Let rangeEndValue be rangeEnd, interpreted as decimal number, if rangeEnd is not the empty string; otherwise null.
|
||||
auto range_end_value = range_end.to_uint<u64>();
|
||||
auto range_end_value = range_end.to_number<u64>();
|
||||
|
||||
// 10. If position is not past the end of data, then return failure.
|
||||
if (!lexer.is_eof())
|
||||
|
|
|
@ -176,7 +176,7 @@ unsigned HTMLImageElement::width() const
|
|||
|
||||
// NOTE: This step seems to not be in the spec, but all browsers do it.
|
||||
auto width_attr = deprecated_get_attribute(HTML::AttributeNames::width);
|
||||
if (auto converted = width_attr.to_uint(); converted.has_value())
|
||||
if (auto converted = width_attr.to_number<unsigned>(); converted.has_value())
|
||||
return *converted;
|
||||
|
||||
// ...or else the density-corrected intrinsic width and height of the image, in CSS pixels,
|
||||
|
@ -204,7 +204,7 @@ unsigned HTMLImageElement::height() const
|
|||
|
||||
// NOTE: This step seems to not be in the spec, but all browsers do it.
|
||||
auto height_attr = deprecated_get_attribute(HTML::AttributeNames::height);
|
||||
if (auto converted = height_attr.to_uint(); converted.has_value())
|
||||
if (auto converted = height_attr.to_number<unsigned>(); converted.has_value())
|
||||
return *converted;
|
||||
|
||||
// ...or else the density-corrected intrinsic height and height of the image, in CSS pixels,
|
||||
|
|
|
@ -193,7 +193,7 @@ Optional<ARIA::Role> HTMLSelectElement::default_role() const
|
|||
if (has_attribute(AttributeNames::multiple))
|
||||
return ARIA::Role::listbox;
|
||||
if (has_attribute(AttributeNames::size)) {
|
||||
auto size_attribute = deprecated_attribute(AttributeNames::size).to_int();
|
||||
auto size_attribute = deprecated_attribute(AttributeNames::size).to_number<int>();
|
||||
if (size_attribute.has_value() && size_attribute.value() > 1)
|
||||
return ARIA::Role::listbox;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ void HTMLTableElement::visit_edges(Cell::Visitor& visitor)
|
|||
|
||||
static unsigned parse_border(ByteString const& value)
|
||||
{
|
||||
return value.to_uint().value_or(0);
|
||||
return value.to_number<unsigned>().value_or(0);
|
||||
}
|
||||
|
||||
void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
|
|
|
@ -84,7 +84,7 @@ Optional<u32> parse_non_negative_integer(StringView string)
|
|||
Optional<double> parse_floating_point_number(StringView string)
|
||||
{
|
||||
// FIXME: Implement spec compliant floating point number parsing
|
||||
auto maybe_double = MUST(String::from_utf8(string)).to_number<double>(TrimWhitespace::Yes);
|
||||
auto maybe_double = string.to_number<double>(TrimWhitespace::Yes);
|
||||
if (!maybe_double.has_value())
|
||||
return {};
|
||||
if (!isfinite(maybe_double.value()))
|
||||
|
|
|
@ -4475,7 +4475,7 @@ RefPtr<CSS::StyleValue> parse_dimension_value(StringView string)
|
|||
number_string.append(*position);
|
||||
++position;
|
||||
}
|
||||
auto integer_value = number_string.string_view().to_int();
|
||||
auto integer_value = number_string.string_view().to_number<int>();
|
||||
|
||||
// 6. If position is past the end of input, then return value as a length.
|
||||
if (position == input.end())
|
||||
|
|
|
@ -269,8 +269,8 @@ descriptor_parser:
|
|||
auto last_character = descriptor.bytes_as_string_view().bytes().last();
|
||||
auto descriptor_without_last_character = descriptor.bytes_as_string_view().substring_view(0, descriptor.bytes_as_string_view().length() - 1);
|
||||
|
||||
auto as_int = descriptor_without_last_character.to_int<i32>();
|
||||
auto as_float = descriptor_without_last_character.to_float();
|
||||
auto as_int = descriptor_without_last_character.to_number<i32>();
|
||||
auto as_float = descriptor_without_last_character.to_number<float>();
|
||||
|
||||
// - If the descriptor consists of a valid non-negative integer followed by a U+0077 LATIN SMALL LETTER W character
|
||||
if (last_character == 'w' && as_int.has_value()) {
|
||||
|
|
|
@ -235,7 +235,7 @@ static T parse_boolean_feature(StringView value)
|
|||
return T::Yes;
|
||||
|
||||
// 4. Let parsed be the result of parsing value as an integer.
|
||||
auto parsed = value.to_int<i64>();
|
||||
auto parsed = value.to_number<i64>();
|
||||
|
||||
// 5. If parsed is an error, then set it to 0.
|
||||
if (!parsed.has_value())
|
||||
|
|
|
@ -24,8 +24,8 @@ void FrameBox::prepare_for_replaced_layout()
|
|||
VERIFY(dom_node().nested_browsing_context());
|
||||
|
||||
// FIXME: Do proper error checking, etc.
|
||||
set_natural_width(dom_node().deprecated_attribute(HTML::AttributeNames::width).to_int().value_or(300));
|
||||
set_natural_height(dom_node().deprecated_attribute(HTML::AttributeNames::height).to_int().value_or(150));
|
||||
set_natural_width(dom_node().deprecated_attribute(HTML::AttributeNames::width).to_number<int>().value_or(300));
|
||||
set_natural_height(dom_node().deprecated_attribute(HTML::AttributeNames::height).to_number<int>().value_or(150));
|
||||
}
|
||||
|
||||
void FrameBox::did_set_content_size()
|
||||
|
|
|
@ -72,7 +72,7 @@ void TableFormattingContext::compute_constrainedness()
|
|||
m_columns[column_index].is_constrained = true;
|
||||
}
|
||||
auto const& col_node = static_cast<HTML::HTMLTableColElement const&>(*column_box.dom_node());
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_uint().value_or(1);
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_number<unsigned>().value_or(1);
|
||||
column_index += span;
|
||||
});
|
||||
});
|
||||
|
@ -189,7 +189,7 @@ void TableFormattingContext::compute_outer_content_sizes()
|
|||
// The outer max-content width of a table-column or table-column-group is max(min-width, min(max-width, width)).
|
||||
m_columns[column_index].max_size = max(min_width, min(max_width, width));
|
||||
auto const& col_node = static_cast<HTML::HTMLTableColElement const&>(*column_box.dom_node());
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_uint().value_or(1);
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_number<unsigned>().value_or(1);
|
||||
column_index += span;
|
||||
});
|
||||
});
|
||||
|
@ -1380,7 +1380,7 @@ void TableFormattingContext::BorderConflictFinder::collect_conflicting_col_eleme
|
|||
for (auto* child_of_column_group = child->first_child(); child_of_column_group; child_of_column_group = child_of_column_group->next_sibling()) {
|
||||
VERIFY(child_of_column_group->display().is_table_column());
|
||||
auto const& col_node = static_cast<HTML::HTMLTableColElement const&>(*child_of_column_group->dom_node());
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_uint().value_or(1);
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_number<unsigned>().value_or(1);
|
||||
for (size_t i = column_index; i < column_index + span; ++i) {
|
||||
m_col_elements_by_index[i] = child_of_column_group;
|
||||
}
|
||||
|
@ -1744,7 +1744,7 @@ void TableFormattingContext::initialize_intrinsic_percentages_from_rows_or_colum
|
|||
m_columns[column_index].has_intrinsic_percentage = computed_values.max_width().is_percentage() || computed_values.width().is_percentage();
|
||||
m_columns[column_index].intrinsic_percentage = min(width_percentage, max_width_percentage);
|
||||
auto const& col_node = static_cast<HTML::HTMLTableColElement const&>(*column_box.dom_node());
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_uint().value_or(1);
|
||||
unsigned span = col_node.deprecated_attribute(HTML::AttributeNames::span).to_number<unsigned>().value_or(1);
|
||||
column_index += span;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ Optional<ViewBox> try_parse_view_box(StringView string)
|
|||
while (!lexer.is_eof()) {
|
||||
lexer.consume_while([](auto ch) { return is_ascii_space(ch); });
|
||||
auto token = lexer.consume_until([](auto ch) { return is_ascii_space(ch) && ch != ','; });
|
||||
auto maybe_number = token.to_float();
|
||||
auto maybe_number = token.to_number<float>();
|
||||
if (!maybe_number.has_value())
|
||||
return {};
|
||||
switch (state) {
|
||||
|
|
|
@ -253,7 +253,7 @@ ErrorOr<JsonValue, Client::WrappedError> Client::read_body_as_json()
|
|||
|
||||
for (auto const& header : m_request->headers()) {
|
||||
if (header.name.equals_ignoring_ascii_case("Content-Length"sv)) {
|
||||
content_length = header.value.to_uint<size_t>(TrimWhitespace::Yes).value_or(0);
|
||||
content_length = header.value.to_number<size_t>(TrimWhitespace::Yes).value_or(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -799,7 +799,7 @@ ErrorOr<Variant<Parser::EntityReference, ByteString>, ParseError> Parser::parse_
|
|||
auto decimal = TRY(expect_many(
|
||||
ranges_for_search<Range('0', '9')>(),
|
||||
"any of [0-9]"sv));
|
||||
code_point = decimal.to_uint<u32>();
|
||||
code_point = decimal.to_number<u32>();
|
||||
}
|
||||
|
||||
if (!code_point.has_value() || !s_characters.contains(*code_point))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue