mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all its users with one of the following: - A normal, empty DeprecatedString - Optional<DeprecatedString> Note that null states of DeprecatedFlyString/StringView/etc are *not* affected by this commit. However, DeprecatedString::empty() is now considered equal to a null StringView.
This commit is contained in:
parent
daf6d8173c
commit
aeee98b3a1
189 changed files with 597 additions and 652 deletions
|
@ -47,7 +47,7 @@ Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(Debug::Proces
|
|||
if (frame_index > 0)
|
||||
--current_instruction;
|
||||
DeprecatedString name = lib->debug_info->elf().symbolicate(current_instruction - lib->base_address);
|
||||
if (name.is_null()) {
|
||||
if (name.is_empty()) {
|
||||
dbgln("BacktraceModel: couldn't find containing function for address: {:p} (library={})", current_instruction, lib->name);
|
||||
name = "<missing>";
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ void Debugger::start()
|
|||
|
||||
Debugger::CreateDebugSessionResult Debugger::create_debug_session()
|
||||
{
|
||||
if (!m_executable_path.is_null()) {
|
||||
if (!m_executable_path.is_empty()) {
|
||||
auto child_setup_callback = [this]() {
|
||||
if (m_child_setup_callback)
|
||||
return m_child_setup_callback();
|
||||
|
|
|
@ -113,7 +113,7 @@ void EditorWrapper::set_project_root(DeprecatedString const& project_root)
|
|||
void EditorWrapper::update_title()
|
||||
{
|
||||
StringBuilder title;
|
||||
if (m_filename.is_null())
|
||||
if (m_filename.is_empty())
|
||||
title.append(untitled_label);
|
||||
else
|
||||
title.append(m_filename);
|
||||
|
|
|
@ -24,7 +24,7 @@ GitRepo::CreateResult GitRepo::try_to_create(DeprecatedString const& repository_
|
|||
RefPtr<GitRepo> GitRepo::initialize_repository(DeprecatedString const& repository_root)
|
||||
{
|
||||
auto res = command_wrapper({ "init" }, repository_root);
|
||||
if (res.is_null())
|
||||
if (!res.has_value())
|
||||
return {};
|
||||
|
||||
VERIFY(git_repo_exists(repository_root));
|
||||
|
@ -42,25 +42,25 @@ Vector<DeprecatedString> GitRepo::unstaged_files() const
|
|||
Vector<DeprecatedString> GitRepo::staged_files() const
|
||||
{
|
||||
auto raw_result = command({ "diff", "--cached", "--name-only" });
|
||||
if (raw_result.is_null())
|
||||
if (!raw_result.has_value())
|
||||
return {};
|
||||
return parse_files_list(raw_result);
|
||||
return parse_files_list(*raw_result);
|
||||
}
|
||||
|
||||
Vector<DeprecatedString> GitRepo::modified_files() const
|
||||
{
|
||||
auto raw_result = command({ "ls-files", "--modified", "--exclude-standard" });
|
||||
if (raw_result.is_null())
|
||||
if (!raw_result.has_value())
|
||||
return {};
|
||||
return parse_files_list(raw_result);
|
||||
return parse_files_list(*raw_result);
|
||||
}
|
||||
|
||||
Vector<DeprecatedString> GitRepo::untracked_files() const
|
||||
{
|
||||
auto raw_result = command({ "ls-files", "--others", "--exclude-standard" });
|
||||
if (raw_result.is_null())
|
||||
if (!raw_result.has_value())
|
||||
return {};
|
||||
return parse_files_list(raw_result);
|
||||
return parse_files_list(*raw_result);
|
||||
}
|
||||
|
||||
Vector<DeprecatedString> GitRepo::parse_files_list(DeprecatedString const& raw_result)
|
||||
|
@ -73,12 +73,12 @@ Vector<DeprecatedString> GitRepo::parse_files_list(DeprecatedString const& raw_r
|
|||
return files;
|
||||
}
|
||||
|
||||
DeprecatedString GitRepo::command(Vector<DeprecatedString> const& command_parts) const
|
||||
Optional<DeprecatedString> GitRepo::command(Vector<DeprecatedString> const& command_parts) const
|
||||
{
|
||||
return command_wrapper(command_parts, m_repository_root);
|
||||
}
|
||||
|
||||
DeprecatedString GitRepo::command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir)
|
||||
Optional<DeprecatedString> GitRepo::command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir)
|
||||
{
|
||||
auto const result = Core::command("git", command_parts, LexicalPath(chdir));
|
||||
if (result.is_error() || result.value().exit_code != 0)
|
||||
|
@ -88,27 +88,27 @@ DeprecatedString GitRepo::command_wrapper(Vector<DeprecatedString> const& comman
|
|||
|
||||
bool GitRepo::git_is_installed()
|
||||
{
|
||||
return !command_wrapper({ "--help" }, "/").is_null();
|
||||
return command_wrapper({ "--help" }, "/").has_value();
|
||||
}
|
||||
|
||||
bool GitRepo::git_repo_exists(DeprecatedString const& repo_root)
|
||||
{
|
||||
return !command_wrapper({ "status" }, repo_root).is_null();
|
||||
return command_wrapper({ "status" }, repo_root).has_value();
|
||||
}
|
||||
|
||||
bool GitRepo::stage(DeprecatedString const& file)
|
||||
{
|
||||
return !command({ "add", file }).is_null();
|
||||
return command({ "add", file }).has_value();
|
||||
}
|
||||
|
||||
bool GitRepo::unstage(DeprecatedString const& file)
|
||||
{
|
||||
return !command({ "reset", "HEAD", "--", file }).is_null();
|
||||
return command({ "reset", "HEAD", "--", file }).has_value();
|
||||
}
|
||||
|
||||
bool GitRepo::commit(DeprecatedString const& message)
|
||||
{
|
||||
return !command({ "commit", "-m", message }).is_null();
|
||||
return command({ "commit", "-m", message }).has_value();
|
||||
}
|
||||
|
||||
Optional<DeprecatedString> GitRepo::original_file_content(DeprecatedString const& file) const
|
||||
|
@ -124,10 +124,10 @@ Optional<DeprecatedString> GitRepo::unstaged_diff(DeprecatedString const& file)
|
|||
bool GitRepo::is_tracked(DeprecatedString const& file) const
|
||||
{
|
||||
auto res = command({ "ls-files", file });
|
||||
if (res.is_null())
|
||||
if (!res.has_value())
|
||||
return false;
|
||||
|
||||
return !res.is_empty();
|
||||
return !res->is_empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ private:
|
|||
static bool git_is_installed();
|
||||
static bool git_repo_exists(DeprecatedString const& repo_root);
|
||||
|
||||
static DeprecatedString command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir);
|
||||
static Optional<DeprecatedString> command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir);
|
||||
static Vector<DeprecatedString> parse_files_list(DeprecatedString const&);
|
||||
|
||||
explicit GitRepo(DeprecatedString const& repository_root)
|
||||
|
@ -56,7 +56,7 @@ private:
|
|||
Vector<DeprecatedString> modified_files() const;
|
||||
Vector<DeprecatedString> untracked_files() const;
|
||||
|
||||
DeprecatedString command(Vector<DeprecatedString> const& command_parts) const;
|
||||
Optional<DeprecatedString> command(Vector<DeprecatedString> const& command_parts) const;
|
||||
|
||||
DeprecatedString m_repository_root;
|
||||
};
|
||||
|
|
|
@ -909,15 +909,15 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_as_action()
|
|||
|
||||
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(),
|
||||
old_filename.is_null() ? "Untitled"sv : old_path.title(),
|
||||
old_filename.is_null() ? "txt"sv : old_path.extension(),
|
||||
old_filename.is_empty() ? "Untitled"sv : old_path.title(),
|
||||
old_filename.is_empty() ? "txt"sv : old_path.extension(),
|
||||
suggested_path);
|
||||
if (!save_path.has_value()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeprecatedString const relative_file_path = LexicalPath::relative_path(save_path.value(), m_project->root_path());
|
||||
if (current_editor_wrapper().filename().is_null()) {
|
||||
if (current_editor_wrapper().filename().is_empty()) {
|
||||
current_editor_wrapper().set_filename(relative_file_path);
|
||||
} else {
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
|
@ -1729,7 +1729,7 @@ void HackStudioWidget::update_current_editor_title()
|
|||
void HackStudioWidget::on_cursor_change()
|
||||
{
|
||||
update_statusbar();
|
||||
if (current_editor_wrapper().filename().is_null())
|
||||
if (current_editor_wrapper().filename().is_empty())
|
||||
return;
|
||||
|
||||
auto current_location = current_project_location();
|
||||
|
|
|
@ -68,9 +68,9 @@ DeprecatedString FileDB::to_absolute_path(DeprecatedString const& filename) cons
|
|||
if (LexicalPath { filename }.is_absolute()) {
|
||||
return filename;
|
||||
}
|
||||
if (m_project_root.is_null())
|
||||
if (!m_project_root.has_value())
|
||||
return filename;
|
||||
return LexicalPath { DeprecatedString::formatted("{}/{}", m_project_root, filename) }.string();
|
||||
return LexicalPath { DeprecatedString::formatted("{}/{}", *m_project_root, filename) }.string();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<GUI::TextDocument>> FileDB::create_from_filesystem(DeprecatedString const& filename) const
|
||||
|
|
|
@ -38,7 +38,7 @@ private:
|
|||
|
||||
private:
|
||||
HashMap<DeprecatedString, NonnullRefPtr<GUI::TextDocument>> m_open_files;
|
||||
DeprecatedString m_project_root;
|
||||
Optional<DeprecatedString> m_project_root;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
}
|
||||
if (suggestion.is_symbol_declaration()) {
|
||||
if (index.column() == Column::Name) {
|
||||
if (suggestion.as_symbol_declaration.value().scope.is_null())
|
||||
if (!suggestion.as_symbol_declaration.value().scope.is_empty())
|
||||
return suggestion.as_symbol_declaration.value().name;
|
||||
return DeprecatedString::formatted("{}::{}", suggestion.as_symbol_declaration.value().scope, suggestion.as_symbol_declaration.value().name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue