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

@ -71,7 +71,7 @@ void DiffViewer::paint_event(GUI::PaintEvent& event)
}
}
void DiffViewer::draw_line(GUI::Painter& painter, String const& line, size_t y_offset, LinePosition line_position, LineType line_type)
void DiffViewer::draw_line(GUI::Painter& painter, DeprecatedString const& line, size_t y_offset, LinePosition line_position, LineType line_type)
{
size_t line_width = font().width(line);
@ -131,7 +131,7 @@ Gfx::IntRect DiffViewer::separator_rect() const
frame_inner_rect().height() };
}
void DiffViewer::set_content(String const& original, String const& diff)
void DiffViewer::set_content(DeprecatedString const& original, DeprecatedString const& diff)
{
m_original_lines = split_to_lines(original);
m_hunks = Diff::parse_hunks(diff);
@ -147,7 +147,7 @@ DiffViewer::DiffViewer()
setup_properties();
}
DiffViewer::DiffViewer(String const& original, String const& diff)
DiffViewer::DiffViewer(DeprecatedString const& original, DeprecatedString const& diff)
: m_original_lines(split_to_lines(original))
, m_hunks(Diff::parse_hunks(diff))
{
@ -161,10 +161,10 @@ void DiffViewer::setup_properties()
set_foreground_role(ColorRole::BaseText);
}
Vector<String> DiffViewer::split_to_lines(String const& text)
Vector<DeprecatedString> DiffViewer::split_to_lines(DeprecatedString const& text)
{
// NOTE: This is slightly different than text.split('\n')
Vector<String> lines;
Vector<DeprecatedString> lines;
size_t next_line_start_index = 0;
for (size_t i = 0; i < text.length(); ++i) {
if (text[i] == '\n') {

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/Vector.h>
#include <LibDiff/Hunks.h>
#include <LibGUI/AbstractScrollableWidget.h>
@ -18,10 +18,10 @@ class DiffViewer final : public GUI::AbstractScrollableWidget {
public:
virtual ~DiffViewer() override = default;
void set_content(String const& original, String const& diff);
void set_content(DeprecatedString const& original, DeprecatedString const& diff);
private:
DiffViewer(String const& original, String const& diff);
DiffViewer(DeprecatedString const& original, DeprecatedString const& diff);
DiffViewer();
void setup_properties();
@ -43,9 +43,9 @@ private:
Missing,
};
void draw_line(GUI::Painter&, String const& line, size_t y_offset, LinePosition, LineType);
void draw_line(GUI::Painter&, DeprecatedString const& line, size_t y_offset, LinePosition, LineType);
static Vector<String> split_to_lines(String const& text);
static Vector<DeprecatedString> split_to_lines(DeprecatedString const& text);
static Gfx::Color red_background();
static Gfx::Color green_background();
@ -55,7 +55,7 @@ private:
Gfx::IntRect separator_rect() const;
Vector<String> m_original_lines;
Vector<DeprecatedString> m_original_lines;
Vector<Diff::Hunk> m_hunks;
};
}

View file

@ -8,12 +8,12 @@
namespace HackStudio {
NonnullRefPtr<GitFilesModel> GitFilesModel::create(Vector<String>&& files)
NonnullRefPtr<GitFilesModel> GitFilesModel::create(Vector<DeprecatedString>&& files)
{
return adopt_ref(*new GitFilesModel(move(files)));
}
GitFilesModel::GitFilesModel(Vector<String>&& files)
GitFilesModel::GitFilesModel(Vector<DeprecatedString>&& files)
: m_files(move(files))
{
}

View file

@ -14,12 +14,12 @@ namespace HackStudio {
class GitFilesModel final : public GUI::Model {
public:
static NonnullRefPtr<GitFilesModel> create(Vector<String>&& files);
static NonnullRefPtr<GitFilesModel> create(Vector<DeprecatedString>&& files);
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_files.size(); }
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return 1; }
virtual String column_name(int) const override
virtual DeprecatedString column_name(int) const override
{
return "";
}
@ -29,7 +29,7 @@ public:
virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex&) const override;
private:
explicit GitFilesModel(Vector<String>&& files);
Vector<String> m_files;
explicit GitFilesModel(Vector<DeprecatedString>&& files);
Vector<DeprecatedString> m_files;
};
}

View file

@ -13,7 +13,7 @@
namespace HackStudio {
// A "GitFileAction" is either the staging or the unstaging of a file.
using GitFileActionCallback = Function<void(String const& file)>;
using GitFileActionCallback = Function<void(DeprecatedString const& file)>;
class GitFilesView : public GUI::ListView {
C_OBJECT(GitFilesView)

View file

@ -9,7 +9,7 @@
namespace HackStudio {
GitRepo::CreateResult GitRepo::try_to_create(String const& repository_root)
GitRepo::CreateResult GitRepo::try_to_create(DeprecatedString const& repository_root)
{
if (!git_is_installed()) {
return { CreateResult::Type::GitProgramNotFound, nullptr };
@ -21,7 +21,7 @@ GitRepo::CreateResult GitRepo::try_to_create(String const& repository_root)
return { CreateResult::Type::Success, adopt_ref(*new GitRepo(repository_root)) };
}
RefPtr<GitRepo> GitRepo::initialize_repository(String const& repository_root)
RefPtr<GitRepo> GitRepo::initialize_repository(DeprecatedString const& repository_root)
{
auto res = command_wrapper({ "init" }, repository_root);
if (res.is_null())
@ -31,7 +31,7 @@ RefPtr<GitRepo> GitRepo::initialize_repository(String const& repository_root)
return adopt_ref(*new GitRepo(repository_root));
}
Vector<String> GitRepo::unstaged_files() const
Vector<DeprecatedString> GitRepo::unstaged_files() const
{
auto modified = modified_files();
auto untracked = untracked_files();
@ -39,7 +39,7 @@ Vector<String> GitRepo::unstaged_files() const
return modified;
}
//
Vector<String> GitRepo::staged_files() const
Vector<DeprecatedString> GitRepo::staged_files() const
{
auto raw_result = command({ "diff", "--cached", "--name-only" });
if (raw_result.is_null())
@ -47,7 +47,7 @@ Vector<String> GitRepo::staged_files() const
return parse_files_list(raw_result);
}
Vector<String> GitRepo::modified_files() const
Vector<DeprecatedString> GitRepo::modified_files() const
{
auto raw_result = command({ "ls-files", "--modified", "--exclude-standard" });
if (raw_result.is_null())
@ -55,7 +55,7 @@ Vector<String> GitRepo::modified_files() const
return parse_files_list(raw_result);
}
Vector<String> GitRepo::untracked_files() const
Vector<DeprecatedString> GitRepo::untracked_files() const
{
auto raw_result = command({ "ls-files", "--others", "--exclude-standard" });
if (raw_result.is_null())
@ -63,22 +63,22 @@ Vector<String> GitRepo::untracked_files() const
return parse_files_list(raw_result);
}
Vector<String> GitRepo::parse_files_list(String const& raw_result)
Vector<DeprecatedString> GitRepo::parse_files_list(DeprecatedString const& raw_result)
{
auto lines = raw_result.split('\n');
Vector<String> files;
Vector<DeprecatedString> files;
for (auto const& line : lines) {
files.empend(line);
}
return files;
}
String GitRepo::command(Vector<String> const& command_parts) const
DeprecatedString GitRepo::command(Vector<DeprecatedString> const& command_parts) const
{
return command_wrapper(command_parts, m_repository_root);
}
String GitRepo::command_wrapper(Vector<String> const& command_parts, String const& chdir)
DeprecatedString GitRepo::command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir)
{
auto result = Core::command("git", command_parts, LexicalPath(chdir));
if (result.is_error() || result.value().exit_code != 0)
@ -91,37 +91,37 @@ bool GitRepo::git_is_installed()
return !command_wrapper({ "--help" }, "/").is_null();
}
bool GitRepo::git_repo_exists(String const& repo_root)
bool GitRepo::git_repo_exists(DeprecatedString const& repo_root)
{
return !command_wrapper({ "status" }, repo_root).is_null();
}
bool GitRepo::stage(String const& file)
bool GitRepo::stage(DeprecatedString const& file)
{
return !command({ "add", file }).is_null();
}
bool GitRepo::unstage(String const& file)
bool GitRepo::unstage(DeprecatedString const& file)
{
return !command({ "reset", "HEAD", "--", file }).is_null();
}
bool GitRepo::commit(String const& message)
bool GitRepo::commit(DeprecatedString const& message)
{
return !command({ "commit", "-m", message }).is_null();
}
Optional<String> GitRepo::original_file_content(String const& file) const
Optional<DeprecatedString> GitRepo::original_file_content(DeprecatedString const& file) const
{
return command({ "show", String::formatted("HEAD:{}", file) });
return command({ "show", DeprecatedString::formatted("HEAD:{}", file) });
}
Optional<String> GitRepo::unstaged_diff(String const& file) const
Optional<DeprecatedString> GitRepo::unstaged_diff(DeprecatedString const& file) const
{
return command({ "diff", file.characters() });
}
bool GitRepo::is_tracked(String const& file) const
bool GitRepo::is_tracked(DeprecatedString const& file) const
{
auto res = command({ "ls-files", file });
if (res.is_null())

View file

@ -7,11 +7,11 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/Optional.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/Vector.h>
namespace HackStudio {
@ -28,37 +28,37 @@ public:
RefPtr<GitRepo> repo;
};
static CreateResult try_to_create(String const& repository_root);
static RefPtr<GitRepo> initialize_repository(String const& repository_root);
static CreateResult try_to_create(DeprecatedString const& repository_root);
static RefPtr<GitRepo> initialize_repository(DeprecatedString const& repository_root);
bool stage(String const& file);
bool unstage(String const& file);
bool commit(String const& message);
bool is_tracked(String const& file) const;
bool stage(DeprecatedString const& file);
bool unstage(DeprecatedString const& file);
bool commit(DeprecatedString const& message);
bool is_tracked(DeprecatedString const& file) const;
Vector<String> unstaged_files() const;
Vector<String> staged_files() const;
Optional<String> original_file_content(String const& file) const;
Optional<String> unstaged_diff(String const& file) const;
Vector<DeprecatedString> unstaged_files() const;
Vector<DeprecatedString> staged_files() const;
Optional<DeprecatedString> original_file_content(DeprecatedString const& file) const;
Optional<DeprecatedString> unstaged_diff(DeprecatedString const& file) const;
private:
static bool git_is_installed();
static bool git_repo_exists(String const& repo_root);
static bool git_repo_exists(DeprecatedString const& repo_root);
static String command_wrapper(Vector<String> const& command_parts, String const& chdir);
static Vector<String> parse_files_list(String const&);
static DeprecatedString command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir);
static Vector<DeprecatedString> parse_files_list(DeprecatedString const&);
explicit GitRepo(String const& repository_root)
explicit GitRepo(DeprecatedString const& repository_root)
: m_repository_root(repository_root)
{
}
Vector<String> modified_files() const;
Vector<String> untracked_files() const;
Vector<DeprecatedString> modified_files() const;
Vector<DeprecatedString> untracked_files() const;
String command(Vector<String> const& command_parts) const;
DeprecatedString command(Vector<DeprecatedString> const& command_parts) const;
String m_repository_root;
DeprecatedString m_repository_root;
};
}

View file

@ -21,7 +21,7 @@
namespace HackStudio {
GitWidget::GitWidget(String const& repo_root)
GitWidget::GitWidget(DeprecatedString const& repo_root)
: m_repo_root(repo_root)
{
set_layout<GUI::HorizontalBoxLayout>();
@ -117,7 +117,7 @@ void GitWidget::refresh()
m_staged_files->set_model(GitFilesModel::create(m_git_repo->staged_files()));
}
void GitWidget::stage_file(String const& file)
void GitWidget::stage_file(DeprecatedString const& file)
{
dbgln("staging: {}", file);
bool rc = m_git_repo->stage(file);
@ -125,7 +125,7 @@ void GitWidget::stage_file(String const& file)
refresh();
}
void GitWidget::unstage_file(String const& file)
void GitWidget::unstage_file(DeprecatedString const& file)
{
dbgln("unstaging: {}", file);
bool rc = m_git_repo->unstage(file);
@ -153,7 +153,7 @@ void GitWidget::set_view_diff_callback(ViewDiffCallback callback)
m_view_diff_callback = move(callback);
}
void GitWidget::show_diff(String const& file_path)
void GitWidget::show_diff(DeprecatedString const& file_path)
{
if (!m_git_repo->is_tracked(file_path)) {
auto file = Core::File::construct(file_path);
@ -163,7 +163,7 @@ void GitWidget::show_diff(String const& file_path)
}
auto content = file->read_all();
String content_string((char*)content.data(), content.size());
DeprecatedString content_string((char*)content.data(), content.size());
m_view_diff_callback("", Diff::generate_only_additions(content_string));
return;
}
@ -173,7 +173,7 @@ void GitWidget::show_diff(String const& file_path)
m_view_diff_callback(original_content.value(), diff.value());
}
void GitWidget::change_repo(String const& repo_root)
void GitWidget::change_repo(DeprecatedString const& repo_root)
{
m_repo_root = repo_root;
m_git_repo = nullptr;

View file

@ -14,7 +14,7 @@
namespace HackStudio {
using ViewDiffCallback = Function<void(String const& original_content, String const& diff)>;
using ViewDiffCallback = Function<void(DeprecatedString const& original_content, DeprecatedString const& diff)>;
class GitWidget final : public GUI::Widget {
C_OBJECT(GitWidget)
@ -24,19 +24,19 @@ public:
void refresh();
void set_view_diff_callback(ViewDiffCallback callback);
bool initialized() const { return !m_git_repo.is_null(); };
void change_repo(String const& repo_root);
void change_repo(DeprecatedString const& repo_root);
private:
explicit GitWidget(String const& repo_root);
explicit GitWidget(DeprecatedString const& repo_root);
bool initialize();
bool initialize_if_needed();
void stage_file(String const&);
void unstage_file(String const&);
void stage_file(DeprecatedString const&);
void unstage_file(DeprecatedString const&);
void commit();
void show_diff(String const&);
void show_diff(DeprecatedString const&);
String m_repo_root;
DeprecatedString m_repo_root;
RefPtr<GitFilesView> m_unstaged_files;
RefPtr<GitFilesView> m_staged_files;
RefPtr<GitRepo> m_git_repo;