diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-12 21:07:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-12 21:28:55 +0200 |
commit | fdfda6dec20101013bb33633e657f06ef2a1ea96 (patch) | |
tree | 2157f8281cd9bc33a6984455c4831c397d2bd30c /Applications/HexEditor | |
parent | 15f4043a7a80f52c0fa05c4e69771e758464cd20 (diff) | |
download | serenity-fdfda6dec20101013bb33633e657f06ef2a1ea96.zip |
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
Diffstat (limited to 'Applications/HexEditor')
-rw-r--r-- | Applications/HexEditor/HexEditorWidget.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 73bee7a7ef..f5c920af9e 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -82,11 +82,10 @@ HexEditorWidget::HexEditorWidget() auto input_box = GUI::InputBox::construct("Enter new file size:", "New file size", window()); if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto valid = false; - auto file_size = input_box->text_value().to_int(valid); - if (valid && file_size > 0) { + auto file_size = input_box->text_value().to_int(); + if (file_size.has_value() && file_size.value() > 0) { m_document_dirty = false; - m_editor->set_buffer(ByteBuffer::create_zeroed(file_size)); + m_editor->set_buffer(ByteBuffer::create_zeroed(file_size.value())); set_path(LexicalPath()); update_title(); } else { @@ -149,11 +148,9 @@ HexEditorWidget::HexEditorWidget() m_goto_decimal_offset_action = GUI::Action::create("Go To Offset (Decimal)...", { Mod_Ctrl | Mod_Shift, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) { auto input_box = GUI::InputBox::construct("Enter Decimal offset:", "Go To", window()); if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto valid = false; - auto new_offset = input_box->text_value().to_int(valid); - if (valid) { - m_editor->set_position(new_offset); - } + auto new_offset = input_box->text_value().to_int(); + if (new_offset.has_value()) + m_editor->set_position(new_offset.value()); } }); |