summaryrefslogtreecommitdiff
path: root/Libraries/LibLine/Editor.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-03 19:06:41 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-03 19:06:41 +0200
commitea9ac3155d1774f13ac4e9a96605c0e85a8f299e (patch)
tree79965fb23c2c75ae48fcbf1300e40671ea90f0df /Libraries/LibLine/Editor.cpp
parentb139fb9f383911130336ac995cd2671662f9c963 (diff)
downloadserenity-ea9ac3155d1774f13ac4e9a96605c0e85a8f299e.zip
Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
Diffstat (limited to 'Libraries/LibLine/Editor.cpp')
-rw-r--r--Libraries/LibLine/Editor.cpp92
1 files changed, 46 insertions, 46 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index fd4605d699..94be98a68f 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -97,7 +97,7 @@ void Editor::clear_line()
void Editor::insert(const Utf32View& string)
{
for (size_t i = 0; i < string.length(); ++i)
- insert(string.codepoints()[i]);
+ insert(string.code_pointss()[i]);
}
void Editor::insert(const String& string)
@@ -137,15 +137,15 @@ void Editor::register_character_input_callback(char ch, Function<bool(Editor&)>
m_key_callbacks.set(ch, make<KeyCallback>(move(callback)));
}
-static size_t codepoint_length_in_utf8(u32 codepoint)
+static size_t code_points_length_in_utf8(u32 code_points)
{
- if (codepoint <= 0x7f)
+ if (code_points <= 0x7f)
return 1;
- if (codepoint <= 0x07ff)
+ if (code_points <= 0x07ff)
return 2;
- if (codepoint <= 0xffff)
+ if (code_points <= 0xffff)
return 3;
- if (codepoint <= 0x10ffff)
+ if (code_points <= 0x10ffff)
return 4;
return 3;
}
@@ -156,20 +156,20 @@ static size_t codepoint_length_in_utf8(u32 codepoint)
// | | +- scan offset = M
// | +- range end = M - B
// +- range start = M - A
-// This method converts a byte range defined by [start_byte_offset, end_byte_offset] to a codepoint range [M - A, M - B] as shown in the diagram above.
+// This method converts a byte range defined by [start_byte_offset, end_byte_offset] to a code_points range [M - A, M - B] as shown in the diagram above.
// If `reverse' is true, A and B are before M, if not, A and B are after M.
-Editor::CodepointRange Editor::byte_offset_range_to_codepoint_offset_range(size_t start_byte_offset, size_t end_byte_offset, size_t scan_codepoint_offset, bool reverse) const
+Editor::CodepointRange Editor::byte_offset_range_to_code_points_offset_range(size_t start_byte_offset, size_t end_byte_offset, size_t scan_code_points_offset, bool reverse) const
{
size_t byte_offset = 0;
- size_t codepoint_offset = scan_codepoint_offset + (reverse ? 1 : 0);
+ size_t code_points_offset = scan_code_points_offset + (reverse ? 1 : 0);
CodepointRange range;
for (;;) {
if (!reverse) {
- if (codepoint_offset >= m_buffer.size())
+ if (code_points_offset >= m_buffer.size())
break;
} else {
- if (codepoint_offset == 0)
+ if (code_points_offset == 0)
break;
}
@@ -182,7 +182,7 @@ Editor::CodepointRange Editor::byte_offset_range_to_codepoint_offset_range(size_
if (byte_offset < end_byte_offset)
++range.end;
- byte_offset += codepoint_length_in_utf8(m_buffer[reverse ? --codepoint_offset : codepoint_offset++]);
+ byte_offset += code_points_length_in_utf8(m_buffer[reverse ? --code_points_offset : code_points_offset++]);
}
return range;
@@ -197,7 +197,7 @@ void Editor::stylize(const Span& span, const Style& style)
auto end = span.end();
if (span.mode() == Span::ByteOriented) {
- auto offsets = byte_offset_range_to_codepoint_offset_range(start, end, 0);
+ auto offsets = byte_offset_range_to_code_points_offset_range(start, end, 0);
start = offsets.start;
end = offsets.end;
@@ -231,7 +231,7 @@ void Editor::suggest(size_t invariant_offset, size_t static_offset, Span::Mode o
if (offset_mode == Span::Mode::ByteOriented) {
// FIXME: We're assuming that invariant_offset points to the end of the available data
// this is not necessarily true, but is true in most cases.
- auto offsets = byte_offset_range_to_codepoint_offset_range(internal_static_offset, internal_invariant_offset + internal_static_offset, m_cursor - 1, true);
+ auto offsets = byte_offset_range_to_code_points_offset_range(internal_static_offset, internal_invariant_offset + internal_static_offset, m_cursor - 1, true);
internal_static_offset = offsets.start;
internal_invariant_offset = offsets.end - offsets.start;
@@ -427,7 +427,7 @@ void Editor::handle_read_event()
}
Utf8View input_view { StringView { m_incomplete_data.data(), valid_bytes } };
- size_t consumed_codepoints = 0;
+ size_t consumed_code_pointss = 0;
enum Amount { Character, Word };
auto do_cursor_left = [&](Amount amount) {
@@ -531,18 +531,18 @@ void Editor::handle_read_event()
m_refresh_needed = true;
};
- for (auto codepoint : input_view) {
+ for (auto code_points : input_view) {
if (m_finish)
break;
- ++consumed_codepoints;
+ ++consumed_code_pointss;
- if (codepoint == 0)
+ if (code_points == 0)
continue;
switch (m_state) {
case InputState::ExpectBracket:
- if (codepoint == '[') {
+ if (code_points == '[') {
m_state = InputState::ExpectFinal;
continue;
} else {
@@ -550,7 +550,7 @@ void Editor::handle_read_event()
break;
}
case InputState::ExpectFinal:
- switch (codepoint) {
+ switch (code_points) {
case 'O': // mod_ctrl
ctrl_held = true;
continue;
@@ -600,7 +600,7 @@ void Editor::handle_read_event()
ctrl_held = false;
continue;
default:
- dbgprintf("LibLine: Unhandled final: %02x (%c)\r\n", codepoint, codepoint);
+ dbgprintf("LibLine: Unhandled final: %02x (%c)\r\n", code_points, code_points);
m_state = InputState::Free;
ctrl_held = false;
continue;
@@ -610,14 +610,14 @@ void Editor::handle_read_event()
m_state = InputState::Free;
continue;
case InputState::Free:
- if (codepoint == 27) {
+ if (code_points == 27) {
m_state = InputState::ExpectBracket;
continue;
}
break;
}
- auto cb = m_key_callbacks.get(codepoint);
+ auto cb = m_key_callbacks.get(code_points);
if (cb.has_value()) {
if (!cb.value()->callback(*this)) {
continue;
@@ -625,19 +625,19 @@ void Editor::handle_read_event()
}
// ^N
- if (codepoint == ctrl('N')) {
+ if (code_points == ctrl('N')) {
do_search_forwards();
continue;
}
// ^P
- if (codepoint == ctrl('P')) {
+ if (code_points == ctrl('P')) {
do_search_backwards();
continue;
}
m_search_offset = 0; // reset search offset on any key
- if (codepoint == '\t' || reverse_tab) {
+ if (code_points == '\t' || reverse_tab) {
if (!on_tab_complete)
continue;
@@ -752,7 +752,7 @@ void Editor::handle_read_event()
}
m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB
- if (codepoint == m_termios.c_cc[VWERASE]) {
+ if (code_points == m_termios.c_cc[VWERASE]) {
bool has_seen_nonspace = false;
while (m_cursor > 0) {
if (isspace(m_buffer[m_cursor - 1])) {
@@ -765,7 +765,7 @@ void Editor::handle_read_event()
}
continue;
}
- if (codepoint == m_termios.c_cc[VKILL]) {
+ if (code_points == m_termios.c_cc[VKILL]) {
for (size_t i = 0; i < m_cursor; ++i)
remove_at_index(0);
m_cursor = 0;
@@ -774,7 +774,7 @@ void Editor::handle_read_event()
}
// Normally ^D. `stty eof \^n` can change it to ^N (or something else), but Serenity doesn't have `stty` yet.
// Handle it before ctrl shortcuts below and only continue if the buffer is empty, so that the editing shortcuts can take effect else.
- if (codepoint == m_termios.c_cc[VEOF] && m_buffer.is_empty()) {
+ if (code_points == m_termios.c_cc[VEOF] && m_buffer.is_empty()) {
printf("<EOF>\n");
if (!m_always_refresh) {
m_input_error = Error::Eof;
@@ -783,37 +783,37 @@ void Editor::handle_read_event()
continue;
}
// ^A
- if (codepoint == ctrl('A')) {
+ if (code_points == ctrl('A')) {
m_cursor = 0;
continue;
}
// ^B
- if (codepoint == ctrl('B')) {
+ if (code_points == ctrl('B')) {
do_cursor_left(Character);
continue;
}
// ^D
- if (codepoint == ctrl('D')) {
+ if (code_points == ctrl('D')) {
do_delete();
continue;
}
// ^E
- if (codepoint == ctrl('E')) {
+ if (code_points == ctrl('E')) {
m_cursor = m_buffer.size();
continue;
}
// ^F
- if (codepoint == ctrl('F')) {
+ if (code_points == ctrl('F')) {
do_cursor_right(Character);
continue;
}
// ^H: ctrl('H') == '\b'
- if (codepoint == '\b' || codepoint == m_termios.c_cc[VERASE]) {
+ if (code_points == '\b' || code_points == m_termios.c_cc[VERASE]) {
do_backspace();
continue;
}
// ^L
- if (codepoint == ctrl('L')) {
+ if (code_points == ctrl('L')) {
printf("\033[3J\033[H\033[2J"); // Clear screen.
VT::move_absolute(1, 1);
set_origin(1, 1);
@@ -821,7 +821,7 @@ void Editor::handle_read_event()
continue;
}
// ^R
- if (codepoint == ctrl('R')) {
+ if (code_points == ctrl('R')) {
if (m_is_searching) {
// how did we get here?
ASSERT_NOT_REACHED();
@@ -829,8 +829,8 @@ void Editor::handle_read_event()
m_is_searching = true;
m_search_offset = 0;
m_pre_search_buffer.clear();
- for (auto codepoint : m_buffer)
- m_pre_search_buffer.append(codepoint);
+ for (auto code_points : m_buffer)
+ m_pre_search_buffer.append(code_points);
m_pre_search_cursor = m_cursor;
// Disable our own notifier so as to avoid interfering with the search editor.
@@ -937,7 +937,7 @@ void Editor::handle_read_event()
continue;
}
// ^T
- if (codepoint == ctrl('T')) {
+ if (code_points == ctrl('T')) {
if (m_cursor > 0 && m_buffer.size() >= 2) {
if (m_cursor < m_buffer.size())
++m_cursor;
@@ -947,18 +947,18 @@ void Editor::handle_read_event()
}
continue;
}
- if (codepoint == '\n') {
+ if (code_points == '\n') {
finish();
continue;
}
- insert(codepoint);
+ insert(code_points);
}
- if (consumed_codepoints == m_incomplete_data.size()) {
+ if (consumed_code_pointss == m_incomplete_data.size()) {
m_incomplete_data.clear();
} else {
- for (size_t i = 0; i < consumed_codepoints; ++i)
+ for (size_t i = 0; i < consumed_code_pointss; ++i)
m_incomplete_data.take_first();
}
}
@@ -1404,8 +1404,8 @@ StringMetrics Editor::actual_rendered_string_metrics(const Utf32View& view) cons
VTState state { Free };
for (size_t i = 0; i < view.length(); ++i) {
- auto c = view.codepoints()[i];
- auto next_c = i + 1 < view.length() ? view.codepoints()[i + 1] : 0;
+ auto c = view.code_pointss()[i];
+ auto next_c = i + 1 < view.length() ? view.code_pointss()[i + 1] : 0;
state = actual_rendered_string_length_step(metrics, length, c, next_c, state);
}