mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
This commit is contained in:
parent
b139fb9f38
commit
ea9ac3155d
45 changed files with 449 additions and 449 deletions
|
@ -37,9 +37,9 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static Vector<u32> supported_emoji_codepoints()
|
||||
static Vector<u32> supported_emoji_code_pointss()
|
||||
{
|
||||
Vector<u32> codepoints;
|
||||
Vector<u32> code_pointss;
|
||||
Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots);
|
||||
while (dt.has_next()) {
|
||||
auto filename = dt.next_path();
|
||||
|
@ -49,10 +49,10 @@ static Vector<u32> supported_emoji_codepoints()
|
|||
auto basename = lexical_path.basename();
|
||||
if (!basename.starts_with("U+"))
|
||||
continue;
|
||||
u32 codepoint = strtoul(basename.characters() + 2, nullptr, 16);
|
||||
codepoints.append(codepoint);
|
||||
u32 code_points = strtoul(basename.characters() + 2, nullptr, 16);
|
||||
code_pointss.append(code_points);
|
||||
}
|
||||
return codepoints;
|
||||
return code_pointss;
|
||||
}
|
||||
|
||||
EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
||||
|
@ -67,20 +67,20 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
|||
auto& main_layout = main_widget.set_layout<VerticalBoxLayout>();
|
||||
main_layout.set_spacing(0);
|
||||
|
||||
auto codepoints = supported_emoji_codepoints();
|
||||
auto code_pointss = supported_emoji_code_pointss();
|
||||
|
||||
size_t index = 0;
|
||||
size_t columns = 6;
|
||||
size_t rows = ceil_div(codepoints.size(), columns);
|
||||
size_t rows = ceil_div(code_pointss.size(), columns);
|
||||
|
||||
for (size_t row = 0; row < rows && index < codepoints.size(); ++row) {
|
||||
for (size_t row = 0; row < rows && index < code_pointss.size(); ++row) {
|
||||
auto& horizontal_container = main_widget.add<Widget>();
|
||||
auto& horizontal_layout = horizontal_container.set_layout<HorizontalBoxLayout>();
|
||||
horizontal_layout.set_spacing(0);
|
||||
for (size_t column = 0; column < columns; ++column) {
|
||||
if (index < codepoints.size()) {
|
||||
if (index < code_pointss.size()) {
|
||||
StringBuilder builder;
|
||||
builder.append(Utf32View(&codepoints[index++], 1));
|
||||
builder.append(Utf32View(&code_pointss[index++], 1));
|
||||
auto emoji_text = builder.to_string();
|
||||
auto& button = horizontal_container.add<Button>(emoji_text);
|
||||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
|
|
|
@ -298,7 +298,7 @@ public:
|
|||
String text() const
|
||||
{
|
||||
StringBuilder sb;
|
||||
sb.append_codepoint(m_code_point);
|
||||
sb.append_code_points(m_code_point);
|
||||
return sb.to_string();
|
||||
}
|
||||
u32 scancode() const { return m_scancode; }
|
||||
|
|
|
@ -87,8 +87,8 @@ void TextDocument::set_text(const StringView& text)
|
|||
size_t TextDocumentLine::first_non_whitespace_column() const
|
||||
{
|
||||
for (size_t i = 0; i < length(); ++i) {
|
||||
auto codepoint = codepoints()[i];
|
||||
if (!isspace(codepoint))
|
||||
auto code_points = code_pointss()[i];
|
||||
if (!isspace(code_points))
|
||||
return i;
|
||||
}
|
||||
return length();
|
||||
|
@ -131,35 +131,35 @@ void TextDocumentLine::set_text(TextDocument& document, const StringView& text)
|
|||
}
|
||||
m_text.clear();
|
||||
Utf8View utf8_view(text);
|
||||
for (auto codepoint : utf8_view)
|
||||
m_text.append(codepoint);
|
||||
for (auto code_points : utf8_view)
|
||||
m_text.append(code_points);
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void TextDocumentLine::append(TextDocument& document, const u32* codepoints, size_t length)
|
||||
void TextDocumentLine::append(TextDocument& document, const u32* code_pointss, size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return;
|
||||
m_text.append(codepoints, length);
|
||||
m_text.append(code_pointss, length);
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void TextDocumentLine::append(TextDocument& document, u32 codepoint)
|
||||
void TextDocumentLine::append(TextDocument& document, u32 code_points)
|
||||
{
|
||||
insert(document, length(), codepoint);
|
||||
insert(document, length(), code_points);
|
||||
}
|
||||
|
||||
void TextDocumentLine::prepend(TextDocument& document, u32 codepoint)
|
||||
void TextDocumentLine::prepend(TextDocument& document, u32 code_points)
|
||||
{
|
||||
insert(document, 0, codepoint);
|
||||
insert(document, 0, code_points);
|
||||
}
|
||||
|
||||
void TextDocumentLine::insert(TextDocument& document, size_t index, u32 codepoint)
|
||||
void TextDocumentLine::insert(TextDocument& document, size_t index, u32 code_points)
|
||||
{
|
||||
if (index == length()) {
|
||||
m_text.append(codepoint);
|
||||
m_text.append(code_points);
|
||||
} else {
|
||||
m_text.insert(index, codepoint);
|
||||
m_text.insert(index, code_points);
|
||||
}
|
||||
document.update_views({});
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ String TextDocument::text_in_range(const TextRange& a_range) const
|
|||
auto& line = this->line(i);
|
||||
size_t selection_start_column_on_line = range.start().line() == i ? range.start().column() : 0;
|
||||
size_t selection_end_column_on_line = range.end().line() == i ? range.end().column() : line.length();
|
||||
builder.append(Utf32View(line.codepoints() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line));
|
||||
builder.append(Utf32View(line.code_pointss() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line));
|
||||
if (i != range.end().line())
|
||||
builder.append('\n');
|
||||
}
|
||||
|
@ -282,13 +282,13 @@ String TextDocument::text_in_range(const TextRange& a_range) const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
u32 TextDocument::codepoint_at(const TextPosition& position) const
|
||||
u32 TextDocument::code_points_at(const TextPosition& position) const
|
||||
{
|
||||
ASSERT(position.line() < line_count());
|
||||
auto& line = this->line(position.line());
|
||||
if (position.column() == line.length())
|
||||
return '\n';
|
||||
return line.codepoints()[position.column()];
|
||||
return line.code_pointss()[position.column()];
|
||||
}
|
||||
|
||||
TextPosition TextDocument::next_position_after(const TextPosition& position, SearchShouldWrap should_wrap) const
|
||||
|
@ -333,7 +333,7 @@ TextRange TextDocument::find_next(const StringView& needle, const TextPosition&
|
|||
size_t needle_index = 0;
|
||||
|
||||
do {
|
||||
auto ch = codepoint_at(position);
|
||||
auto ch = code_points_at(position);
|
||||
// FIXME: This is not the right way to use a Unicode needle!
|
||||
if (ch == (u32)needle[needle_index]) {
|
||||
if (needle_index == 0)
|
||||
|
@ -365,7 +365,7 @@ TextRange TextDocument::find_previous(const StringView& needle, const TextPositi
|
|||
size_t needle_index = needle.length() - 1;
|
||||
|
||||
do {
|
||||
auto ch = codepoint_at(position);
|
||||
auto ch = code_points_at(position);
|
||||
// FIXME: This is not the right way to use a Unicode needle!
|
||||
if (ch == (u32)needle[needle_index]) {
|
||||
if (needle_index == needle.length() - 1)
|
||||
|
@ -439,11 +439,11 @@ TextPosition TextDocument::first_word_break_before(const TextPosition& position,
|
|||
|
||||
auto target = position;
|
||||
auto line = this->line(target.line());
|
||||
auto is_start_alphanumeric = isalnum(line.codepoints()[target.column() - (start_at_column_before ? 1 : 0)]);
|
||||
auto is_start_alphanumeric = isalnum(line.code_pointss()[target.column() - (start_at_column_before ? 1 : 0)]);
|
||||
|
||||
while (target.column() > 0) {
|
||||
auto prev_codepoint = line.codepoints()[target.column() - 1];
|
||||
if ((is_start_alphanumeric && !isalnum(prev_codepoint)) || (!is_start_alphanumeric && isalnum(prev_codepoint)))
|
||||
auto prev_code_points = line.code_pointss()[target.column() - 1];
|
||||
if ((is_start_alphanumeric && !isalnum(prev_code_points)) || (!is_start_alphanumeric && isalnum(prev_code_points)))
|
||||
break;
|
||||
target.set_column(target.column() - 1);
|
||||
}
|
||||
|
@ -463,11 +463,11 @@ TextPosition TextDocument::first_word_break_after(const TextPosition& position)
|
|||
return TextPosition(position.line() + 1, 0);
|
||||
}
|
||||
|
||||
auto is_start_alphanumeric = isalnum(line.codepoints()[target.column()]);
|
||||
auto is_start_alphanumeric = isalnum(line.code_pointss()[target.column()]);
|
||||
|
||||
while (target.column() < line.length()) {
|
||||
auto next_codepoint = line.codepoints()[target.column()];
|
||||
if ((is_start_alphanumeric && !isalnum(next_codepoint)) || (!is_start_alphanumeric && isalnum(next_codepoint)))
|
||||
auto next_code_points = line.code_pointss()[target.column()];
|
||||
if ((is_start_alphanumeric && !isalnum(next_code_points)) || (!is_start_alphanumeric && isalnum(next_code_points)))
|
||||
break;
|
||||
target.set_column(target.column() + 1);
|
||||
}
|
||||
|
@ -555,26 +555,26 @@ TextPosition TextDocument::insert_at(const TextPosition& position, const StringV
|
|||
{
|
||||
TextPosition cursor = position;
|
||||
Utf8View utf8_view(text);
|
||||
for (auto codepoint : utf8_view)
|
||||
cursor = insert_at(cursor, codepoint, client);
|
||||
for (auto code_points : utf8_view)
|
||||
cursor = insert_at(cursor, code_points, client);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint, const Client* client)
|
||||
TextPosition TextDocument::insert_at(const TextPosition& position, u32 code_points, const Client* client)
|
||||
{
|
||||
bool automatic_indentation_enabled = client ? client->is_automatic_indentation_enabled() : false;
|
||||
size_t m_soft_tab_width = client ? client->soft_tab_width() : 4;
|
||||
|
||||
bool at_head = position.column() == 0;
|
||||
bool at_tail = position.column() == line(position.line()).length();
|
||||
if (codepoint == '\n') {
|
||||
if (code_points == '\n') {
|
||||
if (at_tail || at_head) {
|
||||
String new_line_contents;
|
||||
if (automatic_indentation_enabled && at_tail) {
|
||||
size_t leading_spaces = 0;
|
||||
auto& old_line = lines()[position.line()];
|
||||
for (size_t i = 0; i < old_line.length(); ++i) {
|
||||
if (old_line.codepoints()[i] == ' ')
|
||||
if (old_line.code_pointss()[i] == ' ')
|
||||
++leading_spaces;
|
||||
else
|
||||
break;
|
||||
|
@ -586,23 +586,23 @@ TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint
|
|||
size_t row = position.line();
|
||||
Vector<u32> line_content;
|
||||
for (size_t i = position.column(); i < line(row).length(); i++)
|
||||
line_content.append(line(row).codepoints()[i]);
|
||||
line_content.append(line(row).code_pointss()[i]);
|
||||
insert_line(position.line() + (at_tail ? 1 : 0), make<TextDocumentLine>(*this, new_line_contents));
|
||||
notify_did_change();
|
||||
return { position.line() + 1, line(position.line() + 1).length() };
|
||||
}
|
||||
auto new_line = make<TextDocumentLine>(*this);
|
||||
new_line->append(*this, line(position.line()).codepoints() + position.column(), line(position.line()).length() - position.column());
|
||||
new_line->append(*this, line(position.line()).code_pointss() + position.column(), line(position.line()).length() - position.column());
|
||||
|
||||
Vector<u32> line_content;
|
||||
for (size_t i = 0; i < new_line->length(); i++)
|
||||
line_content.append(new_line->codepoints()[i]);
|
||||
line_content.append(new_line->code_pointss()[i]);
|
||||
line(position.line()).truncate(*this, position.column());
|
||||
insert_line(position.line() + 1, move(new_line));
|
||||
notify_did_change();
|
||||
return { position.line() + 1, 0 };
|
||||
}
|
||||
if (codepoint == '\t') {
|
||||
if (code_points == '\t') {
|
||||
size_t next_soft_tab_stop = ((position.column() + m_soft_tab_width) / m_soft_tab_width) * m_soft_tab_width;
|
||||
size_t spaces_to_insert = next_soft_tab_stop - position.column();
|
||||
for (size_t i = 0; i < spaces_to_insert; ++i) {
|
||||
|
@ -611,7 +611,7 @@ TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint
|
|||
notify_did_change();
|
||||
return { position.line(), next_soft_tab_stop };
|
||||
}
|
||||
line(position.line()).insert(*this, position.column(), codepoint);
|
||||
line(position.line()).insert(*this, position.column(), code_points);
|
||||
notify_did_change();
|
||||
return { position.line(), position.column() + 1 };
|
||||
}
|
||||
|
@ -644,10 +644,10 @@ void TextDocument::remove(const TextRange& unnormalized_range)
|
|||
ASSERT(range.start().line() == range.end().line() - 1);
|
||||
auto& first_line = line(range.start().line());
|
||||
auto& second_line = line(range.end().line());
|
||||
Vector<u32> codepoints;
|
||||
codepoints.append(first_line.codepoints(), range.start().column());
|
||||
codepoints.append(second_line.codepoints() + range.end().column(), second_line.length() - range.end().column());
|
||||
first_line.set_text(*this, move(codepoints));
|
||||
Vector<u32> code_pointss;
|
||||
code_pointss.append(first_line.code_pointss(), range.start().column());
|
||||
code_pointss.append(second_line.code_pointss() + range.end().column(), second_line.length() - range.end().column());
|
||||
first_line.set_text(*this, move(code_pointss));
|
||||
remove_line(range.end().line());
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ public:
|
|||
TextPosition next_position_after(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
|
||||
TextPosition previous_position_before(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
|
||||
|
||||
u32 codepoint_at(const TextPosition&) const;
|
||||
u32 code_points_at(const TextPosition&) const;
|
||||
|
||||
TextRange range_for_entire_line(size_t line_index) const;
|
||||
|
||||
|
@ -159,8 +159,8 @@ public:
|
|||
|
||||
String to_utf8() const;
|
||||
|
||||
Utf32View view() const { return { codepoints(), length() }; }
|
||||
const u32* codepoints() const { return m_text.data(); }
|
||||
Utf32View view() const { return { code_pointss(), length() }; }
|
||||
const u32* code_pointss() const { return m_text.data(); }
|
||||
size_t length() const { return m_text.size(); }
|
||||
void set_text(TextDocument&, const StringView&);
|
||||
void set_text(TextDocument&, Vector<u32>);
|
||||
|
|
|
@ -172,7 +172,7 @@ TextPosition TextEditor::text_position_at(const Gfx::IntPoint& a_position) const
|
|||
int glyph_x = 0;
|
||||
size_t i = 0;
|
||||
for (; i < view.length(); ++i) {
|
||||
int advance = font().glyph_width(view.codepoints()[i]) + font().glyph_spacing();
|
||||
int advance = font().glyph_width(view.code_pointss()[i]) + font().glyph_spacing();
|
||||
if ((glyph_x + (advance / 2)) >= position.x())
|
||||
break;
|
||||
glyph_x += advance;
|
||||
|
@ -465,7 +465,7 @@ void TextEditor::paint_event(PaintEvent& event)
|
|||
} else {
|
||||
Gfx::IntRect character_rect = { visual_line_rect.location(), { 0, line_height() } };
|
||||
for (size_t i = 0; i < visual_line_text.length(); ++i) {
|
||||
u32 codepoint = visual_line_text.substring_view(i, 1).codepoints()[0];
|
||||
u32 code_points = visual_line_text.substring_view(i, 1).code_pointss()[0];
|
||||
const Gfx::Font* font = &this->font();
|
||||
Color color;
|
||||
Optional<Color> background_color;
|
||||
|
@ -482,7 +482,7 @@ void TextEditor::paint_event(PaintEvent& event)
|
|||
underline = span.is_underlined;
|
||||
break;
|
||||
}
|
||||
character_rect.set_width(font->glyph_width(codepoint) + font->glyph_spacing());
|
||||
character_rect.set_width(font->glyph_width(code_points) + font->glyph_spacing());
|
||||
if (background_color.has_value())
|
||||
painter.fill_rect(character_rect, background_color.value());
|
||||
painter.draw_text(character_rect, visual_line_text.substring_view(i, 1), *font, m_text_alignment, color);
|
||||
|
@ -524,9 +524,9 @@ void TextEditor::paint_event(PaintEvent& event)
|
|||
|
||||
painter.fill_rect(selection_rect, background_color);
|
||||
|
||||
if (visual_line_text.codepoints()) {
|
||||
if (visual_line_text.code_pointss()) {
|
||||
Utf32View visual_selected_text {
|
||||
visual_line_text.codepoints() + start_of_selection_within_visual_line,
|
||||
visual_line_text.code_pointss() + start_of_selection_within_visual_line,
|
||||
end_of_selection_within_visual_line - start_of_selection_within_visual_line
|
||||
};
|
||||
|
||||
|
@ -660,7 +660,7 @@ void TextEditor::sort_selected_lines()
|
|||
auto end = lines.begin() + (int)last_line + 1;
|
||||
|
||||
quick_sort(start, end, [](auto& a, auto& b) {
|
||||
return strcmp_utf32(a.codepoints(), b.codepoints(), min(a.length(), b.length())) < 0;
|
||||
return strcmp_utf32(a.code_pointss(), b.code_pointss(), min(a.length(), b.length())) < 0;
|
||||
});
|
||||
|
||||
did_change();
|
||||
|
@ -939,7 +939,7 @@ void TextEditor::keydown_event(KeyEvent& event)
|
|||
|
||||
if (is_editable() && !event.ctrl() && !event.alt() && event.code_point() != 0) {
|
||||
StringBuilder sb;
|
||||
sb.append_codepoint(event.code_point());
|
||||
sb.append_code_points(event.code_point());
|
||||
|
||||
insert_at_cursor_or_replace_selection(sb.to_string());
|
||||
return;
|
||||
|
@ -1525,8 +1525,8 @@ void TextEditor::recompute_visual_lines(size_t line_index)
|
|||
|
||||
auto glyph_spacing = font().glyph_spacing();
|
||||
for (size_t i = 0; i < line.length(); ++i) {
|
||||
auto codepoint = line.codepoints()[i];
|
||||
auto glyph_width = font().glyph_or_emoji_width(codepoint);
|
||||
auto code_points = line.code_pointss()[i];
|
||||
auto glyph_width = font().glyph_or_emoji_width(code_points);
|
||||
if ((line_width_so_far + glyph_width + glyph_spacing) > available_width) {
|
||||
visual_data.visual_line_breaks.append(i);
|
||||
line_width_so_far = glyph_width + glyph_spacing;
|
||||
|
@ -1555,7 +1555,7 @@ void TextEditor::for_each_visual_line(size_t line_index, Callback callback) cons
|
|||
auto& visual_data = m_line_visual_data[line_index];
|
||||
|
||||
for (auto visual_line_break : visual_data.visual_line_breaks) {
|
||||
auto visual_line_view = Utf32View(line.codepoints() + start_of_line, visual_line_break - start_of_line);
|
||||
auto visual_line_view = Utf32View(line.code_pointss() + start_of_line, visual_line_break - start_of_line);
|
||||
Gfx::IntRect visual_line_rect {
|
||||
visual_data.visual_rect.x(),
|
||||
visual_data.visual_rect.y() + ((int)visual_line_index * line_height()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue