From 81afa029ac149af03fb3a43246093bddfece6734 Mon Sep 17 00:00:00 2001 From: kamp Date: Mon, 14 Aug 2023 21:12:42 +0300 Subject: [PATCH] HexEditor: Replace DeprecatedString in FindDialog --- .../Applications/HexEditor/FindDialog.cpp | 20 +++++++++---------- Userland/Applications/HexEditor/FindDialog.h | 9 +++++---- .../Applications/HexEditor/HexEditorWidget.h | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Userland/Applications/HexEditor/FindDialog.cpp b/Userland/Applications/HexEditor/FindDialog.cpp index d3743d15ad..be4426955a 100644 --- a/Userland/Applications/HexEditor/FindDialog.cpp +++ b/Userland/Applications/HexEditor/FindDialog.cpp @@ -6,7 +6,6 @@ #include "FindDialog.h" #include -#include #include #include #include @@ -31,14 +30,14 @@ static constexpr Array options = { } }; -GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, DeprecatedString& out_text, ByteBuffer& out_buffer, bool& find_all) +GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& out_buffer, bool& find_all) { auto dialog = FindDialog::construct(); if (parent_window) dialog->set_icon(parent_window->icon()); - if (!out_text.is_empty() && !out_text.is_null()) + if (!out_text.is_empty()) dialog->m_text_editor->set_text(out_text); dialog->m_find_button->set_enabled(!dialog->m_text_editor->text().is_empty()); @@ -63,25 +62,26 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, DeprecatedS find_all = dialog->find_all(); - dbgln("Find: value={} option={} find_all={}", out_text.characters(), (int)selected_option, find_all); + dbgln("Find: value={} option={} find_all={}", out_text, (int)selected_option, find_all); return result; } -Result FindDialog::process_input(DeprecatedString text_value, OptionId opt) +Result FindDialog::process_input(String text_value, OptionId opt) { dbgln("process_input opt={}", (int)opt); switch (opt) { case OPTION_ASCII_STRING: { if (text_value.is_empty()) - return DeprecatedString("Input is empty"); + return "Input is empty"_string; - return text_value.to_byte_buffer(); + return ByteBuffer::copy(text_value.bytes()).release_value_but_fixme_should_propagate_errors(); } case OPTION_HEX_VALUE: { - auto decoded = decode_hex(text_value.replace(" "sv, ""sv, ReplaceMode::All)); + 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 DeprecatedString::formatted("Input is invalid: {}", decoded.error().string_literal()); + return String::formatted("Input is invalid: {}", decoded.error().string_literal()).release_value_but_fixme_should_propagate_errors(); return decoded.value(); } @@ -130,7 +130,7 @@ FindDialog::FindDialog() }; m_find_button->on_click = [this](auto) { - auto text = m_text_editor->text(); + auto text = String::from_deprecated_string(m_text_editor->text()).release_value_but_fixme_should_propagate_errors(); if (!text.is_empty()) { m_text_value = text; done(ExecResult::OK); diff --git a/Userland/Applications/HexEditor/FindDialog.h b/Userland/Applications/HexEditor/FindDialog.h index 1aaf2d9751..40c68184d4 100644 --- a/Userland/Applications/HexEditor/FindDialog.h +++ b/Userland/Applications/HexEditor/FindDialog.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include enum OptionId { @@ -19,12 +20,12 @@ class FindDialog : public GUI::Dialog { C_OBJECT(FindDialog); public: - static ExecResult show(GUI::Window* parent_window, DeprecatedString& out_tex, ByteBuffer& out_buffer, bool& find_all); + static ExecResult show(GUI::Window* parent_window, String& out_tex, ByteBuffer& out_buffer, bool& find_all); private: - Result process_input(DeprecatedString text_value, OptionId opt); + Result process_input(String text_value, OptionId opt); - DeprecatedString text_value() const { return m_text_value; } + String text_value() const { return m_text_value; } OptionId selected_option() const { return m_selected_option; } bool find_all() const { return m_find_all; } @@ -37,6 +38,6 @@ private: RefPtr m_cancel_button; bool m_find_all { false }; - DeprecatedString m_text_value; + String m_text_value; OptionId m_selected_option { OPTION_INVALID }; }; diff --git a/Userland/Applications/HexEditor/HexEditorWidget.h b/Userland/Applications/HexEditor/HexEditorWidget.h index 0bf47d0b5b..a18289a83b 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.h +++ b/Userland/Applications/HexEditor/HexEditorWidget.h @@ -46,7 +46,7 @@ private: DeprecatedString m_extension; int m_goto_history { 0 }; - DeprecatedString m_search_text; + String m_search_text; ByteBuffer m_search_buffer; int last_found_index() const { return m_last_found_index == -1 ? 0 : m_last_found_index; } int m_last_found_index { -1 };