mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
HexEditor: Prefer ErrorOr to Result in FindDialog
This commit is contained in:
parent
a42cf020ea
commit
b330d83be4
2 changed files with 9 additions and 17 deletions
|
@ -59,7 +59,7 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out
|
||||||
out_text = dialog->text_value();
|
out_text = dialog->text_value();
|
||||||
|
|
||||||
if (processed.is_error()) {
|
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;
|
result = ExecResult::Aborted;
|
||||||
} else {
|
} else {
|
||||||
out_buffer = move(processed.value());
|
out_buffer = move(processed.value());
|
||||||
|
@ -71,26 +71,18 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out
|
||||||
return result;
|
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);
|
dbgln("process_input opt={}", (int)opt);
|
||||||
|
VERIFY(!text_value.is_empty());
|
||||||
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case OPTION_ASCII_STRING: {
|
case OPTION_ASCII_STRING:
|
||||||
if (text_value.is_empty())
|
return ByteBuffer::copy(text_value.bytes());
|
||||||
return "Input is empty"_string;
|
|
||||||
|
|
||||||
return ByteBuffer::copy(text_value.bytes()).release_value_but_fixme_should_propagate_errors();
|
|
||||||
}
|
|
||||||
|
|
||||||
case OPTION_HEX_VALUE: {
|
case OPTION_HEX_VALUE: {
|
||||||
auto text_no_spaces = text_value.replace(" "sv, ""sv, ReplaceMode::All).release_value_but_fixme_should_propagate_errors();
|
auto text_no_spaces = text_value.replace(" "sv, ""sv, ReplaceMode::All);
|
||||||
ErrorOr<ByteBuffer> decoded = decode_hex(text_no_spaces);
|
return 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
static ErrorOr<NonnullRefPtr<FindDialog>> try_create();
|
static ErrorOr<NonnullRefPtr<FindDialog>> try_create();
|
||||||
|
|
||||||
private:
|
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; }
|
String text_value() const { return m_text_value; }
|
||||||
OptionId selected_option() const { return m_selected_option; }
|
OptionId selected_option() const { return m_selected_option; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue