1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 05:47:34 +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

@ -40,19 +40,19 @@ void TreeNode::sort_children_by_area() const
}
struct QueueEntry {
QueueEntry(DeprecatedString path, TreeNode* node)
QueueEntry(ByteString path, TreeNode* node)
: path(move(path))
, node(node) {};
DeprecatedString path;
ByteString path;
TreeNode* node { nullptr };
};
static MountInfo* find_mount_for_path(DeprecatedString path, Vector<MountInfo>& mounts)
static MountInfo* find_mount_for_path(ByteString path, Vector<MountInfo>& mounts)
{
MountInfo* result = nullptr;
size_t length = 0;
for (auto& mount_info : mounts) {
DeprecatedString& mount_point = mount_info.mount_point;
ByteString& mount_point = mount_info.mount_point;
if (path.starts_with(mount_point)) {
if (!result || mount_point.length() > length) {
result = &mount_info;
@ -81,7 +81,7 @@ HashMap<int, int> TreeNode::populate_filesize_tree(Vector<MountInfo>& mounts, Fu
StringBuilder builder = StringBuilder();
builder.append(m_name);
builder.append('/');
MountInfo* root_mount_info = find_mount_for_path(builder.to_deprecated_string(), mounts);
MountInfo* root_mount_info = find_mount_for_path(builder.to_byte_string(), mounts);
if (!root_mount_info) {
return error_accumulator;
}
@ -92,7 +92,7 @@ HashMap<int, int> TreeNode::populate_filesize_tree(Vector<MountInfo>& mounts, Fu
builder.append(queue_entry.path);
builder.append('/');
MountInfo* mount_info = find_mount_for_path(builder.to_deprecated_string(), mounts);
MountInfo* mount_info = find_mount_for_path(builder.to_byte_string(), mounts);
if (!mount_info || (mount_info != root_mount_info && mount_info->source != root_mount_info->source)) {
continue;
}
@ -123,7 +123,7 @@ HashMap<int, int> TreeNode::populate_filesize_tree(Vector<MountInfo>& mounts, Fu
} else {
auto st = st_or_error.release_value();
if (S_ISDIR(st.st_mode)) {
queue.enqueue(QueueEntry(builder.to_deprecated_string(), &child));
queue.enqueue(QueueEntry(builder.to_byte_string(), &child));
} else {
child.m_area = st.st_size;
}
@ -137,7 +137,7 @@ HashMap<int, int> TreeNode::populate_filesize_tree(Vector<MountInfo>& mounts, Fu
return error_accumulator;
}
Optional<TreeNode const&> TreeNode::child_with_name(DeprecatedString name) const
Optional<TreeNode const&> TreeNode::child_with_name(ByteString name) const
{
for (auto& child : *m_children) {
if (child.name() == name)

View file

@ -6,22 +6,22 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Forward.h>
#include <AK/OwnPtr.h>
#include <AK/Vector.h>
struct MountInfo {
DeprecatedString mount_point;
DeprecatedString source;
ByteString mount_point;
ByteString source;
};
class TreeNode final {
public:
TreeNode(DeprecatedString name)
TreeNode(ByteString name)
: m_name(move(name)) {};
DeprecatedString name() const { return m_name; }
ByteString name() const { return m_name; }
i64 area() const { return m_area; }
size_t num_children() const
{
@ -31,21 +31,21 @@ public:
return 0;
}
TreeNode const& child_at(size_t i) const { return m_children->at(i); }
Optional<TreeNode const&> child_with_name(DeprecatedString name) const;
Optional<TreeNode const&> child_with_name(ByteString name) const;
void sort_children_by_area() const;
HashMap<int, int> populate_filesize_tree(Vector<MountInfo>& mounts, Function<void(size_t)> on_progress);
private:
long long int update_totals();
DeprecatedString m_name;
ByteString m_name;
i64 m_area { 0 };
OwnPtr<Vector<TreeNode>> m_children;
};
class Tree {
public:
static ErrorOr<NonnullOwnPtr<Tree>> create(DeprecatedString root_name)
static ErrorOr<NonnullOwnPtr<Tree>> create(ByteString root_name)
{
return adopt_nonnull_own_or_enomem(new (nothrow) Tree(move(root_name)));
}
@ -57,7 +57,7 @@ public:
}
private:
Tree(DeprecatedString root_name)
Tree(ByteString root_name)
: m_root(move(root_name)) {};
TreeNode m_root;
};

View file

@ -9,7 +9,7 @@
#include "ProgressWindow.h"
#include "Tree.h"
#include <AK/Array.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/NumberFormat.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/Painter.h>
@ -97,7 +97,7 @@ void TreeMapWidget::paint_cell_frame(GUI::Painter& painter, TreeNode const& node
text_rect.take_from_top(font().presentation_size() + 1);
painter.draw_text(text_rect, human_readable_size(node.area()), font(), Gfx::TextAlignment::TopLeft, Color::Black);
} else {
painter.draw_text(text_rect, DeprecatedString::formatted("{} - {}", node.name(), human_readable_size(node.area())), font(), Gfx::TextAlignment::TopLeft, Color::Black);
painter.draw_text(text_rect, ByteString::formatted("{} - {}", node.name(), human_readable_size(node.area())), font(), Gfx::TextAlignment::TopLeft, Color::Black);
}
painter.clear_clip_rect();
}
@ -261,13 +261,13 @@ void TreeMapWidget::paint_event(GUI::PaintEvent& event)
}
}
Vector<DeprecatedString> TreeMapWidget::path_to_position(Gfx::IntPoint position)
Vector<ByteString> TreeMapWidget::path_to_position(Gfx::IntPoint position)
{
TreeNode const* node = path_node(m_viewpoint);
if (!node) {
return {};
}
Vector<DeprecatedString> path;
Vector<ByteString> path;
lay_out_children(*node, frame_inner_rect(), m_viewpoint, [&](TreeNode const& node, int, Gfx::IntRect const& rect, Gfx::IntRect const&, int, HasLabel, IsRemainder is_remainder) {
if (is_remainder == IsRemainder::No && rect.contains(position)) {
path.append(node.name());
@ -381,8 +381,8 @@ static ErrorOr<void> fill_mounts(Vector<MountInfo>& output)
TRY(json.as_array().try_for_each([&output](JsonValue const& value) -> ErrorOr<void> {
auto& filesystem_object = value.as_object();
MountInfo mount_info;
mount_info.mount_point = filesystem_object.get_deprecated_string("mount_point"sv).value_or({});
mount_info.source = filesystem_object.get_deprecated_string("source"sv).value_or("none");
mount_info.mount_point = filesystem_object.get_byte_string("mount_point"sv).value_or({});
mount_info.source = filesystem_object.get_byte_string("source"sv).value_or("none");
TRY(output.try_append(mount_info));
return {};
}));
@ -420,7 +420,7 @@ ErrorOr<void> TreeMapWidget::analyze(GUI::Statusbar& statusbar)
builder.append({ error, strlen(error) });
builder.append(" ("sv);
int value = errors.get(key).value();
builder.append(DeprecatedString::number(value));
builder.append(ByteString::number(value));
if (value == 1) {
builder.append(" time"sv);
} else {

View file

@ -7,7 +7,7 @@
#pragma once
#include "Tree.h"
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <LibGUI/Frame.h>
#include <LibGfx/Rect.h>
@ -50,11 +50,11 @@ private:
template<typename Function>
void lay_out_children(TreeNode const&, Gfx::IntRect const&, int depth, Function);
void paint_cell_frame(GUI::Painter&, TreeNode const&, Gfx::IntRect const&, Gfx::IntRect const&, int depth, HasLabel has_label) const;
Vector<DeprecatedString> path_to_position(Gfx::IntPoint);
Vector<ByteString> path_to_position(Gfx::IntPoint);
void recalculate_path_for_new_tree();
OwnPtr<Tree> m_tree;
Vector<DeprecatedString> m_path_segments;
Vector<ByteString> m_path_segments;
size_t m_viewpoint { 0 }; // Current position within m_path_segments.
void const* m_selected_node_cache;
};

View file

@ -28,7 +28,7 @@
static auto const APP_NAME = "Space Analyzer"_string;
static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& tree_map_widget, bool include_last_node = true)
static ByteString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& tree_map_widget, bool include_last_node = true)
{
StringBuilder path_builder;
for (size_t k = 0; k < tree_map_widget.path_size() - (include_last_node ? 0 : 1); k++) {
@ -38,7 +38,7 @@ static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMa
TreeNode const* node = tree_map_widget.path_node(k);
path_builder.append(node->name());
}
return path_builder.to_deprecated_string();
return path_builder.to_byte_string();
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
@ -72,7 +72,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
file_menu->add_action(GUI::Action::create("&Analyze", { KeyCode::Key_F5 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
// FIXME: Just modify the tree in memory instead of traversing the entire file system
if (auto result = tree_map_widget.analyze(statusbar); result.is_error()) {
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
GUI::MessageBox::show_error(window, ByteString::formatted("{}", result.error()));
}
}));
file_menu->add_separator();
@ -104,7 +104,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
GUI::Clipboard::the().set_plain_text(get_absolute_path_to_selected_node(tree_map_widget));
});
auto delete_action = GUI::CommonActions::make_delete_action([&](auto&) {
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
ByteString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
bool try_again = true;
while (try_again) {
try_again = false;
@ -112,7 +112,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto deletion_result = FileSystem::remove(selected_node_path, FileSystem::RecursionMode::Allowed);
if (deletion_result.is_error()) {
auto retry_message_result = GUI::MessageBox::show(window,
DeprecatedString::formatted("Failed to delete \"{}\": {}. Retry?",
ByteString::formatted("Failed to delete \"{}\": {}. Retry?",
selected_node_path,
deletion_result.error()),
"Deletion failed"sv,
@ -123,7 +123,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
} else {
GUI::MessageBox::show(window,
DeprecatedString::formatted("Successfully deleted \"{}\".", selected_node_path),
ByteString::formatted("Successfully deleted \"{}\".", selected_node_path),
"Deletion completed"sv,
GUI::MessageBox::Type::Information,
GUI::MessageBox::InputType::OK);
@ -131,7 +131,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
if (auto result = tree_map_widget.analyze(statusbar); result.is_error()) {
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
GUI::MessageBox::show_error(window, ByteString::formatted("{}", result.error()));
}
});
@ -165,14 +165,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// Sneakily set the window title here, while the StringBuilder holds the right amount of the path.
if (k == tree_map_widget.viewpoint())
window->set_title(DeprecatedString::formatted("{} - SpaceAnalyzer", builder.string_view()));
window->set_title(ByteString::formatted("{} - SpaceAnalyzer", builder.string_view()));
breadcrumbbar.append_segment(node->name(), GUI::FileIconProvider::icon_for_path(builder.string_view()).bitmap_for_size(16), builder.string_view(), MUST(builder.to_string()));
}
breadcrumbbar.set_selected_segment(tree_map_widget.viewpoint());
};
tree_map_widget.on_context_menu_request = [&](const GUI::ContextMenuEvent& event) {
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
ByteString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
if (selected_node_path.is_empty())
return;
delete_action->set_enabled(FileSystem::can_delete_or_move(selected_node_path));