1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -80,7 +80,7 @@
namespace HackStudio {
ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(DeprecatedString path_to_project)
ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(ByteString path_to_project)
{
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) HackStudioWidget));
@ -174,7 +174,7 @@ ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(DeprecatedStri
return;
if (event.event_path.starts_with(widget->project().root_path())) {
DeprecatedString relative_path = LexicalPath::relative_path(event.event_path, widget->project().root_path());
ByteString relative_path = LexicalPath::relative_path(event.event_path, widget->project().root_path());
widget->handle_external_file_deletion(relative_path);
} else {
widget->handle_external_file_deletion(event.event_path);
@ -213,7 +213,7 @@ void HackStudioWidget::on_action_tab_change()
}
}
Vector<DeprecatedString> HackStudioWidget::read_recent_projects()
Vector<ByteString> HackStudioWidget::read_recent_projects()
{
auto json = Config::read_string("HackStudio"sv, "Global"sv, "RecentProjects"sv);
AK::JsonParser parser(json);
@ -225,7 +225,7 @@ Vector<DeprecatedString> HackStudioWidget::read_recent_projects()
if (!value.is_array())
return {};
Vector<DeprecatedString> paths;
Vector<ByteString> paths;
for (auto& json_value : value.as_array().values()) {
if (!json_value.is_string())
return {};
@ -235,7 +235,7 @@ Vector<DeprecatedString> HackStudioWidget::read_recent_projects()
return paths;
}
void HackStudioWidget::open_project(DeprecatedString const& root_path)
void HackStudioWidget::open_project(ByteString const& root_path)
{
if (warn_unsaved_changes("There are unsaved changes, do you want to save before closing current project?") == ContinueDecision::No)
return;
@ -280,20 +280,20 @@ void HackStudioWidget::open_project(DeprecatedString const& root_path)
if (recent_projects.size() > recent_projects_history_size)
recent_projects.shrink(recent_projects_history_size);
Config::write_string("HackStudio"sv, "Global"sv, "RecentProjects"sv, JsonArray(recent_projects).to_deprecated_string());
Config::write_string("HackStudio"sv, "Global"sv, "RecentProjects"sv, JsonArray(recent_projects).to_byte_string());
update_recent_projects_submenu();
}
Vector<DeprecatedString> HackStudioWidget::selected_file_paths() const
Vector<ByteString> HackStudioWidget::selected_file_paths() const
{
Vector<DeprecatedString> files;
Vector<ByteString> files;
m_project_tree_view->selection().for_each_index([&](const GUI::ModelIndex& index) {
DeprecatedString sub_path = index.data().as_string();
ByteString sub_path = index.data().as_string();
GUI::ModelIndex parent_or_invalid = index.parent();
while (parent_or_invalid.is_valid()) {
sub_path = DeprecatedString::formatted("{}/{}", parent_or_invalid.data().as_string(), sub_path);
sub_path = ByteString::formatted("{}/{}", parent_or_invalid.data().as_string(), sub_path);
parent_or_invalid = parent_or_invalid.parent();
}
@ -303,9 +303,9 @@ Vector<DeprecatedString> HackStudioWidget::selected_file_paths() const
return files;
}
bool HackStudioWidget::open_file(DeprecatedString const& full_filename, size_t line, size_t column)
bool HackStudioWidget::open_file(ByteString const& full_filename, size_t line, size_t column)
{
DeprecatedString filename = full_filename;
ByteString filename = full_filename;
if (full_filename.starts_with(project().root_path())) {
filename = LexicalPath::relative_path(full_filename, project().root_path());
}
@ -371,7 +371,7 @@ bool HackStudioWidget::open_file(DeprecatedString const& full_filename, size_t l
set_edit_mode(EditMode::Text);
DeprecatedString relative_file_path = filename;
ByteString relative_file_path = filename;
if (filename.starts_with(m_project->root_path()))
relative_file_path = filename.substring(m_project->root_path().length() + 1);
@ -390,16 +390,16 @@ bool HackStudioWidget::open_file(DeprecatedString const& full_filename, size_t l
return true;
}
void HackStudioWidget::close_file_in_all_editors(DeprecatedString const& filename)
void HackStudioWidget::close_file_in_all_editors(ByteString const& filename)
{
m_open_files.remove(filename);
m_open_files_vector.remove_all_matching(
[&filename](DeprecatedString const& element) { return element == filename; });
[&filename](ByteString const& element) { return element == filename; });
for (auto& editor_wrapper : m_all_editor_wrappers) {
Editor& editor = editor_wrapper->editor();
DeprecatedString editor_file_path = editor.code_document().file_path();
DeprecatedString relative_editor_file_path = LexicalPath::relative_path(editor_file_path, project().root_path());
ByteString editor_file_path = editor.code_document().file_path();
ByteString relative_editor_file_path = LexicalPath::relative_path(editor_file_path, project().root_path());
if (relative_editor_file_path == filename) {
if (m_open_files_vector.is_empty()) {
@ -515,7 +515,7 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> HackStudioWidget::create_project_tree_view_con
return project_tree_view_context_menu;
}
ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_file_action(DeprecatedString const& label, DeprecatedString const& icon, DeprecatedString const& extension)
ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_file_action(ByteString const& label, ByteString const& icon, ByteString const& extension)
{
auto icon_no_shadow = TRY(Gfx::Bitmap::load_from_file(icon));
return GUI::Action::create(label, icon_no_shadow, [this, extension](const GUI::Action&) {
@ -523,34 +523,34 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_file_action(Dep
if (GUI::InputBox::show(window(), filename, "Enter a name:"sv, "New File"sv) != GUI::InputBox::ExecResult::OK)
return;
if (!extension.is_empty() && !AK::StringUtils::ends_with(filename, DeprecatedString::formatted(".{}", extension), CaseSensitivity::CaseSensitive)) {
if (!extension.is_empty() && !AK::StringUtils::ends_with(filename, ByteString::formatted(".{}", extension), CaseSensitivity::CaseSensitive)) {
filename = String::formatted("{}.{}", filename, extension).release_value_but_fixme_should_propagate_errors();
}
auto path_to_selected = selected_file_paths();
DeprecatedString filepath;
ByteString filepath;
if (!path_to_selected.is_empty()) {
VERIFY(FileSystem::exists(path_to_selected.first()));
LexicalPath selected(path_to_selected.first());
DeprecatedString dir_path;
ByteString dir_path;
if (FileSystem::is_directory(selected.string()))
dir_path = selected.string();
else
dir_path = selected.dirname();
filepath = DeprecatedString::formatted("{}/", dir_path);
filepath = ByteString::formatted("{}/", dir_path);
}
filepath = DeprecatedString::formatted("{}{}", filepath, filename);
filepath = ByteString::formatted("{}{}", filepath, filename);
auto file_or_error = Core::File::open(filepath, Core::File::OpenMode::Write | Core::File::OpenMode::MustBeNew);
if (file_or_error.is_error()) {
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to create '{}': {}", filepath, file_or_error.error()));
GUI::MessageBox::show_error(window(), ByteString::formatted("Failed to create '{}': {}", filepath, file_or_error.error()));
return;
}
open_file(filepath);
@ -570,7 +570,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_directory_actio
if (!path_to_selected.is_empty()) {
LexicalPath selected(path_to_selected.first());
DeprecatedString dir_path;
ByteString dir_path;
if (FileSystem::is_directory(selected.string()))
dir_path = selected.string();
@ -580,7 +580,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_directory_actio
directory_name = String::formatted("{}/{}", dir_path, directory_name).release_value_but_fixme_should_propagate_errors();
}
auto formatted_dir_name = LexicalPath::canonicalized_path(DeprecatedString::formatted("{}/{}", m_project->model().root_path(), directory_name));
auto formatted_dir_name = LexicalPath::canonicalized_path(ByteString::formatted("{}/{}", m_project->model().root_path(), directory_name));
int rc = mkdir(formatted_dir_name.characters(), 0755);
if (rc < 0) {
GUI::MessageBox::show(window(), "Failed to create new directory"sv, "Error"sv, GUI::MessageBox::Type::Error);
@ -620,7 +620,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_copy_relative_path_action()
auto copy_relative_path_action = GUI::Action::create("Copy &Relative Path", [this](const GUI::Action&) {
auto paths = selected_file_paths();
VERIFY(!paths.is_empty());
auto paths_string = DeprecatedString::join('\n', paths);
auto paths_string = ByteString::join('\n', paths);
GUI::Clipboard::the().set_plain_text(paths_string);
});
copy_relative_path_action->set_enabled(true);
@ -634,10 +634,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_copy_full_path_action()
auto copy_full_path_action = GUI::Action::create("Copy &Full Path", [this](const GUI::Action&) {
auto paths = selected_file_paths();
VERIFY(!paths.is_empty());
Vector<DeprecatedString> full_paths;
Vector<ByteString> full_paths;
for (auto& path : paths)
full_paths.append(get_absolute_path(path));
auto paths_string = DeprecatedString::join('\n', full_paths);
auto paths_string = ByteString::join('\n', full_paths);
GUI::Clipboard::the().set_plain_text(paths_string);
});
copy_full_path_action->set_enabled(true);
@ -653,12 +653,12 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
if (files.is_empty())
return;
DeprecatedString message;
ByteString message;
if (files.size() == 1) {
LexicalPath file(files[0]);
message = DeprecatedString::formatted("Really remove \"{}\" from disk?", file.basename());
message = ByteString::formatted("Really remove \"{}\" from disk?", file.basename());
} else {
message = DeprecatedString::formatted("Really remove \"{}\" files from disk?", files.size());
message = ByteString::formatted("Really remove \"{}\" files from disk?", files.size());
}
auto result = GUI::MessageBox::show(window(),
@ -673,7 +673,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
struct stat st;
if (lstat(file.characters(), &st) < 0) {
GUI::MessageBox::show(window(),
DeprecatedString::formatted("lstat ({}) failed: {}", file, strerror(errno)),
ByteString::formatted("lstat ({}) failed: {}", file, strerror(errno)),
"Removal Failed"sv,
GUI::MessageBox::Type::Error);
break;
@ -684,12 +684,12 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
auto& error = result.error();
if (is_directory) {
GUI::MessageBox::show(window(),
DeprecatedString::formatted("Removing directory \"{}\" from the project failed: {}", file, error),
ByteString::formatted("Removing directory \"{}\" from the project failed: {}", file, error),
"Removal Failed"sv,
GUI::MessageBox::Type::Error);
} else {
GUI::MessageBox::show(window(),
DeprecatedString::formatted("Removing file \"{}\" from the project failed: {}", file, error),
ByteString::formatted("Removing file \"{}\" from the project failed: {}", file, error),
"Removal Failed"sv,
GUI::MessageBox::Type::Error);
}
@ -908,7 +908,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_as_action()
LexicalPath const old_path(old_filename);
auto suggested_path = FileSystem::absolute_path(old_path.string()).release_value_but_fixme_should_propagate_errors();
Optional<DeprecatedString> save_path = GUI::FilePicker::get_save_filepath(window(),
Optional<ByteString> save_path = GUI::FilePicker::get_save_filepath(window(),
old_filename.is_empty() ? "Untitled"sv : old_path.title(),
old_filename.is_empty() ? "txt"sv : old_path.extension(),
suggested_path);
@ -916,7 +916,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_as_action()
return;
}
DeprecatedString const relative_file_path = LexicalPath::relative_path(save_path.value(), m_project->root_path());
ByteString const relative_file_path = LexicalPath::relative_path(save_path.value(), m_project->root_path());
if (current_editor_wrapper().filename().is_empty()) {
current_editor_wrapper().set_filename(relative_file_path);
} else {
@ -1009,7 +1009,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_debug_action()
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/debug-run.png"sv));
return GUI::Action::create("&Debug", icon, [this](auto&) {
if (!FileSystem::exists(get_project_executable_path())) {
GUI::MessageBox::show(window(), DeprecatedString::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error"sv, GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), ByteString::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error"sv, GUI::MessageBox::Type::Error);
return;
}
if (Debugger::the().session()) {
@ -1104,7 +1104,7 @@ void HackStudioWidget::initialize_debugger()
});
}
DeprecatedString HackStudioWidget::get_full_path_of_serenity_source(DeprecatedString const& file)
ByteString HackStudioWidget::get_full_path_of_serenity_source(ByteString const& file)
{
auto path_parts = LexicalPath(file).parts();
while (!path_parts.is_empty() && path_parts[0] == "..") {
@ -1114,10 +1114,10 @@ DeprecatedString HackStudioWidget::get_full_path_of_serenity_source(DeprecatedSt
relative_path_builder.join('/', path_parts);
constexpr char SERENITY_LIBS_PREFIX[] = "/usr/src/serenity";
LexicalPath serenity_sources_base(SERENITY_LIBS_PREFIX);
return DeprecatedString::formatted("{}/{}", serenity_sources_base, relative_path_builder.to_deprecated_string());
return ByteString::formatted("{}/{}", serenity_sources_base, relative_path_builder.to_byte_string());
}
DeprecatedString HackStudioWidget::get_absolute_path(DeprecatedString const& path) const
ByteString HackStudioWidget::get_absolute_path(ByteString const& path) const
{
// TODO: We can probably do a more specific condition here, something like
// "if (file.starts_with("../Libraries/") || file.starts_with("../AK/"))"
@ -1127,9 +1127,9 @@ DeprecatedString HackStudioWidget::get_absolute_path(DeprecatedString const& pat
return m_project->to_absolute_path(path);
}
RefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(DeprecatedString const& filename)
RefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(ByteString const& filename)
{
DeprecatedString file_path = filename;
ByteString file_path = filename;
if (filename.starts_with("../"sv)) {
file_path = get_full_path_of_serenity_source(filename);
@ -1140,19 +1140,19 @@ RefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(DeprecatedString cons
return current_editor_wrapper();
}
DeprecatedString HackStudioWidget::get_project_executable_path() const
ByteString HackStudioWidget::get_project_executable_path() const
{
// FIXME: Dumb heuristic ahead!
// e.g /my/project => /my/project/project
// TODO: Perhaps a Makefile rule for getting the value of $(PROGRAM) would be better?
return DeprecatedString::formatted("{}/{}", m_project->root_path(), LexicalPath::basename(m_project->root_path()));
return ByteString::formatted("{}/{}", m_project->root_path(), LexicalPath::basename(m_project->root_path()));
}
void HackStudioWidget::build()
{
auto result = m_project_builder->build(active_file());
if (result.is_error()) {
GUI::MessageBox::show(window(), DeprecatedString::formatted("{}", result.error()), "Build Failed"sv, GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), ByteString::formatted("{}", result.error()), "Build Failed"sv, GUI::MessageBox::Type::Error);
m_build_action->set_enabled(true);
m_stop_action->set_enabled(false);
} else {
@ -1164,7 +1164,7 @@ void HackStudioWidget::run()
{
auto result = m_project_builder->run(active_file());
if (result.is_error()) {
GUI::MessageBox::show(window(), DeprecatedString::formatted("{}", result.error()), "Run Failed"sv, GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), ByteString::formatted("{}", result.error()), "Run Failed"sv, GUI::MessageBox::Type::Error);
m_run_action->set_enabled(true);
m_stop_action->set_enabled(false);
} else {
@ -1202,7 +1202,7 @@ void HackStudioWidget::set_current_editor_wrapper(RefPtr<EditorWrapper> editor_w
update_statusbar();
}
void HackStudioWidget::file_renamed(DeprecatedString const& old_name, DeprecatedString const& new_name)
void HackStudioWidget::file_renamed(ByteString const& old_name, ByteString const& new_name)
{
auto editor_or_none = m_all_editor_wrappers.first_matching([&old_name](auto const& editor) {
return editor->filename() == old_name;
@ -1272,11 +1272,11 @@ void HackStudioWidget::configure_project_tree_view()
void HackStudioWidget::create_open_files_view(GUI::Widget& parent)
{
m_open_files_view = parent.add<GUI::ListView>();
auto open_files_model = GUI::ItemListModel<DeprecatedString>::create(m_open_files_vector);
auto open_files_model = GUI::ItemListModel<ByteString>::create(m_open_files_vector);
m_open_files_view->set_model(open_files_model);
m_open_files_view->on_activation = [this](auto& index) {
open_file(index.data().to_deprecated_string());
open_file(index.data().to_byte_string());
};
}
@ -1638,7 +1638,7 @@ void HackStudioWidget::update_statusbar()
{
StringBuilder builder;
if (current_editor().has_selection()) {
DeprecatedString selected_text = current_editor().selected_text();
ByteString selected_text = current_editor().selected_text();
auto word_count = current_editor().number_of_selected_words();
builder.appendff("Selected: {:'d} {} ({:'d} {})", selected_text.length(), selected_text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
}
@ -1648,7 +1648,7 @@ void HackStudioWidget::update_statusbar()
m_statusbar->set_text(2, String::formatted("Ln {:'d} Col {:'d}", current_editor().cursor().line() + 1, current_editor().cursor().column()).release_value_but_fixme_should_propagate_errors());
}
void HackStudioWidget::handle_external_file_deletion(DeprecatedString const& filepath)
void HackStudioWidget::handle_external_file_deletion(ByteString const& filepath)
{
close_file_in_all_editors(filepath);
}
@ -1686,7 +1686,7 @@ HackStudioWidget::~HackStudioWidget()
stop_debugger_if_running();
}
HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(DeprecatedString const& prompt)
HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(ByteString const& prompt)
{
if (!any_document_is_dirty())
return ContinueDecision::Yes;
@ -1747,13 +1747,13 @@ void HackStudioWidget::update_toolbar_actions()
void HackStudioWidget::update_window_title()
{
window()->set_title(DeprecatedString::formatted("{} - {} - Hack Studio", m_current_editor_wrapper->filename_title(), m_project->name()));
window()->set_title(ByteString::formatted("{} - {} - Hack Studio", m_current_editor_wrapper->filename_title(), m_project->name()));
window()->set_modified(any_document_is_dirty());
}
void HackStudioWidget::update_current_editor_title()
{
current_editor_tab_widget().set_tab_title(current_editor_wrapper(), String::from_deprecated_string(current_editor_wrapper().filename_title()).release_value_but_fixme_should_propagate_errors());
current_editor_tab_widget().set_tab_title(current_editor_wrapper(), String::from_byte_string(current_editor_wrapper().filename_title()).release_value_but_fixme_should_propagate_errors());
}
void HackStudioWidget::on_cursor_change()
@ -1831,13 +1831,13 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_open_project_config
auto parent_directory = LexicalPath::dirname(Project::config_file_path);
auto absolute_config_file_path = LexicalPath::absolute_path(m_project->root_path(), Project::config_file_path);
DeprecatedString formatted_error_string_holder;
ByteString formatted_error_string_holder;
auto save_configuration_or_error = [&]() -> ErrorOr<void> {
if (FileSystem::exists(absolute_config_file_path))
return {};
if (FileSystem::exists(parent_directory) && !FileSystem::is_directory(parent_directory)) {
formatted_error_string_holder = DeprecatedString::formatted("Cannot create the '{}' directory because there is already a file with that name", parent_directory);
formatted_error_string_holder = ByteString::formatted("Cannot create the '{}' directory because there is already a file with that name", parent_directory);
return Error::from_string_view(formatted_error_string_holder.view());
}
@ -1854,7 +1854,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_open_project_config
return {};
}();
if (save_configuration_or_error.is_error()) {
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Saving configuration failed: {}.", save_configuration_or_error.error()));
GUI::MessageBox::show_error(window(), ByteString::formatted("Saving configuration failed: {}.", save_configuration_or_error.error()));
return;
}