From b330d83be47760835f911d9786a045115287b5bb Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 7 Feb 2024 22:21:25 +0000 Subject: [PATCH] HexEditor: Prefer ErrorOr to Result in FindDialog --- .../Applications/HexEditor/FindDialog.cpp | 24 +++++++------------ Userland/Applications/HexEditor/FindDialog.h | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Userland/Applications/HexEditor/FindDialog.cpp b/Userland/Applications/HexEditor/FindDialog.cpp index 9e36cc1c65..51b04e6930 100644 --- a/Userland/Applications/HexEditor/FindDialog.cpp +++ b/Userland/Applications/HexEditor/FindDialog.cpp @@ -59,7 +59,7 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out out_text = dialog->text_value(); if (processed.is_error()) { - GUI::MessageBox::show_error(parent_window, processed.error()); + GUI::MessageBox::show_error(parent_window, MUST(String::formatted("Input is invalid: {}", processed.release_error()))); result = ExecResult::Aborted; } else { out_buffer = move(processed.value()); @@ -71,26 +71,18 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out return result; } -Result FindDialog::process_input(String text_value, OptionId opt) +ErrorOr FindDialog::process_input(StringView text_value, OptionId opt) { dbgln("process_input opt={}", (int)opt); + VERIFY(!text_value.is_empty()); + switch (opt) { - case OPTION_ASCII_STRING: { - if (text_value.is_empty()) - return "Input is empty"_string; - - return ByteBuffer::copy(text_value.bytes()).release_value_but_fixme_should_propagate_errors(); - } - + case OPTION_ASCII_STRING: + return ByteBuffer::copy(text_value.bytes()); case OPTION_HEX_VALUE: { - auto text_no_spaces = text_value.replace(" "sv, ""sv, ReplaceMode::All).release_value_but_fixme_should_propagate_errors(); - ErrorOr decoded = decode_hex(text_no_spaces); - if (decoded.is_error()) - return String::formatted("Input is invalid: {}", decoded.error().string_literal()).release_value_but_fixme_should_propagate_errors(); - - return decoded.value(); + auto text_no_spaces = text_value.replace(" "sv, ""sv, ReplaceMode::All); + return decode_hex(text_no_spaces); } - default: VERIFY_NOT_REACHED(); } diff --git a/Userland/Applications/HexEditor/FindDialog.h b/Userland/Applications/HexEditor/FindDialog.h index 6f7fc12eca..122630e2f2 100644 --- a/Userland/Applications/HexEditor/FindDialog.h +++ b/Userland/Applications/HexEditor/FindDialog.h @@ -25,7 +25,7 @@ public: static ErrorOr> try_create(); private: - Result process_input(String text_value, OptionId opt); + static ErrorOr process_input(StringView text_value, OptionId opt); String text_value() const { return m_text_value; } OptionId selected_option() const { return m_selected_option; }