1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

HexEditor: Prefer ErrorOr to Result in FindDialog

This commit is contained in:
Tim Ledbetter 2024-02-07 22:21:25 +00:00 committed by Jelle Raaijmakers
parent a42cf020ea
commit b330d83be4
2 changed files with 9 additions and 17 deletions

View file

@ -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<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId opt)
ErrorOr<ByteBuffer> 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<ByteBuffer> 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();
}

View file

@ -25,7 +25,7 @@ public:
static ErrorOr<NonnullRefPtr<FindDialog>> try_create();
private:
Result<ByteBuffer, String> process_input(String text_value, OptionId opt);
static ErrorOr<ByteBuffer> process_input(StringView text_value, OptionId opt);
String text_value() const { return m_text_value; }
OptionId selected_option() const { return m_selected_option; }