mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature: - int StringType::to_int(bool& ok) const And replace it with sensible new signature: - Optional<int> StringType::to_int() const
This commit is contained in:
parent
15f4043a7a
commit
fdfda6dec2
55 changed files with 354 additions and 455 deletions
|
@ -35,10 +35,9 @@ SpinBox::SpinBox()
|
|||
m_editor = add<TextBox>();
|
||||
m_editor->set_text("0");
|
||||
m_editor->on_change = [this] {
|
||||
bool ok;
|
||||
int value = m_editor->text().to_uint(ok);
|
||||
if (ok)
|
||||
set_value(value);
|
||||
auto value = m_editor->text().to_uint();
|
||||
if (value.has_value())
|
||||
set_value(value.value());
|
||||
else
|
||||
m_editor->set_text(String::number(m_value));
|
||||
};
|
||||
|
|
|
@ -91,10 +91,9 @@ void TextEditor::create_actions()
|
|||
auto input_box = InputBox::construct("Line:", "Go to line", window());
|
||||
auto result = input_box->exec();
|
||||
if (result == InputBox::ExecOK) {
|
||||
bool ok;
|
||||
auto line_number = input_box->text_value().to_uint(ok);
|
||||
if (ok)
|
||||
set_cursor(line_number - 1, 0);
|
||||
auto line_number = input_box->text_value().to_uint();
|
||||
if (line_number.has_value())
|
||||
set_cursor(line_number.value() - 1, 0);
|
||||
}
|
||||
},
|
||||
this);
|
||||
|
|
|
@ -158,13 +158,8 @@ public:
|
|||
ASSERT(as_uint() <= INT32_MAX);
|
||||
return (int)as_uint();
|
||||
}
|
||||
if (is_string()) {
|
||||
bool ok;
|
||||
int value = as_string().to_int(ok);
|
||||
if (!ok)
|
||||
return 0;
|
||||
return value;
|
||||
}
|
||||
if (is_string())
|
||||
return as_string().to_int().value_or(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue