1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

Unicode: s/codepoint/code_point/g

Unicode calls them "code points" so let's follow their style.
This commit is contained in:
Andreas Kling 2020-08-03 19:06:41 +02:00
parent b139fb9f38
commit ea9ac3155d
45 changed files with 449 additions and 449 deletions

View file

@ -37,25 +37,25 @@ Line::Line(u16 length)
Line::~Line()
{
if (m_utf32)
delete[] m_codepoints.as_u32;
delete[] m_code_pointss.as_u32;
else
delete[] m_codepoints.as_u8;
delete[] m_code_pointss.as_u8;
delete[] m_attributes;
}
template<typename CodepointType>
static CodepointType* create_new_codepoint_array(size_t new_length, const CodepointType* old_codepoints, size_t old_length)
static CodepointType* create_new_code_points_array(size_t new_length, const CodepointType* old_code_pointss, size_t old_length)
{
auto* new_codepoints = new CodepointType[new_length];
auto* new_code_pointss = new CodepointType[new_length];
for (size_t i = 0; i < new_length; ++i)
new_codepoints[i] = ' ';
if (old_codepoints) {
new_code_pointss[i] = ' ';
if (old_code_pointss) {
for (size_t i = 0; i < min(old_length, new_length); ++i) {
new_codepoints[i] = old_codepoints[i];
new_code_pointss[i] = old_code_pointss[i];
}
}
delete[] old_codepoints;
return new_codepoints;
delete[] old_code_pointss;
return new_code_pointss;
}
void Line::set_length(u16 new_length)
@ -64,9 +64,9 @@ void Line::set_length(u16 new_length)
return;
if (m_utf32)
m_codepoints.as_u32 = create_new_codepoint_array<u32>(new_length, m_codepoints.as_u32, m_length);
m_code_pointss.as_u32 = create_new_code_points_array<u32>(new_length, m_code_pointss.as_u32, m_length);
else
m_codepoints.as_u8 = create_new_codepoint_array<u8>(new_length, m_codepoints.as_u8, m_length);
m_code_pointss.as_u8 = create_new_code_points_array<u8>(new_length, m_code_pointss.as_u8, m_length);
auto* new_attributes = new Attribute[new_length];
if (m_attributes) {
@ -82,15 +82,15 @@ void Line::clear(Attribute attribute)
{
if (m_dirty) {
for (u16 i = 0; i < m_length; ++i) {
set_codepoint(i, ' ');
set_code_points(i, ' ');
m_attributes[i] = attribute;
}
return;
}
for (unsigned i = 0; i < m_length; ++i) {
if (codepoint(i) != ' ')
if (code_points(i) != ' ')
m_dirty = true;
set_codepoint(i, ' ');
set_code_points(i, ' ');
}
for (unsigned i = 0; i < m_length; ++i) {
if (m_attributes[i] != attribute)
@ -115,12 +115,12 @@ bool Line::has_only_one_background_color() const
void Line::convert_to_utf32()
{
ASSERT(!m_utf32);
auto* new_codepoints = new u32[m_length];
auto* new_code_pointss = new u32[m_length];
for (size_t i = 0; i < m_length; ++i) {
new_codepoints[i] = m_codepoints.as_u8[i];
new_code_pointss[i] = m_code_pointss.as_u8[i];
}
delete m_codepoints.as_u8;
m_codepoints.as_u32 = new_codepoints;
delete m_code_pointss.as_u8;
m_code_pointss.as_u32 = new_code_pointss;
m_utf32 = true;
}

View file

@ -90,22 +90,22 @@ public:
u16 length() const { return m_length; }
u32 codepoint(size_t index) const
u32 code_points(size_t index) const
{
if (m_utf32)
return m_codepoints.as_u32[index];
return m_codepoints.as_u8[index];
return m_code_pointss.as_u32[index];
return m_code_pointss.as_u8[index];
}
void set_codepoint(size_t index, u32 codepoint)
void set_code_points(size_t index, u32 code_points)
{
if (!m_utf32 && codepoint & 0xffffff80u)
if (!m_utf32 && code_points & 0xffffff80u)
convert_to_utf32();
if (m_utf32)
m_codepoints.as_u32[index] = codepoint;
m_code_pointss.as_u32[index] = code_points;
else
m_codepoints.as_u8[index] = codepoint;
m_code_pointss.as_u8[index] = code_points;
}
bool is_dirty() const { return m_dirty; }
@ -122,7 +122,7 @@ private:
union {
u8* as_u8;
u32* as_u32;
} m_codepoints { nullptr };
} m_code_pointss { nullptr };
Attribute* m_attributes { nullptr };
bool m_dirty { false };
bool m_utf32 { false };

View file

@ -361,7 +361,7 @@ void Terminal::escape$b(const ParamVector& params)
return;
for (unsigned i = 0; i < params[0]; ++i)
put_character_at(m_cursor_row, m_cursor_column++, m_last_codepoint);
put_character_at(m_cursor_row, m_cursor_column++, m_last_code_points);
}
void Terminal::escape$d(const ParamVector& params)
@ -537,11 +537,11 @@ void Terminal::escape$P(const ParamVector& params)
// Move n characters of line to the left
for (int i = m_cursor_column; i < line.length() - num; i++)
line.set_codepoint(i, line.codepoint(i + num));
line.set_code_points(i, line.code_points(i + num));
// Fill remainder of line with blanks
for (int i = line.length() - num; i < line.length(); i++)
line.set_codepoint(i, ' ');
line.set_code_points(i, ' ');
line.set_dirty(true);
}
@ -768,17 +768,17 @@ void Terminal::set_cursor(unsigned a_row, unsigned a_column)
invalidate_cursor();
}
void Terminal::put_character_at(unsigned row, unsigned column, u32 codepoint)
void Terminal::put_character_at(unsigned row, unsigned column, u32 code_points)
{
ASSERT(row < rows());
ASSERT(column < columns());
auto& line = m_lines[row];
line.set_codepoint(column, codepoint);
line.set_code_points(column, code_points);
line.attributes()[column] = m_current_attribute;
line.attributes()[column].flags |= Attribute::Touched;
line.set_dirty(true);
m_last_codepoint = codepoint;
m_last_code_points = code_points;
}
void Terminal::NEL()
@ -820,14 +820,14 @@ void Terminal::on_input(u8 ch)
auto fail_utf8_parse = [this] {
m_parser_state = Normal;
on_codepoint('%');
on_code_points('%');
};
auto advance_utf8_parse = [this, ch] {
m_parser_codepoint <<= 6;
m_parser_codepoint |= ch & 0x3f;
m_parser_code_points <<= 6;
m_parser_code_points |= ch & 0x3f;
if (m_parser_state == UTF8Needs1Byte) {
on_codepoint(m_parser_codepoint);
on_code_points(m_parser_code_points);
m_parser_state = Normal;
} else {
m_parser_state = (ParserState)(m_parser_state + 1);
@ -928,17 +928,17 @@ void Terminal::on_input(u8 ch)
break;
if ((ch & 0xe0) == 0xc0) {
m_parser_state = UTF8Needs1Byte;
m_parser_codepoint = ch & 0x1f;
m_parser_code_points = ch & 0x1f;
return;
}
if ((ch & 0xf0) == 0xe0) {
m_parser_state = UTF8Needs2Bytes;
m_parser_codepoint = ch & 0x0f;
m_parser_code_points = ch & 0x0f;
return;
}
if ((ch & 0xf8) == 0xf0) {
m_parser_state = UTF8Needs3Bytes;
m_parser_codepoint = ch & 0x07;
m_parser_code_points = ch & 0x07;
return;
}
fail_utf8_parse();
@ -978,26 +978,26 @@ void Terminal::on_input(u8 ch)
return;
}
on_codepoint(ch);
on_code_points(ch);
}
void Terminal::on_codepoint(u32 codepoint)
void Terminal::on_code_points(u32 code_points)
{
auto new_column = m_cursor_column + 1;
if (new_column < columns()) {
put_character_at(m_cursor_row, m_cursor_column, codepoint);
put_character_at(m_cursor_row, m_cursor_column, code_points);
set_cursor(m_cursor_row, new_column);
return;
}
if (m_stomp) {
m_stomp = false;
newline();
put_character_at(m_cursor_row, m_cursor_column, codepoint);
put_character_at(m_cursor_row, m_cursor_column, code_points);
set_cursor(m_cursor_row, 1);
} else {
// Curious: We wait once on the right-hand side
m_stomp = true;
put_character_at(m_cursor_row, m_cursor_column, codepoint);
put_character_at(m_cursor_row, m_cursor_column, code_points);
}
}
@ -1078,7 +1078,7 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
emit_string("\033");
StringBuilder sb;
sb.append_codepoint(code_point);
sb.append_code_points(code_point);
emit_string(sb.to_string());
}

View file

@ -106,7 +106,7 @@ public:
private:
typedef Vector<unsigned, 4> ParamVector;
void on_codepoint(u32);
void on_code_points(u32);
void scroll_up();
void scroll_down();
@ -193,13 +193,13 @@ private:
};
ParserState m_parser_state { Normal };
u32 m_parser_codepoint { 0 };
u32 m_parser_code_points { 0 };
Vector<u8> m_parameters;
Vector<u8> m_intermediates;
Vector<u8> m_xterm_parameters;
Vector<bool> m_horizontal_tabs;
u8 m_final { 0 };
u32 m_last_codepoint { 0 };
u32 m_last_code_points { 0 };
};
}

View file

@ -294,7 +294,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
painter.clear_rect(row_rect, color_from_rgb(line.attributes()[0].background_color).with_alpha(m_opacity));
for (size_t column = 0; column < line.length(); ++column) {
u32 codepoint = line.codepoint(column);
u32 code_points = line.code_points(column);
bool should_reverse_fill_for_cursor_or_selection = m_cursor_blink_state
&& m_has_logical_focus
&& visual_row == row_with_cursor
@ -342,12 +342,12 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
}
}
if (codepoint == ' ')
if (code_points == ' ')
continue;
painter.draw_glyph_or_emoji(
character_rect.location(),
codepoint,
code_points,
attribute.flags & VT::Attribute::Bold ? bold_font() : font(),
text_color);
}
@ -524,16 +524,16 @@ void TerminalWidget::doubleclick_event(GUI::MouseEvent& event)
auto position = buffer_position_at(event.position());
auto& line = m_terminal.line(position.row());
bool want_whitespace = line.codepoint(position.column()) == ' ';
bool want_whitespace = line.code_points(position.column()) == ' ';
int start_column = 0;
int end_column = 0;
for (int column = position.column(); column >= 0 && (line.codepoint(column) == ' ') == want_whitespace; --column) {
for (int column = position.column(); column >= 0 && (line.code_points(column) == ' ') == want_whitespace; --column) {
start_column = column;
}
for (int column = position.column(); column < m_terminal.columns() && (line.codepoint(column) == ' ') == want_whitespace; ++column) {
for (int column = position.column(); column < m_terminal.columns() && (line.code_points(column) == ' ') == want_whitespace; ++column) {
end_column = column;
}
@ -715,10 +715,10 @@ String TerminalWidget::selected_text() const
}
// FIXME: This is a bit hackish.
if (line.is_utf32()) {
u32 codepoint = line.codepoint(column);
builder.append(Utf32View(&codepoint, 1));
u32 code_points = line.code_points(column);
builder.append(Utf32View(&code_points, 1));
} else {
builder.append(line.codepoint(column));
builder.append(line.code_points(column));
}
if (column == line.length() - 1 || (m_rectangle_selection && column == last_column)) {
builder.append('\n');