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

@ -231,11 +231,11 @@ void Editor::get_terminal_size()
m_num_lines = ws.ws_row;
}
void Editor::add_to_history(String const& line)
void Editor::add_to_history(DeprecatedString const& line)
{
if (line.is_empty())
return;
String histcontrol = getenv("HISTCONTROL");
DeprecatedString histcontrol = getenv("HISTCONTROL");
auto ignoredups = histcontrol == "ignoredups" || histcontrol == "ignoreboth";
auto ignorespace = histcontrol == "ignorespace" || histcontrol == "ignoreboth";
if (ignoredups && !m_history.is_empty() && line == m_history.last().entry)
@ -250,7 +250,7 @@ void Editor::add_to_history(String const& line)
m_history_dirty = true;
}
bool Editor::load_history(String const& path)
bool Editor::load_history(DeprecatedString const& path)
{
auto history_file = Core::File::construct(path);
if (!history_file->open(Core::OpenMode::ReadOnly))
@ -308,7 +308,7 @@ static void merge(It0&& begin0, It0 const& end0, It1&& begin1, It1 const& end1,
}
}
bool Editor::save_history(String const& path)
bool Editor::save_history(DeprecatedString const& path)
{
Vector<HistoryEntry> final_history { { "", 0 } };
{
@ -333,7 +333,7 @@ bool Editor::save_history(String const& path)
auto file = file_or_error.release_value();
final_history.take_first();
for (auto const& entry : final_history)
file->write(String::formatted("{}::{}\n\n", entry.timestamp, entry.entry));
file->write(DeprecatedString::formatted("{}::{}\n\n", entry.timestamp, entry.entry));
m_history_dirty = false;
return true;
@ -357,7 +357,7 @@ void Editor::insert(Utf32View const& string)
insert(string.code_points()[i]);
}
void Editor::insert(String const& string)
void Editor::insert(DeprecatedString const& string)
{
for (auto ch : Utf8View { string })
insert(ch);
@ -403,7 +403,7 @@ void Editor::register_key_input_callback(KeyBinding const& binding)
return register_key_input_callback(binding.keys, move(internal_function));
}
return register_key_input_callback(binding.keys, [binding = String(binding.binding)](auto& editor) {
return register_key_input_callback(binding.keys, [binding = DeprecatedString(binding.binding)](auto& editor) {
editor.insert(binding);
return false;
});
@ -678,7 +678,7 @@ void Editor::really_quit_event_loop()
Core::EventLoop::current().quit(Exit);
}
auto Editor::get_line(String const& prompt) -> Result<String, Editor::Error>
auto Editor::get_line(DeprecatedString const& prompt) -> Result<DeprecatedString, Editor::Error>
{
initialize();
m_is_editing = true;
@ -702,7 +702,7 @@ auto Editor::get_line(String const& prompt) -> Result<String, Editor::Error>
}
restore();
if (line) {
String result { line, (size_t)line_length, Chomp };
DeprecatedString result { line, (size_t)line_length, Chomp };
free(line);
return result;
}
@ -750,7 +750,7 @@ auto Editor::get_line(String const& prompt) -> Result<String, Editor::Error>
if (loop.exec() == Retry)
return get_line(prompt);
return m_input_error.has_value() ? Result<String, Editor::Error> { m_input_error.value() } : Result<String, Editor::Error> { m_returned_line };
return m_input_error.has_value() ? Result<DeprecatedString, Editor::Error> { m_input_error.value() } : Result<DeprecatedString, Editor::Error> { m_returned_line };
}
void Editor::save_to(JsonObject& object)
@ -922,7 +922,7 @@ void Editor::handle_read_event()
case InputState::CSIExpectFinal: {
m_state = m_previous_free_state;
auto is_in_paste = m_state == InputState::Paste;
for (auto& parameter : String::copy(csi_parameter_bytes).split(';')) {
for (auto& parameter : DeprecatedString::copy(csi_parameter_bytes).split(';')) {
if (auto value = parameter.to_uint(); value.has_value())
csi_parameters.append(value.value());
else
@ -1577,7 +1577,7 @@ void Editor::reposition_cursor(OutputStream& stream, bool to_end)
void VT::move_absolute(u32 row, u32 col, OutputStream& stream)
{
stream.write(String::formatted("\033[{};{}H", row, col).bytes());
stream.write(DeprecatedString::formatted("\033[{};{}H", row, col).bytes());
}
void VT::move_relative(int row, int col, OutputStream& stream)
@ -1594,9 +1594,9 @@ void VT::move_relative(int row, int col, OutputStream& stream)
col = -col;
if (row > 0)
stream.write(String::formatted("\033[{}{}", row, x_op).bytes());
stream.write(DeprecatedString::formatted("\033[{}{}", row, x_op).bytes());
if (col > 0)
stream.write(String::formatted("\033[{}{}", col, y_op).bytes());
stream.write(DeprecatedString::formatted("\033[{}{}", col, y_op).bytes());
}
Style Editor::find_applicable_style(size_t offset) const
@ -1624,36 +1624,36 @@ Style Editor::find_applicable_style(size_t offset) const
return style;
}
String Style::Background::to_vt_escape() const
DeprecatedString Style::Background::to_vt_escape() const
{
if (is_default())
return "";
if (m_is_rgb) {
return String::formatted("\e[48;2;{};{};{}m", m_rgb_color[0], m_rgb_color[1], m_rgb_color[2]);
return DeprecatedString::formatted("\e[48;2;{};{};{}m", m_rgb_color[0], m_rgb_color[1], m_rgb_color[2]);
} else {
return String::formatted("\e[{}m", (u8)m_xterm_color + 40);
return DeprecatedString::formatted("\e[{}m", (u8)m_xterm_color + 40);
}
}
String Style::Foreground::to_vt_escape() const
DeprecatedString Style::Foreground::to_vt_escape() const
{
if (is_default())
return "";
if (m_is_rgb) {
return String::formatted("\e[38;2;{};{};{}m", m_rgb_color[0], m_rgb_color[1], m_rgb_color[2]);
return DeprecatedString::formatted("\e[38;2;{};{};{}m", m_rgb_color[0], m_rgb_color[1], m_rgb_color[2]);
} else {
return String::formatted("\e[{}m", (u8)m_xterm_color + 30);
return DeprecatedString::formatted("\e[{}m", (u8)m_xterm_color + 30);
}
}
String Style::Hyperlink::to_vt_escape(bool starting) const
DeprecatedString Style::Hyperlink::to_vt_escape(bool starting) const
{
if (is_empty())
return "";
return String::formatted("\e]8;;{}\e\\", starting ? m_link : String::empty());
return DeprecatedString::formatted("\e]8;;{}\e\\", starting ? m_link : DeprecatedString::empty());
}
void Style::unify_with(Style const& other, bool prefer_other)
@ -1680,7 +1680,7 @@ void Style::unify_with(Style const& other, bool prefer_other)
m_hyperlink = other.hyperlink();
}
String Style::to_string() const
DeprecatedString Style::to_string() const
{
StringBuilder builder;
builder.append("Style { "sv);
@ -1733,7 +1733,7 @@ String Style::to_string() const
void VT::apply_style(Style const& style, OutputStream& stream, bool is_starting)
{
if (is_starting) {
stream.write(String::formatted("\033[{};{};{}m{}{}{}",
stream.write(DeprecatedString::formatted("\033[{};{};{}m{}{}{}",
style.bold() ? 1 : 22,
style.underline() ? 4 : 24,
style.italic() ? 3 : 23,
@ -1753,7 +1753,7 @@ void VT::clear_lines(size_t count_above, size_t count_below, OutputStream& strea
} else {
// Go down count_below lines.
if (count_below > 0)
stream.write(String::formatted("\033[{}B", count_below).bytes());
stream.write(DeprecatedString::formatted("\033[{}B", count_below).bytes());
// Then clear lines going upwards.
for (size_t i = count_below + count_above; i > 0; --i) {
stream.write("\033[2K"sv.bytes());
@ -2151,7 +2151,7 @@ Result<Vector<size_t, 2>, Editor::Error> Editor::vt_dsr()
return Vector<size_t, 2> { row, col };
}
String Editor::line(size_t up_to_index) const
DeprecatedString Editor::line(size_t up_to_index) const
{
StringBuilder builder;
builder.append(Utf32View { m_buffer.data(), min(m_buffer.size(), up_to_index) });

View file

@ -9,12 +9,12 @@
#include <AK/BinarySearch.h>
#include <AK/ByteBuffer.h>
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/RedBlackTree.h>
#include <AK/Result.h>
#include <AK/String.h>
#include <AK/Traits.h>
#include <AK/Utf32View.h>
#include <AK/Utf8View.h>
@ -42,7 +42,7 @@ struct KeyBinding {
InternalFunction,
Insertion,
} kind { Kind::InternalFunction };
String binding;
DeprecatedString binding;
};
struct Configuration {
@ -67,7 +67,7 @@ struct Configuration {
};
struct DefaultTextEditor {
String command;
DeprecatedString command;
};
Configuration()
@ -97,7 +97,7 @@ struct Configuration {
SignalHandler m_signal_mode { SignalHandler::WithSignalHandlers };
OperationMode operation_mode { OperationMode::Unset };
Vector<KeyBinding> keybindings;
String m_default_text_editor {};
DeprecatedString m_default_text_editor {};
bool enable_bracketed_paste { false };
};
@ -144,15 +144,15 @@ public:
~Editor();
Result<String, Error> get_line(String const& prompt);
Result<DeprecatedString, Error> get_line(DeprecatedString const& prompt);
void initialize();
void refetch_default_termios();
void add_to_history(String const& line);
bool load_history(String const& path);
bool save_history(String const& path);
void add_to_history(DeprecatedString const& line);
bool load_history(DeprecatedString const& path);
bool save_history(DeprecatedString const& path);
auto const& history() const { return m_history; }
bool is_history_dirty() const { return m_history_dirty; }
@ -194,11 +194,11 @@ public:
}
Vector<u32, 1024> const& buffer() const { return m_buffer; }
u32 buffer_at(size_t pos) const { return m_buffer.at(pos); }
String line() const { return line(m_buffer.size()); }
String line(size_t up_to_index) const;
DeprecatedString line() const { return line(m_buffer.size()); }
DeprecatedString line(size_t up_to_index) const;
// Only makes sense inside a character_input callback or on_* callback.
void set_prompt(String const& prompt)
void set_prompt(DeprecatedString const& prompt)
{
if (m_cached_prompt_valid)
m_old_prompt_metrics = m_cached_prompt_metrics;
@ -208,7 +208,7 @@ public:
}
void clear_line();
void insert(String const&);
void insert(DeprecatedString const&);
void insert(StringView);
void insert(Utf32View const&);
void insert(const u32);
@ -318,7 +318,7 @@ private:
m_prompt_lines_at_suggestion_initiation = 0;
m_refresh_needed = true;
m_input_error.clear();
m_returned_line = String::empty();
m_returned_line = DeprecatedString::empty();
m_chars_touched_in_the_middle = 0;
m_drawn_end_of_line_offset = 0;
m_drawn_spans = {};
@ -420,7 +420,7 @@ private:
ByteBuffer m_pending_chars;
Vector<char, 512> m_incomplete_data;
Optional<Error> m_input_error;
String m_returned_line;
DeprecatedString m_returned_line;
size_t m_cursor { 0 };
size_t m_drawn_cursor { 0 };
@ -447,7 +447,7 @@ private:
OwnPtr<SuggestionDisplay> m_suggestion_display;
Vector<u32, 32> m_remembered_suggestion_static_data;
String m_new_prompt;
DeprecatedString m_new_prompt;
SuggestionManager m_suggestion_manager;
@ -471,7 +471,7 @@ private:
// FIXME: This should be something more take_first()-friendly.
struct HistoryEntry {
String entry;
DeprecatedString entry;
time_t timestamp;
};
Vector<HistoryEntry> m_history;

View file

@ -38,7 +38,7 @@ void Editor::search_forwards()
ScopedValueRollback inline_search_cursor_rollback { m_inline_search_cursor };
StringBuilder builder;
builder.append(Utf32View { m_buffer.data(), m_inline_search_cursor });
String search_phrase = builder.to_string();
DeprecatedString search_phrase = builder.to_string();
if (m_search_offset_state == SearchOffsetState::Backwards)
--m_search_offset;
if (m_search_offset > 0) {
@ -65,7 +65,7 @@ void Editor::search_backwards()
ScopedValueRollback inline_search_cursor_rollback { m_inline_search_cursor };
StringBuilder builder;
builder.append(Utf32View { m_buffer.data(), m_inline_search_cursor });
String search_phrase = builder.to_string();
DeprecatedString search_phrase = builder.to_string();
if (m_search_offset_state == SearchOffsetState::Forwards)
++m_search_offset;
if (search(search_phrase, true)) {

View file

@ -6,9 +6,9 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/Vector.h>
namespace Line {

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/Types.h>
#include <AK/Utf8View.h>
#include <AK/Vector.h>
@ -72,7 +72,7 @@ public:
: Color(r, g, b)
{
}
String to_vt_escape() const;
DeprecatedString to_vt_escape() const;
};
struct Foreground : public Color {
@ -85,7 +85,7 @@ public:
{
}
String to_vt_escape() const;
DeprecatedString to_vt_escape() const;
};
struct Hyperlink {
@ -99,11 +99,11 @@ public:
Hyperlink() = default;
String to_vt_escape(bool starting) const;
DeprecatedString to_vt_escape(bool starting) const;
bool is_empty() const { return !m_has_link; }
String m_link;
DeprecatedString m_link;
bool m_has_link { false };
};
@ -124,7 +124,7 @@ public:
{
}
String replacement;
DeprecatedString replacement;
mutable Utf8View replacement_view;
Mode mode;
};
@ -180,7 +180,7 @@ public:
bool is_anchored() const { return m_is_anchored; }
bool is_empty() const { return m_is_empty; }
String to_string() const;
DeprecatedString to_string() const;
private:
bool m_underline { false };

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Forward.h>
#include <AK/String.h>
#include <LibLine/StringMetrics.h>
#include <LibLine/SuggestionManager.h>
#include <stdlib.h>

View file

@ -117,7 +117,7 @@ SuggestionManager::CompletionAttemptResult SuggestionManager::attempt_completion
result.avoid_committing_to_single_suggestion = true;
m_last_shown_suggestion_display_length = 0;
m_last_shown_suggestion_was_complete = false;
m_last_shown_suggestion = String::empty();
m_last_shown_suggestion = DeprecatedString::empty();
return result;
}
@ -169,7 +169,7 @@ SuggestionManager::CompletionAttemptResult SuggestionManager::attempt_completion
}
result.new_completion_mode = CompletionMode::ShowSuggestions;
m_last_shown_suggestion_was_complete = false;
m_last_shown_suggestion = String::empty();
m_last_shown_suggestion = DeprecatedString::empty();
} else {
result.insert.append(suggestion.text_view.substring_view(suggestion.invariant_offset, suggestion.text_view.length() - suggestion.invariant_offset));
// Add in the trivia of the last selected suggestion.

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Forward.h>
#include <AK/String.h>
#include <AK/Utf32View.h>
#include <AK/Utf8View.h>
#include <LibLine/Style.h>
@ -26,12 +26,12 @@ public:
static constexpr ForSearchTag ForSearch {};
// Intentionally not explicit. (To allow suggesting bare strings)
CompletionSuggestion(String const& completion)
CompletionSuggestion(DeprecatedString const& completion)
: CompletionSuggestion(completion, ""sv, {})
{
}
CompletionSuggestion(String const& completion, ForSearchTag)
CompletionSuggestion(DeprecatedString const& completion, ForSearchTag)
: text_string(completion)
{
}
@ -61,8 +61,8 @@ public:
Utf32View text_view;
Utf32View trivia_view;
Utf32View display_trivia_view;
String text_string;
String display_trivia_string;
DeprecatedString text_string;
DeprecatedString display_trivia_string;
bool is_valid { false };
};
@ -120,7 +120,7 @@ public:
void reset()
{
m_last_shown_suggestion = String::empty();
m_last_shown_suggestion = DeprecatedString::empty();
m_last_shown_suggestion_display_length = 0;
m_suggestions.clear();
m_last_displayed_suggestion_index = 0;
@ -133,7 +133,7 @@ private:
}
Vector<CompletionSuggestion> m_suggestions;
CompletionSuggestion m_last_shown_suggestion { String::empty() };
CompletionSuggestion m_last_shown_suggestion { DeprecatedString::empty() };
size_t m_last_shown_suggestion_display_length { 0 };
bool m_last_shown_suggestion_was_complete { false };
mutable size_t m_next_suggestion_index { 0 };

View file

@ -118,8 +118,8 @@ void XtermSuggestionDisplay::display(SuggestionManager const& manager)
stderr_stream.write(suggestion.text_string.bytes());
stderr_stream.write(suggestion.display_trivia_string.bytes());
} else {
auto field = String::formatted("{: <{}} {}", suggestion.text_string, longest_suggestion_byte_length_without_trivia, suggestion.display_trivia_string);
stderr_stream.write(String::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes());
auto field = DeprecatedString::formatted("{: <{}} {}", suggestion.text_string, longest_suggestion_byte_length_without_trivia, suggestion.display_trivia_string);
stderr_stream.write(DeprecatedString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes());
num_printed += longest_suggestion_length + 2;
}
@ -141,7 +141,7 @@ void XtermSuggestionDisplay::display(SuggestionManager const& manager)
if (m_pages.size() > 1) {
auto left_arrow = page_index > 0 ? '<' : ' ';
auto right_arrow = page_index < m_pages.size() - 1 ? '>' : ' ';
auto string = String::formatted("{:c} page {} of {} {:c}", left_arrow, page_index + 1, m_pages.size(), right_arrow);
auto string = DeprecatedString::formatted("{:c} page {} of {} {:c}", left_arrow, page_index + 1, m_pages.size(), right_arrow);
if (string.length() > m_num_columns - 1) {
// This would overflow into the next line, so just don't print an indicator.