1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:17:34 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -6,8 +6,8 @@
#include "FindDialog.h"
#include <AK/Array.h>
#include <AK/DeprecatedString.h>
#include <AK/Hex.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <Applications/HexEditor/FindDialogGML.h>
#include <LibGUI/BoxLayout.h>
@ -31,7 +31,7 @@ static constexpr Array<Option, 2> options = {
}
};
GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& out_buffer, bool& find_all)
GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, DeprecatedString& out_text, ByteBuffer& out_buffer, bool& find_all)
{
auto dialog = FindDialog::construct();
@ -67,13 +67,13 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out
return result;
}
Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId opt)
Result<ByteBuffer, DeprecatedString> FindDialog::process_input(DeprecatedString text_value, OptionId opt)
{
dbgln("process_input opt={}", (int)opt);
switch (opt) {
case OPTION_ASCII_STRING: {
if (text_value.is_empty())
return String("Input is empty");
return DeprecatedString("Input is empty");
return text_value.to_byte_buffer();
}
@ -81,7 +81,7 @@ Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId
case OPTION_HEX_VALUE: {
auto decoded = decode_hex(text_value.replace(" "sv, ""sv, ReplaceMode::All));
if (decoded.is_error())
return String::formatted("Input is invalid: {}", decoded.error().string_literal());
return DeprecatedString::formatted("Input is invalid: {}", decoded.error().string_literal());
return decoded.value();
}

View file

@ -19,12 +19,12 @@ class FindDialog : public GUI::Dialog {
C_OBJECT(FindDialog);
public:
static ExecResult show(GUI::Window* parent_window, String& out_tex, ByteBuffer& out_buffer, bool& find_all);
static ExecResult show(GUI::Window* parent_window, DeprecatedString& out_tex, ByteBuffer& out_buffer, bool& find_all);
private:
Result<ByteBuffer, String> process_input(String text_value, OptionId opt);
Result<ByteBuffer, DeprecatedString> process_input(DeprecatedString text_value, OptionId opt);
String text_value() const { return m_text_value; }
DeprecatedString 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 +37,6 @@ private:
RefPtr<GUI::Button> m_cancel_button;
bool m_find_all { false };
String m_text_value;
DeprecatedString m_text_value;
OptionId m_selected_option { OPTION_INVALID };
};

View file

@ -5,7 +5,7 @@
*/
#include "GoToOffsetDialog.h"
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <Applications/HexEditor/GoToOffsetDialogGML.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@ -27,7 +27,7 @@ GUI::Dialog::ExecResult GoToOffsetDialog::show(GUI::Window* parent_window, int&
dialog->set_icon(parent_window->icon());
if (history_offset)
dialog->m_text_editor->set_text(String::formatted("{}", history_offset));
dialog->m_text_editor->set_text(DeprecatedString::formatted("{}", history_offset));
auto result = dialog->exec();
@ -50,9 +50,9 @@ int GoToOffsetDialog::process_input()
int offset;
auto type = m_offset_type_box->text().trim_whitespace();
if (type == "Decimal") {
offset = String::formatted("{}", input_offset).to_int().value_or(0);
offset = DeprecatedString::formatted("{}", input_offset).to_int().value_or(0);
} else if (type == "Hexadecimal") {
offset = strtol(String::formatted("{}", input_offset).characters(), nullptr, 16);
offset = strtol(DeprecatedString::formatted("{}", input_offset).characters(), nullptr, 16);
} else {
VERIFY_NOT_REACHED();
}
@ -84,8 +84,8 @@ int GoToOffsetDialog::calculate_new_offset(int input_offset)
void GoToOffsetDialog::update_statusbar()
{
auto new_offset = calculate_new_offset(process_input());
m_statusbar->set_text(0, String::formatted("HEX: {:#08X}", new_offset));
m_statusbar->set_text(1, String::formatted("DEC: {}", new_offset));
m_statusbar->set_text(0, DeprecatedString::formatted("HEX: {:#08X}", new_offset));
m_statusbar->set_text(1, DeprecatedString::formatted("DEC: {}", new_offset));
}
GoToOffsetDialog::GoToOffsetDialog()
@ -108,14 +108,14 @@ GoToOffsetDialog::GoToOffsetDialog()
m_offset_type.append("Decimal");
m_offset_type.append("Hexadecimal");
m_offset_type_box->set_model(GUI::ItemListModel<String>::create(m_offset_type));
m_offset_type_box->set_model(GUI::ItemListModel<DeprecatedString>::create(m_offset_type));
m_offset_type_box->set_selected_index(0);
m_offset_type_box->set_only_allow_values_from_model(true);
m_offset_from.append("Start");
m_offset_from.append("Here");
m_offset_from.append("End");
m_offset_from_box->set_model(GUI::ItemListModel<String>::create(m_offset_from));
m_offset_from_box->set_model(GUI::ItemListModel<DeprecatedString>::create(m_offset_from));
m_offset_from_box->set_selected_index(0);
m_offset_from_box->set_only_allow_values_from_model(true);

View file

@ -24,8 +24,8 @@ private:
int calculate_new_offset(int offset);
int m_selection_offset { 0 };
int m_buffer_size { 0 };
Vector<String> m_offset_type;
Vector<String> m_offset_from;
Vector<DeprecatedString> m_offset_type;
Vector<DeprecatedString> m_offset_from;
RefPtr<GUI::TextEditor> m_text_editor;
RefPtr<GUI::Button> m_go_button;

View file

@ -89,7 +89,7 @@ public:
virtual void undo() override;
virtual void redo() override;
virtual String action_text() const override { return "Update cell"; }
virtual DeprecatedString action_text() const override { return "Update cell"; }
virtual bool merge_with(GUI::Command const& other) override;

View file

@ -590,7 +590,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
};
bool is_current_line = (m_position / bytes_per_row()) == i;
auto line = String::formatted("{:#08X}", i * bytes_per_row());
auto line = DeprecatedString::formatted("{:#08X}", i * bytes_per_row());
painter.draw_text(
side_offset_rect,
line,
@ -625,7 +625,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
};
const u8 cell_value = m_document->get(byte_position).value;
auto line = String::formatted("{:02X}", cell_value);
auto line = DeprecatedString::formatted("{:02X}", cell_value);
Gfx::Color background_color = palette().color(background_role());
Gfx::Color text_color = [&]() -> Gfx::Color {
@ -690,7 +690,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
}
painter.fill_rect(text_background_rect, background_color);
painter.draw_text(text_display_rect, String::formatted("{:c}", isprint(cell_value) ? cell_value : '.'), Gfx::TextAlignment::TopLeft, text_color);
painter.draw_text(text_display_rect, DeprecatedString::formatted("{:c}", isprint(cell_value) ? cell_value : '.'), Gfx::TextAlignment::TopLeft, text_color);
if (m_edit_mode == EditMode::Text) {
if (byte_position == m_position && m_cursor_blink_active) {
@ -768,7 +768,7 @@ Vector<Match> HexEditor::find_all(ByteBuffer& needle, size_t start)
}
}
if (found) {
matches.append({ i, String::formatted("{}", StringView { needle }.to_string().characters()) });
matches.append({ i, DeprecatedString::formatted("{}", StringView { needle }.to_string().characters()) });
i += needle.size() - 1;
}
}

View file

@ -61,11 +61,11 @@ HexEditorWidget::HexEditorWidget()
};
m_editor->on_status_change = [this](int position, HexEditor::EditMode edit_mode, int selection_start, int selection_end) {
m_statusbar->set_text(0, String::formatted("Offset: {:#08X}", position));
m_statusbar->set_text(1, String::formatted("Edit Mode: {}", edit_mode == HexEditor::EditMode::Hex ? "Hex" : "Text"));
m_statusbar->set_text(2, String::formatted("Selection Start: {}", selection_start));
m_statusbar->set_text(3, String::formatted("Selection End: {}", selection_end));
m_statusbar->set_text(4, String::formatted("Selected Bytes: {}", m_editor->selection_size()));
m_statusbar->set_text(0, DeprecatedString::formatted("Offset: {:#08X}", position));
m_statusbar->set_text(1, DeprecatedString::formatted("Edit Mode: {}", edit_mode == HexEditor::EditMode::Hex ? "Hex" : "Text"));
m_statusbar->set_text(2, DeprecatedString::formatted("Selection Start: {}", selection_start));
m_statusbar->set_text(3, DeprecatedString::formatted("Selection End: {}", selection_end));
m_statusbar->set_text(4, DeprecatedString::formatted("Selected Bytes: {}", m_editor->selection_size()));
bool has_selection = m_editor->has_selection();
m_copy_hex_action->set_enabled(has_selection);
@ -99,7 +99,7 @@ HexEditorWidget::HexEditorWidget()
};
m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) {
String value;
DeprecatedString value;
if (request_close() && GUI::InputBox::show(window(), value, "Enter new file size:"sv, "New file size"sv) == GUI::InputBox::ExecResult::OK && !value.is_empty()) {
auto file_size = value.to_uint();
if (!file_size.has_value()) {
@ -108,7 +108,7 @@ HexEditorWidget::HexEditorWidget()
}
if (auto error = m_editor->open_new_file(file_size.value()); error.is_error()) {
GUI::MessageBox::show(window(), String::formatted("Unable to open new file: {}"sv, error.error()), "Error"sv, GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), DeprecatedString::formatted("Unable to open new file: {}"sv, error.error()), "Error"sv, GUI::MessageBox::Type::Error);
return;
}
@ -176,11 +176,11 @@ HexEditorWidget::HexEditorWidget()
m_search_results->update();
if (matches.is_empty()) {
GUI::MessageBox::show(window(), String::formatted("Pattern \"{}\" not found in this file", m_search_text), "Not found"sv, GUI::MessageBox::Type::Warning);
GUI::MessageBox::show(window(), DeprecatedString::formatted("Pattern \"{}\" not found in this file", m_search_text), "Not found"sv, GUI::MessageBox::Type::Warning);
return;
}
GUI::MessageBox::show(window(), String::formatted("Found {} matches for \"{}\" in this file", matches.size(), m_search_text), String::formatted("{} matches", matches.size()), GUI::MessageBox::Type::Warning);
GUI::MessageBox::show(window(), DeprecatedString::formatted("Found {} matches for \"{}\" in this file", matches.size(), m_search_text), DeprecatedString::formatted("{} matches", matches.size()), GUI::MessageBox::Type::Warning);
set_search_results_visible(true);
} else {
bool same_buffers = false;
@ -192,7 +192,7 @@ HexEditorWidget::HexEditorWidget()
auto result = m_editor->find_and_highlight(m_search_buffer, same_buffers ? last_found_index() : 0);
if (!result.has_value()) {
GUI::MessageBox::show(window(), String::formatted("Pattern \"{}\" not found in this file", m_search_text), "Not found"sv, GUI::MessageBox::Type::Warning);
GUI::MessageBox::show(window(), DeprecatedString::formatted("Pattern \"{}\" not found in this file", m_search_text), "Not found"sv, GUI::MessageBox::Type::Warning);
return;
}
@ -242,7 +242,7 @@ HexEditorWidget::HexEditorWidget()
m_copy_as_c_code_action->set_enabled(false);
m_fill_selection_action = GUI::Action::create("Fill &Selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) {
String value;
DeprecatedString value;
if (GUI::InputBox::show(window(), value, "Fill byte (hex):"sv, "Fill Selection"sv) == GUI::InputBox::ExecResult::OK && !value.is_empty()) {
auto fill_byte = strtol(value.characters(), nullptr, 16);
m_editor->fill_selection(fill_byte);
@ -305,9 +305,9 @@ void HexEditorWidget::update_inspector_values(size_t position)
else
unsigned_byte_value = (unsigned_64_bit_int >> (64 - 8)) & 0xFF;
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, String::number(static_cast<i8>(unsigned_byte_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, String::number(unsigned_byte_value));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, String::formatted("{:c}", static_cast<char>(unsigned_byte_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, DeprecatedString::number(static_cast<i8>(unsigned_byte_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, DeprecatedString::number(unsigned_byte_value));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, DeprecatedString::formatted("{:c}", static_cast<char>(unsigned_byte_value)));
} else {
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, "");
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, "");
@ -321,8 +321,8 @@ void HexEditorWidget::update_inspector_values(size_t position)
else
unsigned_short_value = (unsigned_64_bit_int >> (64 - 16)) & 0xFFFF;
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, String::number(static_cast<i16>(unsigned_short_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, String::number(unsigned_short_value));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, DeprecatedString::number(static_cast<i16>(unsigned_short_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, DeprecatedString::number(unsigned_short_value));
} else {
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, "");
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, "");
@ -335,9 +335,9 @@ void HexEditorWidget::update_inspector_values(size_t position)
else
unsigned_int_value = (unsigned_64_bit_int >> 32) & 0xFFFFFFFF;
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, String::number(static_cast<i32>(unsigned_int_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, String::number(unsigned_int_value));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, String::number(bit_cast<float>(unsigned_int_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, DeprecatedString::number(static_cast<i32>(unsigned_int_value)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, DeprecatedString::number(unsigned_int_value));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, DeprecatedString::number(bit_cast<float>(unsigned_int_value)));
} else {
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, "");
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, "");
@ -345,9 +345,9 @@ void HexEditorWidget::update_inspector_values(size_t position)
}
if (byte_read_count >= 8) {
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, String::number(static_cast<i64>(unsigned_64_bit_int)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, String::number(unsigned_64_bit_int));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, String::number(bit_cast<double>(unsigned_64_bit_int)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, DeprecatedString::number(static_cast<i64>(unsigned_64_bit_int)));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, DeprecatedString::number(unsigned_64_bit_int));
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, DeprecatedString::number(bit_cast<double>(unsigned_64_bit_int)));
} else {
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, "");
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, "");
@ -418,7 +418,7 @@ void HexEditorWidget::initialize_menubar(GUI::Window& window)
auto result = m_editor->find_and_highlight(m_search_buffer, last_found_index());
if (!result.has_value()) {
GUI::MessageBox::show(&window, String::formatted("No more matches for \"{}\" found in this file", m_search_text), "Not found"sv, GUI::MessageBox::Type::Warning);
GUI::MessageBox::show(&window, DeprecatedString::formatted("No more matches for \"{}\" found in this file", m_search_text), "Not found"sv, GUI::MessageBox::Type::Warning);
return;
}
m_editor->update();
@ -459,7 +459,7 @@ void HexEditorWidget::initialize_menubar(GUI::Window& window)
m_bytes_per_row_actions.set_exclusive(true);
auto& bytes_per_row_menu = view_menu.add_submenu("Bytes per &Row");
for (int i = 8; i <= 32; i += 8) {
auto action = GUI::Action::create_checkable(String::number(i), [this, i](auto&) {
auto action = GUI::Action::create_checkable(DeprecatedString::number(i), [this, i](auto&) {
m_editor->set_bytes_per_row(i);
m_editor->update();
Config::write_i32("HexEditor"sv, "Layout"sv, "BytesPerRow"sv, i);

View file

@ -41,12 +41,12 @@ private:
virtual void drop_event(GUI::DropEvent&) override;
RefPtr<HexEditor> m_editor;
String m_path;
String m_name;
String m_extension;
DeprecatedString m_path;
DeprecatedString m_name;
DeprecatedString m_extension;
int m_goto_history { 0 };
String m_search_text;
DeprecatedString 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 };

View file

@ -6,16 +6,16 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Hex.h>
#include <AK/NonnullRefPtr.h>
#include <AK/String.h>
#include <AK/Utf8View.h>
#include <AK/Vector.h>
#include <LibGUI/Model.h>
struct Match {
u64 offset;
String value;
DeprecatedString value;
};
class SearchResultsModel final : public GUI::Model {
@ -40,7 +40,7 @@ public:
return 2;
}
String column_name(int column) const override
DeprecatedString column_name(int column) const override
{
switch (column) {
case Column::Offset:
@ -63,7 +63,7 @@ public:
auto& match = m_matches.at(index.row());
switch (index.column()) {
case Column::Offset:
return String::formatted("{:#08X}", match.offset);
return DeprecatedString::formatted("{:#08X}", match.offset);
case Column::Value: {
Utf8View utf8_view(match.value);
if (!utf8_view.validate())

View file

@ -6,9 +6,9 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Hex.h>
#include <AK/NonnullRefPtr.h>
#include <AK/String.h>
#include <AK/Utf16View.h>
#include <AK/Utf8View.h>
#include <AK/Vector.h>
@ -45,7 +45,7 @@ public:
set_parsed_value(static_cast<ValueType>(i), "");
}
void set_parsed_value(ValueType type, String value)
void set_parsed_value(ValueType type, DeprecatedString value)
{
m_values[type] = value;
}
@ -60,7 +60,7 @@ public:
return 2;
}
String column_name(int column) const override
DeprecatedString column_name(int column) const override
{
switch (column) {
case Column::Type:
@ -71,7 +71,7 @@ public:
VERIFY_NOT_REACHED();
}
String inspector_value_type_to_string(ValueType type) const
DeprecatedString inspector_value_type_to_string(ValueType type) const
{
switch (type) {
case SignedByte:
@ -156,5 +156,5 @@ public:
private:
bool m_is_little_endian = false;
Array<String, ValueType::__Count> m_values = {};
Array<DeprecatedString, ValueType::__Count> m_values = {};
};