diff options
author | Nico Weber <thakis@chromium.org> | 2020-08-05 16:31:20 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-05 22:33:42 +0200 |
commit | ce95628b7f96924e851d8cedac1d784547600cd3 (patch) | |
tree | 533dad9932cfc954ead3cfc776a27a9f7c4333f9 | |
parent | 19ac1f6368c91cc00a68717001ea4eae65567a47 (diff) | |
download | serenity-ce95628b7f96924e851d8cedac1d784547600cd3.zip |
Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:
git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
45 files changed, 441 insertions, 441 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 5697287ef6..349c44a0b6 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -126,9 +126,9 @@ String JsonParser::consume_quoted_string() sb.append(consume()); sb.append(consume()); - auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string()); - if (codepoint.has_value()) { - final_sb.append_codepoint(codepoint.value()); + auto code_point = AK::StringUtils::convert_to_uint_from_hex(sb.to_string()); + if (code_point.has_value()) { + final_sb.append_code_point(code_point.value()); } else { final_sb.append('?'); } diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 40a6e83646..15239bfb39 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -113,22 +113,22 @@ void StringBuilder::clear() m_length = 0; } -void StringBuilder::append_codepoint(u32 codepoint) +void StringBuilder::append_code_point(u32 code_point) { - if (codepoint <= 0x7f) { - append((char)codepoint); - } else if (codepoint <= 0x07ff) { - append((char)(((codepoint >> 6) & 0x1f) | 0xc0)); - append((char)(((codepoint >> 0) & 0x3f) | 0x80)); - } else if (codepoint <= 0xffff) { - append((char)(((codepoint >> 12) & 0x0f) | 0xe0)); - append((char)(((codepoint >> 6) & 0x3f) | 0x80)); - append((char)(((codepoint >> 0) & 0x3f) | 0x80)); - } else if (codepoint <= 0x10ffff) { - append((char)(((codepoint >> 18) & 0x07) | 0xf0)); - append((char)(((codepoint >> 12) & 0x3f) | 0x80)); - append((char)(((codepoint >> 6) & 0x3f) | 0x80)); - append((char)(((codepoint >> 0) & 0x3f) | 0x80)); + if (code_point <= 0x7f) { + append((char)code_point); + } else if (code_point <= 0x07ff) { + append((char)(((code_point >> 6) & 0x1f) | 0xc0)); + append((char)(((code_point >> 0) & 0x3f) | 0x80)); + } else if (code_point <= 0xffff) { + append((char)(((code_point >> 12) & 0x0f) | 0xe0)); + append((char)(((code_point >> 6) & 0x3f) | 0x80)); + append((char)(((code_point >> 0) & 0x3f) | 0x80)); + } else if (code_point <= 0x10ffff) { + append((char)(((code_point >> 18) & 0x07) | 0xf0)); + append((char)(((code_point >> 12) & 0x3f) | 0x80)); + append((char)(((code_point >> 6) & 0x3f) | 0x80)); + append((char)(((code_point >> 0) & 0x3f) | 0x80)); } else { append(0xef); append(0xbf); @@ -139,8 +139,8 @@ void StringBuilder::append_codepoint(u32 codepoint) void StringBuilder::append(const Utf32View& utf32_view) { for (size_t i = 0; i < utf32_view.length(); ++i) { - auto codepoint = utf32_view.codepoints()[i]; - append_codepoint(codepoint); + auto code_point = utf32_view.code_points()[i]; + append_code_point(code_point); } } diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 009c9a55bd..0bd2dde47d 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -42,7 +42,7 @@ public: void append(const StringView&); void append(const Utf32View&); void append(char); - void append_codepoint(u32); + void append_code_point(u32); void append(const char*, size_t); void appendf(const char*, ...); void appendvf(const char*, va_list); diff --git a/AK/Tests/TestUtf8.cpp b/AK/Tests/TestUtf8.cpp index d61209e63b..a98129a287 100644 --- a/AK/Tests/TestUtf8.cpp +++ b/AK/Tests/TestUtf8.cpp @@ -37,9 +37,9 @@ TEST_CASE(decode_ascii) size_t expected_size = sizeof(expected) / sizeof(expected[0]); size_t i = 0; - for (u32 codepoint : utf8) { + for (u32 code_point : utf8) { ASSERT(i < expected_size); - EXPECT_EQ(codepoint, expected[i]); + EXPECT_EQ(code_point, expected[i]); i++; } EXPECT_EQ(i, expected_size); @@ -56,9 +56,9 @@ TEST_CASE(decode_utf8) size_t expected_size = sizeof(expected) / sizeof(expected[0]); size_t i = 0; - for (u32 codepoint : utf8) { + for (u32 code_point : utf8) { ASSERT(i < expected_size); - EXPECT_EQ(codepoint, expected[i]); + EXPECT_EQ(code_point, expected[i]); i++; } EXPECT_EQ(i, expected_size); diff --git a/AK/Utf32View.h b/AK/Utf32View.h index 25f4c4a828..539443df1d 100644 --- a/AK/Utf32View.h +++ b/AK/Utf32View.h @@ -35,14 +35,14 @@ namespace AK { class Utf32View { public: Utf32View() { } - Utf32View(const u32* codepoints, size_t length) - : m_codepoints(codepoints) + Utf32View(const u32* code_points, size_t length) + : m_code_points(code_points) , m_length(length) { - ASSERT(codepoints || length == 0); + ASSERT(code_points || length == 0); } - const u32* codepoints() const { return m_codepoints; } + const u32* code_points() const { return m_code_points; } bool is_empty() const { return m_length == 0; } size_t length() const { return m_length; } @@ -53,11 +53,11 @@ public: ASSERT(offset < m_length); ASSERT(!Checked<size_t>::addition_would_overflow(offset, length)); ASSERT((offset + length) <= m_length); - return Utf32View(m_codepoints + offset, length); + return Utf32View(m_code_points + offset, length); } private: - const u32* m_codepoints { nullptr }; + const u32* m_code_points { nullptr }; size_t m_length { 0 }; }; diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp index a2cd2fa2a7..f94d11ac69 100644 --- a/AK/Utf8View.cpp +++ b/AK/Utf8View.cpp @@ -81,12 +81,12 @@ Utf8View Utf8View::substring_view(int byte_offset, int byte_length) const static inline bool decode_first_byte( unsigned char byte, - int& out_codepoint_length_in_bytes, + int& out_code_point_length_in_bytes, u32& out_value) { if ((byte & 128) == 0) { out_value = byte; - out_codepoint_length_in_bytes = 1; + out_code_point_length_in_bytes = 1; return true; } if ((byte & 64) == 0) { @@ -94,17 +94,17 @@ static inline bool decode_first_byte( } if ((byte & 32) == 0) { out_value = byte & 31; - out_codepoint_length_in_bytes = 2; + out_code_point_length_in_bytes = 2; return true; } if ((byte & 16) == 0) { out_value = byte & 15; - out_codepoint_length_in_bytes = 3; + out_code_point_length_in_bytes = 3; return true; } if ((byte & 8) == 0) { out_value = byte & 7; - out_codepoint_length_in_bytes = 4; + out_code_point_length_in_bytes = 4; return true; } @@ -115,13 +115,13 @@ bool Utf8View::validate(size_t& valid_bytes) const { valid_bytes = 0; for (auto ptr = begin_ptr(); ptr < end_ptr(); ptr++) { - int codepoint_length_in_bytes; + int code_point_length_in_bytes; u32 value; - bool first_byte_makes_sense = decode_first_byte(*ptr, codepoint_length_in_bytes, value); + bool first_byte_makes_sense = decode_first_byte(*ptr, code_point_length_in_bytes, value); if (!first_byte_makes_sense) return false; - for (int i = 1; i < codepoint_length_in_bytes; i++) { + for (int i = 1; i < code_point_length_in_bytes; i++) { ptr++; if (ptr >= end_ptr()) return false; @@ -129,17 +129,17 @@ bool Utf8View::validate(size_t& valid_bytes) const return false; } - valid_bytes += codepoint_length_in_bytes; + valid_bytes += code_point_length_in_bytes; } return true; } -size_t Utf8View::length_in_codepoints() const +size_t Utf8View::length_in_code_points() const { size_t length = 0; - for (auto codepoint : *this) { - (void)codepoint; + for (auto code_point : *this) { + (void)code_point; ++length; } return length; @@ -165,54 +165,54 @@ Utf8CodepointIterator& Utf8CodepointIterator::operator++() { ASSERT(m_length > 0); - int codepoint_length_in_bytes = 0; + int code_point_length_in_bytes = 0; u32 value; - bool first_byte_makes_sense = decode_first_byte(*m_ptr, codepoint_length_in_bytes, value); + bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_point_length_in_bytes, value); ASSERT(first_byte_makes_sense); (void)value; - ASSERT(codepoint_length_in_bytes <= m_length); - m_ptr += codepoint_length_in_bytes; - m_length -= codepoint_length_in_bytes; + ASSERT(code_point_length_in_bytes <= m_length); + m_ptr += code_point_length_in_bytes; + m_length -= code_point_length_in_bytes; return *this; } -int Utf8CodepointIterator::codepoint_length_in_bytes() const +int Utf8CodepointIterator::code_point_length_in_bytes() const { ASSERT(m_length > 0); - int codepoint_length_in_bytes = 0; + int code_point_length_in_bytes = 0; u32 value; - bool first_byte_makes_sense = decode_first_byte(*m_ptr, codepoint_length_in_bytes, value); + bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_point_length_in_bytes, value); ASSERT(first_byte_makes_sense); - return codepoint_length_in_bytes; + return code_point_length_in_bytes; } u32 Utf8CodepointIterator::operator*() const { ASSERT(m_length > 0); - u32 codepoint_value_so_far = 0; - int codepoint_length_in_bytes = 0; + u32 code_point_value_so_far = 0; + int code_point_length_in_bytes = 0; - bool first_byte_makes_sense = decode_first_byte(m_ptr[0], codepoint_length_in_bytes, codepoint_value_so_far); + bool first_byte_makes_sense = decode_first_byte(m_ptr[0], code_point_length_in_bytes, code_point_value_so_far); if (!first_byte_makes_sense) { dbg() << "First byte doesn't make sense, bytes: " << StringView((const char*)m_ptr, m_length); } ASSERT(first_byte_makes_sense); - if (codepoint_length_in_bytes > m_length) { - dbg() << "Not enough bytes (need " << codepoint_length_in_bytes << ", have " << m_length << "), first byte is: " << m_ptr[0] << " " << (const char*)m_ptr; + if (code_point_length_in_bytes > m_length) { + dbg() << "Not enough bytes (need " << code_point_length_in_bytes << ", have " << m_length << "), first byte is: " << m_ptr[0] << " " << (const char*)m_ptr; } - ASSERT(codepoint_length_in_bytes <= m_length); + ASSERT(code_point_length_in_bytes <= m_length); - for (int offset = 1; offset < codepoint_length_in_bytes; offset++) { + for (int offset = 1; offset < code_point_length_in_bytes; offset++) { ASSERT(m_ptr[offset] >> 6 == 2); - codepoint_value_so_far <<= 6; - codepoint_value_so_far |= m_ptr[offset] & 63; + code_point_value_so_far <<= 6; + code_point_value_so_far |= m_ptr[offset] & 63; } - return codepoint_value_so_far; + return code_point_value_so_far; } } diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 7b650ad0bf..a24e7ea42a 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -45,7 +45,7 @@ public: Utf8CodepointIterator& operator++(); u32 operator*() const; - int codepoint_length_in_bytes() const; + int code_point_length_in_bytes() const; bool done() const { return !m_length; } private: @@ -80,7 +80,7 @@ public: return validate(valid_bytes); } - size_t length_in_codepoints() const; + size_t length_in_code_points() const; private: const unsigned char* begin_ptr() const; diff --git a/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index 72283e19aa..1d4c26e051 100644 --- a/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -267,7 +267,7 @@ void KeyboardMapperWidget::set_current_map(const String current_map) continue; AK::StringBuilder sb; - sb.append_codepoint(map[index]); + sb.append_code_point(map[index]); m_keys.at(k)->set_text(sb.to_string()); } diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index c8eac8da6a..29742a8222 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -287,10 +287,10 @@ void VirtualConsole::flush_dirty_lines() if (!line.is_dirty() && !m_terminal.m_need_full_flush) continue; for (size_t column = 0; column < line.length(); ++column) { - u32 codepoint = line.codepoint(column); + u32 code_point = line.code_point(column); auto attribute = line.attributes()[column]; u16 vga_index = (visual_row * 160) + (column * 2); - m_current_vga_window[vga_index] = codepoint < 128 ? codepoint : '?'; + m_current_vga_window[vga_index] = code_point < 128 ? code_point : '?'; m_current_vga_window[vga_index + 1] = attribute_to_vga(attribute); } line.set_dirty(false); diff --git a/Libraries/LibGUI/EmojiInputDialog.cpp b/Libraries/LibGUI/EmojiInputDialog.cpp index f345cf7f49..ef0a2d65c5 100644 --- a/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Libraries/LibGUI/EmojiInputDialog.cpp @@ -37,9 +37,9 @@ namespace GUI { -static Vector<u32> supported_emoji_codepoints() +static Vector<u32> supported_emoji_code_points() { - Vector<u32> codepoints; + Vector<u32> code_points; 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_point = strtoul(basename.characters() + 2, nullptr, 16); + code_points.append(code_point); } - return codepoints; + return code_points; } 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_points = supported_emoji_code_points(); size_t index = 0; size_t columns = 6; - size_t rows = ceil_div(codepoints.size(), columns); + size_t rows = ceil_div(code_points.size(), columns); - for (size_t row = 0; row < rows && index < codepoints.size(); ++row) { + for (size_t row = 0; row < rows && index < code_points.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_points.size()) { StringBuilder builder; - builder.append(Utf32View(&codepoints[index++], 1)); + builder.append(Utf32View(&code_points[index++], 1)); auto emoji_text = builder.to_string(); auto& button = horizontal_container.add<Button>(emoji_text); button.set_button_style(Gfx::ButtonStyle::CoolBar); diff --git a/Libraries/LibGUI/Event.h b/Libraries/LibGUI/Event.h index f5ab95ce14..0351eb0fcb 100644 --- a/Libraries/LibGUI/Event.h +++ b/Libraries/LibGUI/Event.h @@ -298,7 +298,7 @@ public: String text() const { StringBuilder sb; - sb.append_codepoint(m_code_point); + sb.append_code_point(m_code_point); return sb.to_string(); } u32 scancode() const { return m_scancode; } diff --git a/Libraries/LibGUI/TextDocument.cpp b/Libraries/LibGUI/TextDocument.cpp index 4d13b99510..25dec99964 100644 --- a/Libraries/LibGUI/TextDocument.cpp +++ b/Libraries/LibGUI/TextDocument.cpp @@ -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_point = code_points()[i]; + if (!isspace(code_point)) 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_point : utf8_view) + m_text.append(code_point); document.update_views({}); } -void TextDocumentLine::append(TextDocument& document, const u32* codepoints, size_t length) +void TextDocumentLine::append(TextDocument& document, const u32* code_points, size_t length) { if (length == 0) return; - m_text.append(codepoints, length); + m_text.append(code_points, length); document.update_views({}); } -void TextDocumentLine::append(TextDocument& document, u32 codepoint) +void TextDocumentLine::append(TextDocument& document, u32 code_point) { - insert(document, length(), codepoint); + insert(document, length(), code_point); } -void TextDocumentLine::prepend(TextDocument& document, u32 codepoint) +void TextDocumentLine::prepend(TextDocument& document, u32 code_point) { - insert(document, 0, codepoint); + insert(document, 0, code_point); } -void TextDocumentLine::insert(TextDocument& document, size_t index, u32 codepoint) +void TextDocumentLine::insert(TextDocument& document, size_t index, u32 code_point) { if (index == length()) { - m_text.append(codepoint); + m_text.append(code_point); } else { - m_text.insert(index, codepoint); + m_text.insert(index, code_point); } 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_points() + 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_point_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_points()[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_point_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_point_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_points()[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_point = line.code_points()[target.column() - 1]; + if ((is_start_alphanumeric && !isalnum(prev_code_point)) || (!is_start_alphanumeric && isalnum(prev_code_point))) 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_points()[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_point = line.code_points()[target.column()]; + if ((is_start_alphanumeric && !isalnum(next_code_point)) || (!is_start_alphanumeric && isalnum(next_code_point))) 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_point : utf8_view) + cursor = insert_at(cursor, code_point, client); return cursor; } -TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint, const Client* client) +TextPosition TextDocument::insert_at(const TextPosition& position, u32 code_point, 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_point == '\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_points()[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_points()[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_points() + 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_points()[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_point == '\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_point); 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_points; + code_points.append(first_line.code_points(), range.start().column()); + code_points.append(second_line.code_points() + range.end().column(), second_line.length() - range.end().column()); + first_line.set_text(*this, move(code_points)); remove_line(range.end().line()); } diff --git a/Libraries/LibGUI/TextDocument.h b/Libraries/LibGUI/TextDocument.h index 8fa922dd2f..ff5f8e6cc3 100644 --- a/Libraries/LibGUI/TextDocument.h +++ b/Libraries/LibGUI/TextDocument.h @@ -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_point_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_points(), length() }; } + const u32* code_points() 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>); diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index bb2796b7fa..e434d5b769 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -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_points()[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_point = visual_line_text.substring_view(i, 1).code_points()[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_point) + 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_points()) { Utf32View visual_selected_text { - visual_line_text.codepoints() + start_of_selection_within_visual_line, + visual_line_text.code_points() + 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_points(), b.code_points(), 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_point(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_point = line.code_points()[i]; + auto glyph_width = font().glyph_or_emoji_width(code_point); 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_points() + 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()), diff --git a/Libraries/LibGfx/Emoji.cpp b/Libraries/LibGfx/Emoji.cpp index 530a6716aa..a5deabe46c 100644 --- a/Libraries/LibGfx/Emoji.cpp +++ b/Libraries/LibGfx/Emoji.cpp @@ -33,21 +33,21 @@ namespace Gfx { static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis; -const Bitmap* Emoji::emoji_for_codepoint(u32 codepoint) +const Bitmap* Emoji::emoji_for_code_point(u32 code_point) { - auto it = s_emojis.find(codepoint); + auto it = s_emojis.find(code_point); if (it != s_emojis.end()) return (*it).value.ptr(); - String path = String::format("/res/emoji/U+%X.png", codepoint); + String path = String::format("/res/emoji/U+%X.png", code_point); auto bitmap = Bitmap::load_from_file(path); if (!bitmap) { - s_emojis.set(codepoint, nullptr); + s_emojis.set(code_point, nullptr); return nullptr; } - s_emojis.set(codepoint, bitmap); + s_emojis.set(code_point, bitmap); return bitmap.ptr(); } diff --git a/Libraries/LibGfx/Emoji.h b/Libraries/LibGfx/Emoji.h index 094f2050d7..232927732e 100644 --- a/Libraries/LibGfx/Emoji.h +++ b/Libraries/LibGfx/Emoji.h @@ -34,7 +34,7 @@ class Bitmap; class Emoji { public: - static const Gfx::Bitmap* emoji_for_codepoint(u32 codepoint); + static const Gfx::Bitmap* emoji_for_code_point(u32 code_point); }; } diff --git a/Libraries/LibGfx/Font.cpp b/Libraries/LibGfx/Font.cpp index 43ed8fd867..b0e21f47e9 100644 --- a/Libraries/LibGfx/Font.cpp +++ b/Libraries/LibGfx/Font.cpp @@ -255,20 +255,20 @@ bool Font::write_to_file(const StringView& path) return true; } -GlyphBitmap Font::glyph_bitmap(u32 codepoint) const +GlyphBitmap Font::glyph_bitmap(u32 code_point) const { - return GlyphBitmap(&m_rows[codepoint * m_glyph_height], { glyph_width(codepoint), m_glyph_height }); + return GlyphBitmap(&m_rows[code_point * m_glyph_height], { glyph_width(code_point), m_glyph_height }); } -int Font::glyph_or_emoji_width(u32 codepoint) const +int Font::glyph_or_emoji_width(u32 code_point) const { - if (codepoint < m_glyph_count) - return glyph_width(codepoint); + if (code_point < m_glyph_count) + return glyph_width(code_point); if (m_fixed_width) return m_glyph_width; - auto* emoji = Emoji::emoji_for_codepoint(codepoint); + auto* emoji = Emoji::emoji_for_code_point(code_point); if (emoji == nullptr) return glyph_width('?'); return emoji->size().width(); @@ -285,11 +285,11 @@ int Font::width(const Utf8View& utf8) const bool first = true; int width = 0; - for (u32 codepoint : utf8) { + for (u32 code_point : utf8) { if (!first) width += glyph_spacing(); first = false; - width += glyph_or_emoji_width(codepoint); + width += glyph_or_emoji_width(code_point); } return width; @@ -301,7 +301,7 @@ int Font::width(const Utf32View& view) const return 0; int width = (view.length() - 1) * glyph_spacing(); for (size_t i = 0; i < view.length(); ++i) - width += glyph_or_emoji_width(view.codepoints()[i]); + width += glyph_or_emoji_width(view.code_points()[i]); return width; } diff --git a/Libraries/LibGfx/Font.h b/Libraries/LibGfx/Font.h index a28fde8a78..001b55bfb8 100644 --- a/Libraries/LibGfx/Font.h +++ b/Libraries/LibGfx/Font.h @@ -89,10 +89,10 @@ public: ~Font(); - GlyphBitmap glyph_bitmap(u32 codepoint) const; + GlyphBitmap glyph_bitmap(u32 code_point) const; u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; } - int glyph_or_emoji_width(u32 codepoint) const; + int glyph_or_emoji_width(u32 code_point) const; u8 glyph_height() const { return m_glyph_height; } u8 min_glyph_width() const { return m_min_glyph_width; } u8 max_glyph_width() const { return m_max_glyph_width; } diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index 333dc3daa4..ab807dafb1 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -803,14 +803,14 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s } } -FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, Color color) +FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, Color color) { - draw_glyph(point, codepoint, font(), color); + draw_glyph(point, code_point, font(), color); } -FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, const Font& font, Color color) +FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, const Font& font, Color color) { - draw_bitmap(point, font.glyph_bitmap(codepoint), color); + draw_bitmap(point, font.glyph_bitmap(code_point), color); } void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const Font& font) @@ -828,19 +828,19 @@ void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const } } -void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 codepoint, const Font& font, Color color) +void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 code_point, const Font& font, Color color) { - if (codepoint < (u32)font.glyph_count()) { + if (code_point < (u32)font.glyph_count()) { // This looks like a regular character. - draw_glyph(point, (size_t)codepoint, font, color); + draw_glyph(point, (size_t)code_point, font, color); return; } // Perhaps it's an emoji? - auto* emoji = Emoji::emoji_for_codepoint(codepoint); + auto* emoji = Emoji::emoji_for_code_point(code_point); if (emoji == nullptr) { #ifdef EMOJI_DEBUG - dbg() << "Failed to find an emoji for codepoint " << codepoint; + dbg() << "Failed to find an emoji for code_point " << code_point; #endif draw_glyph(point, '?', font, color); return; @@ -862,8 +862,8 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf8View& text, const int new_width = font.width("..."); if (new_width < text_width) { for (auto it = final_text.begin(); it != final_text.end(); ++it) { - u32 codepoint = *it; - int glyph_width = font.glyph_or_emoji_width(codepoint); + u32 code_point = *it; + int glyph_width = font.glyph_or_emoji_width(code_point); // NOTE: Glyph spacing should not be added after the last glyph on the line, // but since we are here because the last glyph does not actually fit on the line, // we don't have to worry about spacing. @@ -904,13 +904,13 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf8View& text, const auto point = rect.location(); int space_width = font.glyph_width(' ') + font.glyph_spacing(); - for (u32 codepoint : final_text) { - if (codepoint == ' ') { + for (u32 code_point : final_text) { + if (code_point == ' ') { point.move_by(space_width, 0); continue; } - draw_glyph_or_emoji(point, codepoint, font, color); - point.move_by(font.glyph_or_emoji_width(codepoint) + font.glyph_spacing(), 0); + draw_glyph_or_emoji(point, code_point, font, color); + point.move_by(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), 0); } } @@ -927,8 +927,8 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const if (new_width < text_width) { size_t i = 0; for (; i < text.length(); ++i) { - u32 codepoint = text.codepoints()[i]; - int glyph_width = font.glyph_or_emoji_width(codepoint); + u32 code_point = text.code_points()[i]; + int glyph_width = font.glyph_or_emoji_width(code_point); // NOTE: Glyph spacing should not be added after the last glyph on the line, // but since we are here because the last glyph does not actually fit on the line, // we don't have to worry about spacing. @@ -938,7 +938,7 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const new_width += glyph_width + glyph_spacing; } elided_text.clear(); - elided_text.append(final_text.codepoints(), i); + elided_text.append(final_text.code_points(), i); elided_text.append('.'); elided_text.append('.'); elided_text.append('.'); @@ -970,13 +970,13 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const int space_width = font.glyph_width(' ') + font.glyph_spacing(); for (size_t i = 0; i < final_text.length(); ++i) { - auto codepoint = final_text.codepoints()[i]; - if (codepoint == ' ') { + auto code_point = final_text.code_points()[i]; + if (code_point == ' ') { point.move_by(space_width, 0); continue; } - draw_glyph_or_emoji(point, codepoint, font, color); - point.move_by(font.glyph_or_emoji_width(codepoint) + font.glyph_spacing(), 0); + draw_glyph_or_emoji(point, code_point, font, color); + point.move_by(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), 0); } } @@ -997,8 +997,8 @@ void Painter::draw_text(const IntRect& rect, const StringView& raw_text, const F int start_of_current_line = 0; for (auto it = text.begin(); it != text.end(); ++it) { - u32 codepoint = *it; - if (codepoint == '\n') { + u32 code_point = *it; + if (code_point == '\n') { int byte_offset = text.byte_offset_of(it); Utf8View line = text.substring_view(start_of_current_line, byte_offset - start_of_current_line); lines.append(line); @@ -1055,8 +1055,8 @@ void Painter::draw_text(const IntRect& rect, const Utf32View& text, const Font& size_t start_of_current_line = 0; for (size_t i = 0; i < text.length(); ++i) { - u32 codepoint = text.codepoints()[i]; - if (codepoint == '\n') { + u32 code_point = text.code_points()[i]; + if (code_point == '\n') { Utf32View line = text.substring_view(start_of_current_line, i - start_of_current_line); lines.append(line); start_of_current_line = i + 1; diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h index e712bc04bb..ee84db265a 100644 --- a/Libraries/LibGfx/Painter.h +++ b/Libraries/LibGfx/Painter.h @@ -81,7 +81,7 @@ public: void draw_glyph(const IntPoint&, u32, Color); void draw_glyph(const IntPoint&, u32, const Font&, Color); void draw_emoji(const IntPoint&, const Gfx::Bitmap&, const Font&); - void draw_glyph_or_emoji(const IntPoint&, u32 codepoint, const Font&, Color); + void draw_glyph_or_emoji(const IntPoint&, u32 code_point, const Font&, Color); static void for_each_line_segment_on_bezier_curve(const FloatPoint& control_point, const FloatPoint& p1, const FloatPoint& p2, Function<void(const FloatPoint&, const FloatPoint&)>&); static void for_each_line_segment_on_bezier_curve(const FloatPoint& control_point, const FloatPoint& p1, const FloatPoint& p2, Function<void(const FloatPoint&, const FloatPoint&)>&&); diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index f06bab3572..8411503777 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -834,7 +834,7 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(Token token) auto type = status == Token::StringValueStatus::MalformedUnicodeEscape ? "unicode" : "hexadecimal"; message = String::format("Malformed %s escape sequence", type); } else if (status == Token::StringValueStatus::UnicodeEscapeOverflow) { - message = "Unicode codepoint must not be greater than 0x10ffff in escape sequence"; + message = "Unicode code_point must not be greater than 0x10ffff in escape sequence"; } syntax_error( diff --git a/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp b/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp index 39acbb25d7..15b3f15716 100644 --- a/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp @@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next) } StringBuilder builder; - builder.append_codepoint(*utf8_iterator); + builder.append_code_point(*utf8_iterator); ++utf8_iterator; return create_iterator_result_object(global_object, js_string(interpreter, builder.to_string()), false); diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index 529438baab..1b00208d30 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -321,7 +321,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring) if (interpreter.argument_count() == 0) return js_string(interpreter, string); - // FIXME: index_start and index_end should index a UTF-16 codepoint view of the string. + // FIXME: index_start and index_end should index a UTF-16 code_point view of the string. auto string_length = string.length(); auto index_start = min(interpreter.argument(0).to_size_t(interpreter), string_length); if (interpreter.exception()) @@ -358,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes) if (interpreter.exception()) return {}; - // FIXME: position should index a UTF-16 codepoint view of the string. + // FIXME: position should index a UTF-16 code_point view of the string. size_t position = 0; if (interpreter.argument_count() >= 2) { position = interpreter.argument(1).to_size_t(interpreter); @@ -385,7 +385,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice) if (interpreter.argument_count() == 0) return js_string(interpreter, string); - // FIXME: index_start and index_end should index a UTF-16 codepoint view of the string. + // FIXME: index_start and index_end should index a UTF-16 code_point view of the string. auto string_length = static_cast<i32>(string.length()); auto index_start = interpreter.argument(0).to_i32(interpreter); if (interpreter.exception()) @@ -437,7 +437,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of) auto max_index = string.length() - search_string.length(); auto from_index = max_index; if (interpreter.argument_count() >= 2) { - // FIXME: from_index should index a UTF-16 codepoint view of the string. + // FIXME: from_index should index a UTF-16 code_point view of the string. from_index = min(interpreter.argument(1).to_size_t(interpreter), max_index); if (interpreter.exception()) return {}; diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 82eb484ad0..af52fe2e51 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -917,10 +917,10 @@ TriState abstract_relation(Interpreter& interpreter, bool left_first, Value lhs, if (y_string.starts_with(x_string)) return TriState::True; - Utf8View x_codepoints { x_string }; - Utf8View y_codepoints { y_string }; - for (auto k = x_codepoints.begin(), l = y_codepoints.begin(); - k != x_codepoints.end() && l != y_codepoints.end(); + Utf8View x_code_points { x_string }; + Utf8View y_code_points { y_string }; + for (auto k = x_code_points.begin(), l = y_code_points.begin(); + k != x_code_points.end() && l != y_code_points.end(); ++k, ++l) { if (*k != *l) { if (*k < *l) { diff --git a/Libraries/LibJS/Token.cpp b/Libraries/LibJS/Token.cpp index 9ceedc094f..22ec42ce80 100644 --- a/Libraries/LibJS/Token.cpp +++ b/Libraries/LibJS/Token.cpp @@ -136,7 +136,7 @@ String Token::string_value(StringValueStatus& status) const auto digit2 = m_value[++i]; if (!isxdigit(digit1) || !isxdigit(digit2)) return encoding_failure(StringValueStatus::MalformedHexEscape); - builder.append_codepoint(hex2int(digit1) * 16 + hex2int(digit2)); + builder.append_code_point(hex2int(digit1) * 16 + hex2int(digit2)); break; } case 'u': { @@ -174,7 +174,7 @@ String Token::string_value(StringValueStatus& status) const } } - builder.append_codepoint(code_point); + builder.append_code_point(code_point); break; } default: diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 798130a390..a77a158216 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_points()[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_point_length_in_utf8(u32 code_point) { - if (codepoint <= 0x7f) + if (code_point <= 0x7f) return 1; - if (codepoint <= 0x07ff) + if (code_point <= 0x07ff) return 2; - if (codepoint <= 0xffff) + if (code_point <= 0xffff) return 3; - if (codepoint <= 0x10ffff) + if (code_point <= 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_point 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_point_offset_range(size_t start_byte_offset, size_t end_byte_offset, size_t scan_code_point_offset, bool reverse) const { size_t byte_offset = 0; - size_t codepoint_offset = scan_codepoint_offset + (reverse ? 1 : 0); + size_t code_point_offset = scan_code_point_offset + (reverse ? 1 : 0); CodepointRange range; for (;;) { if (!reverse) { - if (codepoint_offset >= m_buffer.size()) + if (code_point_offset >= m_buffer.size()) break; } else { - if (codepoint_offset == 0) + if (code_point_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_point_length_in_utf8(m_buffer[reverse ? --code_point_offset : code_point_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_point_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_point_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; @@ -445,7 +445,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_points = 0; enum Amount { Character, @@ -552,18 +552,18 @@ void Editor::handle_read_event() m_refresh_needed = true; }; - for (auto codepoint : input_view) { + for (auto code_point : input_view) { if (m_finish) break; - ++consumed_codepoints; + ++consumed_code_points; - if (codepoint == 0) + if (code_point == 0) continue; switch (m_state) { case InputState::ExpectBracket: - if (codepoint == '[') { + if (code_point == '[') { m_state = InputState::ExpectFinal; continue; } else { @@ -571,7 +571,7 @@ void Editor::handle_read_event() break; } case InputState::ExpectFinal: - switch (codepoint) { + switch (code_point) { case 'O': // mod_ctrl ctrl_held = true; continue; @@ -621,7 +621,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_point, code_point); m_state = InputState::Free; ctrl_held = false; continue; @@ -631,14 +631,14 @@ void Editor::handle_read_event() m_state = InputState::Free; continue; case InputState::Free: - if (codepoint == 27) { + if (code_point == 27) { m_state = InputState::ExpectBracket; continue; } break; } - auto cb = m_key_callbacks.get(codepoint); + auto cb = m_key_callbacks.get(code_point); if (cb.has_value()) { if (!cb.value()->callback(*this)) { continue; @@ -646,19 +646,19 @@ void Editor::handle_read_event() } // ^N - if (codepoint == ctrl('N')) { + if (code_point == ctrl('N')) { do_search_forwards(); continue; } // ^P - if (codepoint == ctrl('P')) { + if (code_point == ctrl('P')) { do_search_backwards(); continue; } m_search_offset = 0; // reset search offset on any key - if (codepoint == '\t' || reverse_tab) { + if (code_point == '\t' || reverse_tab) { if (!on_tab_complete) continue; @@ -773,7 +773,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_point == m_termios.c_cc[VWERASE]) { bool has_seen_nonspace = false; while (m_cursor > 0) { if (isspace(m_buffer[m_cursor - 1])) { @@ -786,7 +786,7 @@ void Editor::handle_read_event() } continue; } - if (codepoint == m_termios.c_cc[VKILL]) { + if (code_point == m_termios.c_cc[VKILL]) { for (size_t i = 0; i < m_cursor; ++i) remove_at_index(0); m_cursor = 0; @@ -795,7 +795,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_point == m_termios.c_cc[VEOF] && m_buffer.is_empty()) { printf("<EOF>\n"); if (!m_always_refresh) { m_input_error = Error::Eof; @@ -804,37 +804,37 @@ void Editor::handle_read_event() continue; } // ^A - if (codepoint == ctrl('A')) { + if (code_point == ctrl('A')) { m_cursor = 0; continue; } // ^B - if (codepoint == ctrl('B')) { + if (code_point == ctrl('B')) { do_cursor_left(Character); continue; } // ^D - if (codepoint == ctrl('D')) { + if (code_point == ctrl('D')) { do_delete(); continue; } // ^E - if (codepoint == ctrl('E')) { + if (code_point == ctrl('E')) { m_cursor = m_buffer.size(); continue; } // ^F - if (codepoint == ctrl('F')) { + if (code_point == ctrl('F')) { do_cursor_right(Character); continue; } // ^H: ctrl('H') == '\b' - if (codepoint == '\b' || codepoint == m_termios.c_cc[VERASE]) { + if (code_point == '\b' || code_point == m_termios.c_cc[VERASE]) { do_backspace(); continue; } // ^L - if (codepoint == ctrl('L')) { + if (code_point == ctrl('L')) { printf("\033[3J\033[H\033[2J"); // Clear screen. VT::move_absolute(1, 1); set_origin(1, 1); @@ -842,7 +842,7 @@ void Editor::handle_read_event() continue; } // ^R - if (codepoint == ctrl('R')) { + if (code_point == ctrl('R')) { if (m_is_searching) { // how did we get here? ASSERT_NOT_REACHED(); @@ -850,8 +850,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_point : m_buffer) + m_pre_search_buffer.append(code_point); m_pre_search_cursor = m_cursor; // Disable our own notifier so as to avoid interfering with the search editor. @@ -958,7 +958,7 @@ void Editor::handle_read_event() continue; } // ^T - if (codepoint == ctrl('T')) { + if (code_point == ctrl('T')) { if (m_cursor > 0 && m_buffer.size() >= 2) { if (m_cursor < m_buffer.size()) ++m_cursor; @@ -968,18 +968,18 @@ void Editor::handle_read_event() } continue; } - if (codepoint == '\n') { + if (code_point == '\n') { finish(); continue; } - insert(codepoint); + insert(code_point); } - if (consumed_codepoints == m_incomplete_data.size()) { + if (consumed_code_points == 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_points; ++i) m_incomplete_data.take_first(); } } @@ -1425,8 +1425,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_points()[i]; + auto next_c = i + 1 < view.length() ? view.code_points()[i + 1] : 0; state = actual_rendered_string_length_step(metrics, length, c, next_c, state); } diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index 343f6687e7..5574184550 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -310,7 +310,7 @@ private: size_t start { 0 }; size_t end { 0 }; }; - CodepointRange byte_offset_range_to_codepoint_offset_range(size_t byte_start, size_t byte_end, size_t codepoint_scan_offset, bool reverse = false) const; + CodepointRange byte_offset_range_to_code_point_offset_range(size_t byte_start, size_t byte_end, size_t code_point_scan_offset, bool reverse = false) const; void get_terminal_size(); diff --git a/Libraries/LibLine/SuggestionManager.cpp b/Libraries/LibLine/SuggestionManager.cpp index 11c92899ff..f7c0667e49 100644 --- a/Libraries/LibLine/SuggestionManager.cpp +++ b/Libraries/LibLine/SuggestionManager.cpp @@ -59,16 +59,16 @@ void SuggestionManager::set_suggestions(Vector<CompletionSuggestion>&& suggestio if (m_suggestions.size() == 1) { m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length(); } else if (m_suggestions.size()) { - u32 last_valid_suggestion_codepoint; + u32 last_valid_suggestion_code_point; for (;; ++common_suggestion_prefix) { if (m_suggestions[0].text_view.length() <= common_suggestion_prefix) goto no_more_commons; - last_valid_suggestion_codepoint = m_suggestions[0].text_view.codepoints()[common_suggestion_prefix]; + last_valid_suggestion_code_point = m_suggestions[0].text_view.code_points()[common_suggestion_prefix]; for (auto& suggestion : m_suggestions) { - if (suggestion.text_view.length() <= common_suggestion_prefix || suggestion.text_view.codepoints()[common_suggestion_prefix] != last_valid_suggestion_codepoint) { + if (suggestion.text_view.length() <= common_suggestion_prefix || suggestion.text_view.code_points()[common_suggestion_prefix] != last_valid_suggestion_code_point) { goto no_more_commons; } } diff --git a/Libraries/LibTextCodec/Decoder.cpp b/Libraries/LibTextCodec/Decoder.cpp index a00c6c6493..2c62037962 100644 --- a/Libraries/LibTextCodec/Decoder.cpp +++ b/Libraries/LibTextCodec/Decoder.cpp @@ -65,8 +65,8 @@ String Latin1Decoder::to_utf8(const StringView& input) StringBuilder builder(input.length()); for (size_t i = 0; i < input.length(); ++i) { u8 ch = input[i]; - // Latin1 is the same as the first 256 Unicode codepoints, so no mapping is needed, just utf-8 encoding. - builder.append_codepoint(ch); + // Latin1 is the same as the first 256 Unicode code_points, so no mapping is needed, just utf-8 encoding. + builder.append_code_point(ch); } return builder.to_string(); } diff --git a/Libraries/LibVT/Line.cpp b/Libraries/LibVT/Line.cpp index efa438c5d4..9b1e42a58b 100644 --- a/Libraries/LibVT/Line.cpp +++ b/Libraries/LibVT/Line.cpp @@ -37,25 +37,25 @@ Line::Line(u16 length) Line::~Line() { if (m_utf32) - delete[] m_codepoints.as_u32; + delete[] m_code_points.as_u32; else - delete[] m_codepoints.as_u8; + delete[] m_code_points.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_point_array(size_t new_length, const CodepointType* old_code_points, size_t old_length) { - auto* new_codepoints = new CodepointType[new_length]; + auto* new_code_points = new CodepointType[new_length]; for (size_t i = 0; i < new_length; ++i) - new_codepoints[i] = ' '; - if (old_codepoints) { + new_code_points[i] = ' '; + if (old_code_points) { for (size_t i = 0; i < min(old_length, new_length); ++i) { - new_codepoints[i] = old_codepoints[i]; + new_code_points[i] = old_code_points[i]; } } - delete[] old_codepoints; - return new_codepoints; + delete[] old_code_points; + return new_code_points; } 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_points.as_u32 = create_new_code_point_array<u32>(new_length, m_code_points.as_u32, m_length); else - m_codepoints.as_u8 = create_new_codepoint_array<u8>(new_length, m_codepoints.as_u8, m_length); + m_code_points.as_u8 = create_new_code_point_array<u8>(new_length, m_code_points.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_point(i, ' '); m_attributes[i] = attribute; } return; } for (unsigned i = 0; i < m_length; ++i) { - if (codepoint(i) != ' ') + if (code_point(i) != ' ') m_dirty = true; - set_codepoint(i, ' '); + set_code_point(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_points = new u32[m_length]; for (size_t i = 0; i < m_length; ++i) { - new_codepoints[i] = m_codepoints.as_u8[i]; + new_code_points[i] = m_code_points.as_u8[i]; } - delete m_codepoints.as_u8; - m_codepoints.as_u32 = new_codepoints; + delete m_code_points.as_u8; + m_code_points.as_u32 = new_code_points; m_utf32 = true; } diff --git a/Libraries/LibVT/Line.h b/Libraries/LibVT/Line.h index ac456f8bfc..3bbeadf1f1 100644 --- a/Libraries/LibVT/Line.h +++ b/Libraries/LibVT/Line.h @@ -90,22 +90,22 @@ public: u16 length() const { return m_length; } - u32 codepoint(size_t index) const + u32 code_point(size_t index) const { if (m_utf32) - return m_codepoints.as_u32[index]; - return m_codepoints.as_u8[index]; + return m_code_points.as_u32[index]; + return m_code_points.as_u8[index]; } - void set_codepoint(size_t index, u32 codepoint) + void set_code_point(size_t index, u32 code_point) { - if (!m_utf32 && codepoint & 0xffffff80u) + if (!m_utf32 && code_point & 0xffffff80u) convert_to_utf32(); if (m_utf32) - m_codepoints.as_u32[index] = codepoint; + m_code_points.as_u32[index] = code_point; else - m_codepoints.as_u8[index] = codepoint; + m_code_points.as_u8[index] = code_point; } bool is_dirty() const { return m_dirty; } @@ -122,7 +122,7 @@ private: union { u8* as_u8; u32* as_u32; - } m_codepoints { nullptr }; + } m_code_points { nullptr }; Attribute* m_attributes { nullptr }; bool m_dirty { false }; bool m_utf32 { false }; diff --git a/Libraries/LibVT/Terminal.cpp b/Libraries/LibVT/Terminal.cpp index 01adcacbd0..9ec0e61e2b 100644 --- a/Libraries/LibVT/Terminal.cpp +++ b/Libraries/LibVT/Terminal.cpp @@ -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_point); } 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_point(i, line.code_point(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_point(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_point) { ASSERT(row < rows()); ASSERT(column < columns()); auto& line = m_lines[row]; - line.set_codepoint(column, codepoint); + line.set_code_point(column, code_point); line.attributes()[column] = m_current_attribute; line.attributes()[column].flags |= Attribute::Touched; line.set_dirty(true); - m_last_codepoint = codepoint; + m_last_code_point = code_point; } 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_point('%'); }; auto advance_utf8_parse = [this, ch] { - m_parser_codepoint <<= 6; - m_parser_codepoint |= ch & 0x3f; + m_parser_code_point <<= 6; + m_parser_code_point |= ch & 0x3f; if (m_parser_state == UTF8Needs1Byte) { - on_codepoint(m_parser_codepoint); + on_code_point(m_parser_code_point); 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_point = ch & 0x1f; return; } if ((ch & 0xf0) == 0xe0) { m_parser_state = UTF8Needs2Bytes; - m_parser_codepoint = ch & 0x0f; + m_parser_code_point = ch & 0x0f; return; } if ((ch & 0xf8) == 0xf0) { m_parser_state = UTF8Needs3Bytes; - m_parser_codepoint = ch & 0x07; + m_parser_code_point = ch & 0x07; return; } fail_utf8_parse(); @@ -978,26 +978,26 @@ void Terminal::on_input(u8 ch) return; } - on_codepoint(ch); + on_code_point(ch); } -void Terminal::on_codepoint(u32 codepoint) +void Terminal::on_code_point(u32 code_point) { 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_point); 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_point); 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_point); } } @@ -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_point(code_point); emit_string(sb.to_string()); } diff --git a/Libraries/LibVT/Terminal.h b/Libraries/LibVT/Terminal.h index e1d565cdff..c1f7fc0b6b 100644 --- a/Libraries/LibVT/Terminal.h +++ b/Libraries/LibVT/Terminal.h @@ -106,7 +106,7 @@ public: private: typedef Vector<unsigned, 4> ParamVector; - void on_codepoint(u32); + void on_code_point(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_point { 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_point { 0 }; }; } diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp index 3d9f8fea32..cd61db7847 100644 --- a/Libraries/LibVT/TerminalWidget.cpp +++ b/Libraries/LibVT/TerminalWidget.cpp @@ -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_point = line.code_point(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_point == ' ') continue; painter.draw_glyph_or_emoji( character_rect.location(), - codepoint, + code_point, 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_point(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_point(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_point(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_point = line.code_point(column); + builder.append(Utf32View(&code_point, 1)); } else { - builder.append(line.codepoint(column)); + builder.append(line.code_point(column)); } if (column == line.length() - 1 || (m_rectangle_selection && column == last_column)) { builder.append('\n'); diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index de382cf9ba..14fd04e568 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -272,10 +272,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa) Vector<u8> byte_string; byte_string.ensure_capacity(string.length()); - for (u32 codepoint : Utf8View(string)) { - if (codepoint > 0xff) + for (u32 code_point : Utf8View(string)) { + if (code_point > 0xff) return interpreter.throw_exception<JS::InvalidCharacterError>(JS::ErrorType::NotAByteString, "btoa"); - byte_string.append(codepoint); + byte_string.append(code_point); } auto encoded = encode_base64(byte_string.span()); diff --git a/Libraries/LibWeb/HTML/Parser/Entities.cpp b/Libraries/LibWeb/HTML/Parser/Entities.cpp index 088d6f9bc9..edda468b0a 100644 --- a/Libraries/LibWeb/HTML/Parser/Entities.cpp +++ b/Libraries/LibWeb/HTML/Parser/Entities.cpp @@ -31,12 +31,12 @@ namespace Web { namespace HTML { -Optional<EntityMatch> codepoints_from_entity(const StringView& entity) +Optional<EntityMatch> code_points_from_entity(const StringView& entity) { constexpr struct { StringView entity; - u32 codepoint; - } single_codepoint_entities[] = { + u32 code_point; + } single_code_point_entities[] = { { "AElig;", 0x000C6 }, { "AElig", 0x000C6 }, { "AMP;", 0x00026 }, @@ -2179,9 +2179,9 @@ Optional<EntityMatch> codepoints_from_entity(const StringView& entity) constexpr struct { StringView entity; - u32 codepoint1; - u32 codepoint2; - } double_codepoint_entities[] = { + u32 code_point1; + u32 code_point2; + } double_code_point_entities[] = { { "NotEqualTilde;", 0x02242, 0x00338 }, { "NotGreaterFullEqual;", 0x02267, 0x00338 }, { "NotGreaterGreater;", 0x0226B, 0x00338 }, @@ -2279,17 +2279,17 @@ Optional<EntityMatch> codepoints_from_entity(const StringView& entity) EntityMatch match; - for (auto& single_codepoint_entity : single_codepoint_entities) { - if (entity.starts_with(single_codepoint_entity.entity)) { - if (match.entity.is_null() || single_codepoint_entity.entity.length() > match.entity.length()) - match = { { single_codepoint_entity.codepoint }, single_codepoint_entity.entity }; + for (auto& single_code_point_entity : single_code_point_entities) { + if (entity.starts_with(single_code_point_entity.entity)) { + if (match.entity.is_null() || single_code_point_entity.entity.length() > match.entity.length()) + match = { { single_code_point_entity.code_point }, single_code_point_entity.entity }; } } - for (auto& double_codepoint_entity : double_codepoint_entities) { - if (entity.starts_with(double_codepoint_entity.entity)) { - if (match.entity.is_null() || double_codepoint_entity.entity.length() > match.entity.length()) - match = EntityMatch { { double_codepoint_entity.codepoint1, double_codepoint_entity.codepoint2 }, StringView(double_codepoint_entity.entity) }; + for (auto& double_code_point_entity : double_code_point_entities) { + if (entity.starts_with(double_code_point_entity.entity)) { + if (match.entity.is_null() || double_code_point_entity.entity.length() > match.entity.length()) + match = EntityMatch { { double_code_point_entity.code_point1, double_code_point_entity.code_point2 }, StringView(double_code_point_entity.entity) }; } } diff --git a/Libraries/LibWeb/HTML/Parser/Entities.h b/Libraries/LibWeb/HTML/Parser/Entities.h index 0e65a068a6..0701f3be8d 100644 --- a/Libraries/LibWeb/HTML/Parser/Entities.h +++ b/Libraries/LibWeb/HTML/Parser/Entities.h @@ -33,11 +33,11 @@ namespace Web { namespace HTML { struct EntityMatch { - Vector<u32, 2> codepoints; + Vector<u32, 2> code_points; StringView entity; }; -Optional<EntityMatch> codepoints_from_entity(const StringView&); +Optional<EntityMatch> code_points_from_entity(const StringView&); } } diff --git a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 59aaef631a..ca8ab1f683 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -472,7 +472,7 @@ void HTMLDocumentParser::insert_comment(HTMLToken& token) void HTMLDocumentParser::handle_in_head(HTMLToken& token) { if (token.is_parser_whitespace()) { - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } @@ -671,7 +671,7 @@ void HTMLDocumentParser::insert_character(u32 data) void HTMLDocumentParser::handle_after_head(HTMLToken& token) { if (token.is_character() && token.is_parser_whitespace()) { - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } @@ -1004,17 +1004,17 @@ bool HTMLDocumentParser::is_special_tag(const FlyString& tag_name) void HTMLDocumentParser::handle_in_body(HTMLToken& token) { if (token.is_character()) { - if (token.codepoint() == 0) { + if (token.code_point() == 0) { PARSE_ERROR(); return; } if (token.is_parser_whitespace()) { reconstruct_the_active_formatting_elements(); - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } reconstruct_the_active_formatting_elements(); - insert_character(token.codepoint()); + insert_character(token.code_point()); m_frameset_ok = false; return; } @@ -1162,7 +1162,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) // then ignore that token and move on to the next one. // (Newlines at the start of pre blocks are ignored as an authoring convenience.) auto next_token = m_tokenizer.next_token(); - if (next_token.has_value() && next_token.value().is_character() && next_token.value().codepoint() == '\n') { + if (next_token.has_value() && next_token.value().is_character() && next_token.value().code_point() == '\n') { // Ignore it. } else { process_using_the_rules_for(m_insertion_mode, next_token.value()); @@ -1503,7 +1503,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) m_frameset_ok = false; m_insertion_mode = InsertionMode::Text; - if (next_token.has_value() && next_token.value().is_character() && next_token.value().codepoint() == '\n') { + if (next_token.has_value() && next_token.value().is_character() && next_token.value().code_point() == '\n') { // Ignore it. } else { process_using_the_rules_for(m_insertion_mode, next_token.value()); @@ -1750,7 +1750,7 @@ void HTMLDocumentParser::decrement_script_nesting_level() void HTMLDocumentParser::handle_text(HTMLToken& token) { if (token.is_character()) { - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } if (token.is_end_of_file()) { @@ -1979,7 +1979,7 @@ void HTMLDocumentParser::handle_in_cell(HTMLToken& token) void HTMLDocumentParser::handle_in_table_text(HTMLToken& token) { if (token.is_character()) { - if (token.codepoint() == 0) { + if (token.code_point() == 0) { PARSE_ERROR(); return; } @@ -2000,7 +2000,7 @@ void HTMLDocumentParser::handle_in_table_text(HTMLToken& token) } for (auto& pending_token : m_pending_table_character_tokens) { - insert_character(pending_token.codepoint()); + insert_character(pending_token.code_point()); } m_insertion_mode = m_original_insertion_mode; @@ -2210,11 +2210,11 @@ void HTMLDocumentParser::handle_in_select_in_table(HTMLToken& token) void HTMLDocumentParser::handle_in_select(HTMLToken& token) { if (token.is_character()) { - if (token.codepoint() == 0) { + if (token.code_point() == 0) { PARSE_ERROR(); return; } - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } @@ -2384,7 +2384,7 @@ void HTMLDocumentParser::handle_in_caption(HTMLToken& token) void HTMLDocumentParser::handle_in_column_group(HTMLToken& token) { if (token.is_character() && token.is_parser_whitespace()) { - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } @@ -2527,7 +2527,7 @@ void HTMLDocumentParser::handle_in_template(HTMLToken& token) void HTMLDocumentParser::handle_in_frameset(HTMLToken& token) { if (token.is_character() && token.is_parser_whitespace()) { - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } @@ -2587,7 +2587,7 @@ void HTMLDocumentParser::handle_in_frameset(HTMLToken& token) void HTMLDocumentParser::handle_after_frameset(HTMLToken& token) { if (token.is_character() && token.is_parser_whitespace()) { - insert_character(token.codepoint()); + insert_character(token.code_point()); return; } diff --git a/Libraries/LibWeb/HTML/Parser/HTMLToken.h b/Libraries/LibWeb/HTML/Parser/HTMLToken.h index 13e12e9a83..fe43c25034 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLToken.h +++ b/Libraries/LibWeb/HTML/Parser/HTMLToken.h @@ -50,11 +50,11 @@ public: EndOfFile, }; - static HTMLToken make_character(u32 codepoint) + static HTMLToken make_character(u32 code_point) { HTMLToken token; token.m_type = Type::Character; - token.m_comment_or_character.data.append(codepoint); + token.m_comment_or_character.data.append(code_point); return token; } @@ -73,11 +73,11 @@ public: bool is_character() const { return m_type == Type::Character; } bool is_end_of_file() const { return m_type == Type::EndOfFile; } - u32 codepoint() const + u32 code_point() const { ASSERT(is_character()); Utf8View view(m_comment_or_character.data.string_view()); - ASSERT(view.length_in_codepoints() == 1); + ASSERT(view.length_in_code_points() == 1); return *view.begin(); } @@ -86,7 +86,7 @@ public: // NOTE: The parser considers '\r' to be whitespace, while the tokenizer does not. if (!is_character()) return false; - switch (codepoint()) { + switch (code_point()) { case '\t': case '\n': case '\f': diff --git a/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index cdc8ec8044..ddab59c5c1 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -46,7 +46,7 @@ namespace Web::HTML { #endif #define CONSUME_NEXT_INPUT_CHARACTER \ - current_input_character = next_codepoint(); + current_input_character = next_code_point(); #define SWITCH_TO(new_state) \ do { \ @@ -86,9 +86,9 @@ namespace Web::HTML { return m_queued_tokens.dequeue(); \ } while (0) -#define EMIT_CHARACTER_AND_RECONSUME_IN(codepoint, new_state) \ +#define EMIT_CHARACTER_AND_RECONSUME_IN(code_point, new_state) \ do { \ - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); \ + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); \ will_reconsume_in(State::new_state); \ m_state = State::new_state; \ goto new_state; \ @@ -96,12 +96,12 @@ namespace Web::HTML { #define FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \ do { \ - for (auto codepoint : m_temporary_buffer) { \ + for (auto code_point : m_temporary_buffer) { \ if (consumed_as_part_of_an_attribute()) { \ - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(codepoint); \ + m_current_token.m_tag.attributes.last().value_builder.append_code_point(code_point); \ } else { \ create_new_token(HTMLToken::Type::Character); \ - m_current_token.m_comment_or_character.data.append_codepoint(codepoint); \ + m_current_token.m_comment_or_character.data.append_code_point(code_point); \ m_queued_tokens.enqueue(m_current_token); \ } \ } \ @@ -112,8 +112,8 @@ namespace Web::HTML { m_utf8_iterator = m_prev_utf8_iterator; \ } while (0) -#define ON(codepoint) \ - if (current_input_character.has_value() && current_input_character.value() == codepoint) +#define ON(code_point) \ + if (current_input_character.has_value() && current_input_character.value() == code_point) #define ON_EOF \ if (!current_input_character.has_value()) @@ -159,10 +159,10 @@ namespace Web::HTML { return m_queued_tokens.dequeue(); \ } while (0) -#define EMIT_CHARACTER(codepoint) \ +#define EMIT_CHARACTER(code_point) \ do { \ create_new_token(HTMLToken::Type::Character); \ - m_current_token.m_comment_or_character.data.append_codepoint(codepoint); \ + m_current_token.m_comment_or_character.data.append_code_point(code_point); \ m_queued_tokens.enqueue(m_current_token); \ return m_queued_tokens.dequeue(); \ } while (0) @@ -170,11 +170,11 @@ namespace Web::HTML { #define EMIT_CURRENT_CHARACTER \ EMIT_CHARACTER(current_input_character.value()); -#define SWITCH_TO_AND_EMIT_CHARACTER(codepoint, new_state) \ +#define SWITCH_TO_AND_EMIT_CHARACTER(code_point, new_state) \ do { \ will_switch_to(State::new_state); \ m_state = State::new_state; \ - EMIT_CHARACTER(codepoint); \ + EMIT_CHARACTER(code_point); \ } while (0) #define SWITCH_TO_AND_EMIT_CURRENT_CHARACTER(new_state) \ @@ -193,39 +193,39 @@ namespace Web::HTML { } \ } -static inline bool is_surrogate(u32 codepoint) +static inline bool is_surrogate(u32 code_point) { - return (codepoint & 0xfffff800) == 0xd800; + return (code_point & 0xfffff800) == 0xd800; } -static inline bool is_noncharacter(u32 codepoint) +static inline bool is_noncharacter(u32 code_point) { - return codepoint >= 0xfdd0 && (codepoint <= 0xfdef || (codepoint & 0xfffe) == 0xfffe) && codepoint <= 0x10ffff; + return code_point >= 0xfdd0 && (code_point <= 0xfdef || (code_point & 0xfffe) == 0xfffe) && code_point <= 0x10ffff; } -static inline bool is_c0_control(u32 codepoint) +static inline bool is_c0_control(u32 code_point) { - return codepoint <= 0x1f; + return code_point <= 0x1f; } -static inline bool is_control(u32 codepoint) +static inline bool is_control(u32 code_point) { - return is_c0_control(codepoint) || (codepoint >= 0x7f && codepoint <= 0x9f); + return is_c0_control(code_point) || (code_point >= 0x7f && code_point <= 0x9f); } -Optional<u32> HTMLTokenizer::next_codepoint() +Optional<u32> HTMLTokenizer::next_code_point() { if (m_utf8_iterator == m_utf8_view.end()) return {}; m_prev_utf8_iterator = m_utf8_iterator; ++m_utf8_iterator; #ifdef TOKENIZER_TRACE - dbg() << "(Tokenizer) Next codepoint: " << (char)*m_prev_utf8_iterator; + dbg() << "(Tokenizer) Next code_point: " << (char)*m_prev_utf8_iterator; #endif return *m_prev_utf8_iterator; } -Optional<u32> HTMLTokenizer::peek_codepoint(size_t offset) const +Optional<u32> HTMLTokenizer::peek_code_point(size_t offset) const { auto it = m_utf8_iterator; for (size_t i = 0; i < offset && it != m_utf8_view.end(); ++i) @@ -242,7 +242,7 @@ _StartOfFunction: return m_queued_tokens.dequeue(); for (;;) { - auto current_input_character = next_codepoint(); + auto current_input_character = next_code_point(); switch (m_state) { BEGIN_STATE(Data) { @@ -328,7 +328,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_tag.tag_name.append_codepoint(0xFFFD); + m_current_token.m_tag.tag_name.append_code_point(0xFFFD); continue; } ON_EOF @@ -338,7 +338,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_tag.tag_name.append_codepoint(current_input_character.value()); + m_current_token.m_tag.tag_name.append_code_point(current_input_character.value()); continue; } } @@ -408,12 +408,12 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_comment_or_character.data.append_codepoint(0xFFFD); + m_current_token.m_comment_or_character.data.append_code_point(0xFFFD); continue; } ANYTHING_ELSE { - m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value()); + m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value()); continue; } } @@ -462,7 +462,7 @@ _StartOfFunction: { PARSE_ERROR(); create_new_token(HTMLToken::Type::DOCTYPE); - m_current_token.m_doctype.name.append_codepoint(0xFFFD); + m_current_token.m_doctype.name.append_code_point(0xFFFD); m_current_token.m_doctype.missing_name = false; SWITCH_TO(DOCTYPEName); } @@ -484,7 +484,7 @@ _StartOfFunction: ANYTHING_ELSE { create_new_token(HTMLToken::Type::DOCTYPE); - m_current_token.m_doctype.name.append_codepoint(current_input_character.value()); + m_current_token.m_doctype.name.append_code_point(current_input_character.value()); m_current_token.m_doctype.missing_name = false; SWITCH_TO(DOCTYPEName); } @@ -509,7 +509,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_doctype.name.append_codepoint(0xFFFD); + m_current_token.m_doctype.name.append_code_point(0xFFFD); continue; } ON_EOF @@ -521,7 +521,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_doctype.name.append_codepoint(current_input_character.value()); + m_current_token.m_doctype.name.append_code_point(current_input_character.value()); continue; } } @@ -732,7 +732,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_doctype.public_identifier.append_codepoint(0xFFFD); + m_current_token.m_doctype.public_identifier.append_code_point(0xFFFD); continue; } ON('>') @@ -750,7 +750,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_doctype.public_identifier.append_codepoint(current_input_character.value()); + m_current_token.m_doctype.public_identifier.append_code_point(current_input_character.value()); continue; } } @@ -765,7 +765,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_doctype.public_identifier.append_codepoint(0xFFFD); + m_current_token.m_doctype.public_identifier.append_code_point(0xFFFD); continue; } ON('>') @@ -783,7 +783,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_doctype.public_identifier.append_codepoint(current_input_character.value()); + m_current_token.m_doctype.public_identifier.append_code_point(current_input_character.value()); continue; } } @@ -798,7 +798,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_doctype.system_identifier.append_codepoint(0xFFFD); + m_current_token.m_doctype.system_identifier.append_code_point(0xFFFD); continue; } ON('>') @@ -816,7 +816,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_doctype.system_identifier.append_codepoint(current_input_character.value()); + m_current_token.m_doctype.system_identifier.append_code_point(current_input_character.value()); continue; } } @@ -831,7 +831,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_doctype.system_identifier.append_codepoint(0xFFFD); + m_current_token.m_doctype.system_identifier.append_code_point(0xFFFD); continue; } ON('>') @@ -849,7 +849,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_doctype.system_identifier.append_codepoint(current_input_character.value()); + m_current_token.m_doctype.system_identifier.append_code_point(current_input_character.value()); continue; } } @@ -1003,7 +1003,7 @@ _StartOfFunction: { PARSE_ERROR(); auto new_attribute = HTMLToken::AttributeBuilder(); - new_attribute.local_name_builder.append_codepoint(current_input_character.value()); + new_attribute.local_name_builder.append_code_point(current_input_character.value()); m_current_token.m_tag.attributes.append(new_attribute); SWITCH_TO(AttributeName); } @@ -1059,13 +1059,13 @@ _StartOfFunction: } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(tolower(current_input_character.value())); + m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(tolower(current_input_character.value())); continue; } ON(0) { PARSE_ERROR(); - m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(0xFFFD); + m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(0xFFFD); continue; } ON('"') @@ -1086,7 +1086,7 @@ _StartOfFunction: ANYTHING_ELSE { AnythingElseAttributeName: - m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(current_input_character.value()); + m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(current_input_character.value()); continue; } } @@ -1163,7 +1163,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD); continue; } ON_EOF @@ -1173,7 +1173,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value()); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); continue; } } @@ -1193,7 +1193,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD); continue; } ON_EOF @@ -1203,7 +1203,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value()); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); continue; } } @@ -1227,7 +1227,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD); continue; } ON('"') @@ -1263,7 +1263,7 @@ _StartOfFunction: ANYTHING_ELSE { AnythingElseAttributeValueUnquoted: - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value()); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); continue; } } @@ -1343,7 +1343,7 @@ _StartOfFunction: { ON('<') { - m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value()); + m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value()); SWITCH_TO(CommentLessThanSign); } ON('-') @@ -1353,7 +1353,7 @@ _StartOfFunction: ON(0) { PARSE_ERROR(); - m_current_token.m_comment_or_character.data.append_codepoint(0xFFFD); + m_current_token.m_comment_or_character.data.append_code_point(0xFFFD); continue; } ON_EOF @@ -1364,7 +1364,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value()); + m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value()); continue; } } @@ -1449,12 +1449,12 @@ _StartOfFunction: { ON('!') { - m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value()); + m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value()); SWITCH_TO(CommentLessThanSignBang); } ON('<') { - m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value()); + m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value()); continue; } ANYTHING_ELSE @@ -1533,7 +1533,7 @@ _StartOfFunction: { size_t byte_offset = m_utf8_view.byte_offset_of(m_prev_utf8_iterator); - auto match = HTML::codepoints_from_entity(m_decoded_input.substring_view(byte_offset, m_decoded_input.length() - byte_offset - 1)); + auto match = HTML::code_points_from_entity(m_decoded_input.substring_view(byte_offset, m_decoded_input.length() - byte_offset - 1)); if (match.has_value()) { for (size_t i = 0; i < match.value().entity.length() - 1; ++i) { @@ -1543,8 +1543,8 @@ _StartOfFunction: for (auto ch : match.value().entity) m_temporary_buffer.append(ch); - if (consumed_as_part_of_an_attribute() && match.value().codepoints.last() != ';') { - auto next = peek_codepoint(0); + if (consumed_as_part_of_an_attribute() && match.value().code_points.last() != ';') { + auto next = peek_code_point(0); if (next.has_value() && (next.value() == '=' || isalnum(next.value()))) { FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE; SWITCH_TO_RETURN_STATE; @@ -1552,8 +1552,8 @@ _StartOfFunction: } if (consumed_as_part_of_an_attribute() && match.value().entity.ends_with(';')) { - auto next_codepoint = peek_codepoint(0); - if (next_codepoint.has_value() && next_codepoint.value() == '=') { + auto next_code_point = peek_code_point(0); + if (next_code_point.has_value() && next_code_point.value() == '=') { FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE; SWITCH_TO_RETURN_STATE; } @@ -1564,7 +1564,7 @@ _StartOfFunction: } m_temporary_buffer.clear(); - m_temporary_buffer.append(match.value().codepoints); + m_temporary_buffer.append(match.value().code_points); FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE; SWITCH_TO_RETURN_STATE; @@ -1580,7 +1580,7 @@ _StartOfFunction: ON_ASCII_ALPHANUMERIC { if (consumed_as_part_of_an_attribute()) { - m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value()); + m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); continue; } else { EMIT_CURRENT_CHARACTER; @@ -1724,7 +1724,7 @@ _StartOfFunction: PARSE_ERROR(); constexpr struct { u32 number; - u32 codepoint; + u32 code_point; } conversion_table[] = { { 0x80, 0x20AC }, { 0x82, 0x201A }, @@ -1756,7 +1756,7 @@ _StartOfFunction: }; for (auto& entry : conversion_table) { if (m_character_reference_code == entry.number) { - m_character_reference_code = entry.codepoint; + m_character_reference_code = entry.code_point; break; } } @@ -1833,8 +1833,8 @@ _StartOfFunction: if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RCDATA); } SWITCH_TO(BeforeAttributeName); @@ -1844,8 +1844,8 @@ _StartOfFunction: if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RCDATA); } SWITCH_TO(SelfClosingStartTag); @@ -1855,8 +1855,8 @@ _StartOfFunction: if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RCDATA); } SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); @@ -1869,7 +1869,7 @@ _StartOfFunction: } ON_ASCII_LOWER_ALPHA { - m_current_token.m_tag.tag_name.append_codepoint(current_input_character.value()); + m_current_token.m_tag.tag_name.append_code_point(current_input_character.value()); m_temporary_buffer.append(current_input_character.value()); continue; } @@ -1877,8 +1877,8 @@ _StartOfFunction: { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RCDATA); } } @@ -1943,8 +1943,8 @@ _StartOfFunction: if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RAWTEXT); } SWITCH_TO(BeforeAttributeName); @@ -1954,8 +1954,8 @@ _StartOfFunction: if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RAWTEXT); } SWITCH_TO(SelfClosingStartTag); @@ -1965,8 +1965,8 @@ _StartOfFunction: if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RAWTEXT); } SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); @@ -1987,8 +1987,8 @@ _StartOfFunction: { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(RAWTEXT); } } @@ -2155,8 +2155,8 @@ _StartOfFunction: m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) { - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) { + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); } RECONSUME_IN(ScriptDataEscaped); } @@ -2167,8 +2167,8 @@ _StartOfFunction: m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) { - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) { + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); } RECONSUME_IN(ScriptDataEscaped); } @@ -2179,8 +2179,8 @@ _StartOfFunction: m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) { - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) { + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); } RECONSUME_IN(ScriptDataEscaped); } @@ -2200,8 +2200,8 @@ _StartOfFunction: { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) { - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) { + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); } RECONSUME_IN(ScriptDataEscaped); } @@ -2479,8 +2479,8 @@ _StartOfFunction: SWITCH_TO(BeforeAttributeName); m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(ScriptData); } ON('/') @@ -2489,8 +2489,8 @@ _StartOfFunction: SWITCH_TO(SelfClosingStartTag); m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(ScriptData); } ON('>') @@ -2499,8 +2499,8 @@ _StartOfFunction: SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(ScriptData); } ON_ASCII_UPPER_ALPHA @@ -2519,8 +2519,8 @@ _StartOfFunction: { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); - for (auto codepoint : m_temporary_buffer) - m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); + for (auto code_point : m_temporary_buffer) + m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); RECONSUME_IN(ScriptData); } } @@ -2585,18 +2585,18 @@ _StartOfFunction: bool HTMLTokenizer::consume_next_if_match(const StringView& string, CaseSensitivity case_sensitivity) { for (size_t i = 0; i < string.length(); ++i) { - auto codepoint = peek_codepoint(i); - if (!codepoint.has_value()) + auto code_point = peek_code_point(i); + if (!code_point.has_value()) return false; // FIXME: This should be more Unicode-aware. if (case_sensitivity == CaseSensitivity::CaseInsensitive) { - if (codepoint.value() < 0x80) { - if (tolower(codepoint.value()) != tolower(string[i])) + if (code_point.value() < 0x80) { + if (tolower(code_point.value()) != tolower(string[i])) return false; continue; } } - if (codepoint.value() != (u32)string[i]) + if (code_point.value() != (u32)string[i]) return false; } for (size_t i = 0; i < string.length(); ++i) { diff --git a/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.h b/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.h index f4aa69ab91..787bc12b46 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.h +++ b/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.h @@ -137,8 +137,8 @@ public: String source() const { return m_decoded_input; } private: - Optional<u32> next_codepoint(); - Optional<u32> peek_codepoint(size_t offset) const; + Optional<u32> next_code_point(); + Optional<u32> peek_code_point(size_t offset) const; bool consume_next_if_match(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive); void create_new_token(HTMLToken::Type); bool current_end_tag_token_is_appropriate() const; diff --git a/Libraries/LibWeb/Layout/LayoutText.cpp b/Libraries/LibWeb/Layout/LayoutText.cpp index 61839b4bb1..769abc6d93 100644 --- a/Libraries/LibWeb/Layout/LayoutText.cpp +++ b/Libraries/LibWeb/Layout/LayoutText.cpp @@ -209,7 +209,7 @@ void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode la skip_over_whitespace(); for (; it != utf8_view.end(); ++it) { if (!isspace(*it)) { - builder.append(utf8_view.as_string().characters_without_null_termination() + utf8_view.byte_offset_of(it), it.codepoint_length_in_bytes()); + builder.append(utf8_view.as_string().characters_without_null_termination() + utf8_view.byte_offset_of(it), it.code_point_length_in_bytes()); } else { builder.append(' '); skip_over_whitespace(); diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index c9768ab7c7..55769c7699 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -255,7 +255,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned, u32 code_point) auto& text_node = downcast<DOM::Text>(*m_frame.cursor_position().node()); StringBuilder builder; builder.append(text_node.data().substring_view(0, m_frame.cursor_position().offset())); - builder.append_codepoint(code_point); + builder.append_code_point(code_point); builder.append(text_node.data().substring_view(m_frame.cursor_position().offset(), text_node.data().length() - m_frame.cursor_position().offset())); text_node.set_data(builder.to_string()); // FIXME: This will advance the cursor incorrectly when inserting multiple whitespaces (DOM vs layout whitespace collapse difference.) diff --git a/Services/WindowServer/MenuManager.cpp b/Services/WindowServer/MenuManager.cpp index 13f1b7c265..7ea8f5aa11 100644 --- a/Services/WindowServer/MenuManager.cpp +++ b/Services/WindowServer/MenuManager.cpp @@ -146,7 +146,7 @@ void MenuManager::event(Core::Event& event) if (m_current_menu && event.type() == Event::KeyDown && ((key_event.key() >= Key_A && key_event.key() <= Key_Z) || (key_event.key() >= Key_0 && key_event.key() <= Key_9))) { - m_current_search.append_codepoint(key_event.code_point()); + m_current_search.append_code_point(key_event.code_point()); m_search_timer->restart(s_search_timeout); for (int i = 0; i < m_current_menu->item_count(); ++i) { auto text = m_current_menu->item(i).text(); diff --git a/Userland/ls.cpp b/Userland/ls.cpp index c4f2fb1bf5..5fd6c45fcf 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -144,7 +144,7 @@ int print_escaped(const char* name) Utf8View utf8_name(name); if (utf8_name.validate()) { printf("%s", name); - return utf8_name.length_in_codepoints(); + return utf8_name.length_in_code_points(); } for (int i = 0; name[i] != '\0'; i++) { |