diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-01-20 17:01:39 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-24 22:36:09 +0100 |
commit | f590cd1850027399ab7f0193ba97fa76b3a9cbab (patch) | |
tree | c081315ec020ff956bd8cc62ab2549def75bcc9e /Userland | |
parent | 45cf40653a03dab11c0739783446ff696a9a5b0a (diff) | |
download | serenity-f590cd1850027399ab7f0193ba97fa76b3a9cbab.zip |
AK+Userland: Make AK::decode_hex() return ErrorOr
This lets us propagate the reason why it failed up to the caller. :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/HexEditor/FindDialog.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/Filter.cpp | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Userland/Applications/HexEditor/FindDialog.cpp b/Userland/Applications/HexEditor/FindDialog.cpp index c1cb3399bf..a2531b2a26 100644 --- a/Userland/Applications/HexEditor/FindDialog.cpp +++ b/Userland/Applications/HexEditor/FindDialog.cpp @@ -77,8 +77,8 @@ Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId case OPTION_HEX_VALUE: { auto decoded = decode_hex(text_value.replace(" ", "", true)); - if (!decoded.has_value()) - return String("Input contains invalid hex values."); + if (decoded.is_error()) + return String::formatted("Input is invalid: {}", decoded.error().string_literal()); return decoded.value(); } diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp index f5c15fa326..929f78ffca 100644 --- a/Userland/Libraries/LibPDF/Filter.cpp +++ b/Userland/Libraries/LibPDF/Filter.cpp @@ -39,8 +39,12 @@ Optional<ByteBuffer> Filter::decode(ReadonlyBytes bytes, FlyString const& encodi Optional<ByteBuffer> Filter::decode_ascii_hex(ReadonlyBytes bytes) { - if (bytes.size() % 2 == 0) - return decode_hex(bytes); + if (bytes.size() % 2 == 0) { + auto decode_result = decode_hex(bytes); + if (decode_result.is_error()) + return {}; + return decode_result.release_value(); + } // FIXME: Integrate this padding into AK/Hex? |