Revert "Unicode: s/codepoint/code_point/g"

This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
This commit is contained in:
Nico Weber 2020-08-05 16:28:19 -04:00 committed by Andreas Kling
parent 9664bac281
commit 19ac1f6368
Notes: sideshowbarker 2024-07-19 04:15:33 +09:00
45 changed files with 449 additions and 449 deletions

View file

@ -126,9 +126,9 @@ String JsonParser::consume_quoted_string()
sb.append(consume());
sb.append(consume());
auto code_points = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
if (code_points.has_value()) {
final_sb.append_code_points(code_points.value());
auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
if (codepoint.has_value()) {
final_sb.append_codepoint(codepoint.value());
} else {
final_sb.append('?');
}

View file

@ -113,22 +113,22 @@ void StringBuilder::clear()
m_length = 0;
}
void StringBuilder::append_code_points(u32 code_points)
void StringBuilder::append_codepoint(u32 codepoint)
{
if (code_points <= 0x7f) {
append((char)code_points);
} else if (code_points <= 0x07ff) {
append((char)(((code_points >> 6) & 0x1f) | 0xc0));
append((char)(((code_points >> 0) & 0x3f) | 0x80));
} else if (code_points <= 0xffff) {
append((char)(((code_points >> 12) & 0x0f) | 0xe0));
append((char)(((code_points >> 6) & 0x3f) | 0x80));
append((char)(((code_points >> 0) & 0x3f) | 0x80));
} else if (code_points <= 0x10ffff) {
append((char)(((code_points >> 18) & 0x07) | 0xf0));
append((char)(((code_points >> 12) & 0x3f) | 0x80));
append((char)(((code_points >> 6) & 0x3f) | 0x80));
append((char)(((code_points >> 0) & 0x3f) | 0x80));
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));
} else {
append(0xef);
append(0xbf);
@ -139,8 +139,8 @@ void StringBuilder::append_code_points(u32 code_points)
void StringBuilder::append(const Utf32View& utf32_view)
{
for (size_t i = 0; i < utf32_view.length(); ++i) {
auto code_points = utf32_view.code_pointss()[i];
append_code_points(code_points);
auto codepoint = utf32_view.codepoints()[i];
append_codepoint(codepoint);
}
}

View file

@ -42,7 +42,7 @@ public:
void append(const StringView&);
void append(const Utf32View&);
void append(char);
void append_code_points(u32);
void append_codepoint(u32);
void append(const char*, size_t);
void appendf(const char*, ...);
void appendvf(const char*, va_list);

View file

@ -37,9 +37,9 @@ TEST_CASE(decode_ascii)
size_t expected_size = sizeof(expected) / sizeof(expected[0]);
size_t i = 0;
for (u32 code_points : utf8) {
for (u32 codepoint : utf8) {
ASSERT(i < expected_size);
EXPECT_EQ(code_points, expected[i]);
EXPECT_EQ(codepoint, 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 code_points : utf8) {
for (u32 codepoint : utf8) {
ASSERT(i < expected_size);
EXPECT_EQ(code_points, expected[i]);
EXPECT_EQ(codepoint, expected[i]);
i++;
}
EXPECT_EQ(i, expected_size);

View file

@ -35,14 +35,14 @@ namespace AK {
class Utf32View {
public:
Utf32View() { }
Utf32View(const u32* code_pointss, size_t length)
: m_code_pointss(code_pointss)
Utf32View(const u32* codepoints, size_t length)
: m_codepoints(codepoints)
, m_length(length)
{
ASSERT(code_pointss || length == 0);
ASSERT(codepoints || length == 0);
}
const u32* code_pointss() const { return m_code_pointss; }
const u32* codepoints() const { return m_codepoints; }
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_code_pointss + offset, length);
return Utf32View(m_codepoints + offset, length);
}
private:
const u32* m_code_pointss { nullptr };
const u32* m_codepoints { nullptr };
size_t m_length { 0 };
};

View file

@ -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_code_points_length_in_bytes,
int& out_codepoint_length_in_bytes,
u32& out_value)
{
if ((byte & 128) == 0) {
out_value = byte;
out_code_points_length_in_bytes = 1;
out_codepoint_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_code_points_length_in_bytes = 2;
out_codepoint_length_in_bytes = 2;
return true;
}
if ((byte & 16) == 0) {
out_value = byte & 15;
out_code_points_length_in_bytes = 3;
out_codepoint_length_in_bytes = 3;
return true;
}
if ((byte & 8) == 0) {
out_value = byte & 7;
out_code_points_length_in_bytes = 4;
out_codepoint_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 code_points_length_in_bytes;
int codepoint_length_in_bytes;
u32 value;
bool first_byte_makes_sense = decode_first_byte(*ptr, code_points_length_in_bytes, value);
bool first_byte_makes_sense = decode_first_byte(*ptr, codepoint_length_in_bytes, value);
if (!first_byte_makes_sense)
return false;
for (int i = 1; i < code_points_length_in_bytes; i++) {
for (int i = 1; i < codepoint_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 += code_points_length_in_bytes;
valid_bytes += codepoint_length_in_bytes;
}
return true;
}
size_t Utf8View::length_in_code_pointss() const
size_t Utf8View::length_in_codepoints() const
{
size_t length = 0;
for (auto code_points : *this) {
(void)code_points;
for (auto codepoint : *this) {
(void)codepoint;
++length;
}
return length;
@ -165,54 +165,54 @@ Utf8CodepointIterator& Utf8CodepointIterator::operator++()
{
ASSERT(m_length > 0);
int code_points_length_in_bytes = 0;
int codepoint_length_in_bytes = 0;
u32 value;
bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_points_length_in_bytes, value);
bool first_byte_makes_sense = decode_first_byte(*m_ptr, codepoint_length_in_bytes, value);
ASSERT(first_byte_makes_sense);
(void)value;
ASSERT(code_points_length_in_bytes <= m_length);
m_ptr += code_points_length_in_bytes;
m_length -= code_points_length_in_bytes;
ASSERT(codepoint_length_in_bytes <= m_length);
m_ptr += codepoint_length_in_bytes;
m_length -= codepoint_length_in_bytes;
return *this;
}
int Utf8CodepointIterator::code_points_length_in_bytes() const
int Utf8CodepointIterator::codepoint_length_in_bytes() const
{
ASSERT(m_length > 0);
int code_points_length_in_bytes = 0;
int codepoint_length_in_bytes = 0;
u32 value;
bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_points_length_in_bytes, value);
bool first_byte_makes_sense = decode_first_byte(*m_ptr, codepoint_length_in_bytes, value);
ASSERT(first_byte_makes_sense);
return code_points_length_in_bytes;
return codepoint_length_in_bytes;
}
u32 Utf8CodepointIterator::operator*() const
{
ASSERT(m_length > 0);
u32 code_points_value_so_far = 0;
int code_points_length_in_bytes = 0;
u32 codepoint_value_so_far = 0;
int codepoint_length_in_bytes = 0;
bool first_byte_makes_sense = decode_first_byte(m_ptr[0], code_points_length_in_bytes, code_points_value_so_far);
bool first_byte_makes_sense = decode_first_byte(m_ptr[0], codepoint_length_in_bytes, codepoint_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 (code_points_length_in_bytes > m_length) {
dbg() << "Not enough bytes (need " << code_points_length_in_bytes << ", have " << m_length << "), first byte is: " << m_ptr[0] << " " << (const char*)m_ptr;
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;
}
ASSERT(code_points_length_in_bytes <= m_length);
ASSERT(codepoint_length_in_bytes <= m_length);
for (int offset = 1; offset < code_points_length_in_bytes; offset++) {
for (int offset = 1; offset < codepoint_length_in_bytes; offset++) {
ASSERT(m_ptr[offset] >> 6 == 2);
code_points_value_so_far <<= 6;
code_points_value_so_far |= m_ptr[offset] & 63;
codepoint_value_so_far <<= 6;
codepoint_value_so_far |= m_ptr[offset] & 63;
}
return code_points_value_so_far;
return codepoint_value_so_far;
}
}

View file

@ -45,7 +45,7 @@ public:
Utf8CodepointIterator& operator++();
u32 operator*() const;
int code_points_length_in_bytes() const;
int codepoint_length_in_bytes() const;
bool done() const { return !m_length; }
private:
@ -80,7 +80,7 @@ public:
return validate(valid_bytes);
}
size_t length_in_code_pointss() const;
size_t length_in_codepoints() const;
private:
const unsigned char* begin_ptr() const;

View file

@ -267,7 +267,7 @@ void KeyboardMapperWidget::set_current_map(const String current_map)
continue;
AK::StringBuilder sb;
sb.append_code_points(map[index]);
sb.append_codepoint(map[index]);
m_keys.at(k)->set_text(sb.to_string());
}

View file

@ -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 code_points = line.code_points(column);
u32 codepoint = line.codepoint(column);
auto attribute = line.attributes()[column];
u16 vga_index = (visual_row * 160) + (column * 2);
m_current_vga_window[vga_index] = code_points < 128 ? code_points : '?';
m_current_vga_window[vga_index] = codepoint < 128 ? codepoint : '?';
m_current_vga_window[vga_index + 1] = attribute_to_vga(attribute);
}
line.set_dirty(false);

View file

@ -37,9 +37,9 @@
namespace GUI {
static Vector<u32> supported_emoji_code_pointss()
static Vector<u32> supported_emoji_codepoints()
{
Vector<u32> code_pointss;
Vector<u32> codepoints;
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_code_pointss()
auto basename = lexical_path.basename();
if (!basename.starts_with("U+"))
continue;
u32 code_points = strtoul(basename.characters() + 2, nullptr, 16);
code_pointss.append(code_points);
u32 codepoint = strtoul(basename.characters() + 2, nullptr, 16);
codepoints.append(codepoint);
}
return code_pointss;
return codepoints;
}
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 code_pointss = supported_emoji_code_pointss();
auto codepoints = supported_emoji_codepoints();
size_t index = 0;
size_t columns = 6;
size_t rows = ceil_div(code_pointss.size(), columns);
size_t rows = ceil_div(codepoints.size(), columns);
for (size_t row = 0; row < rows && index < code_pointss.size(); ++row) {
for (size_t row = 0; row < rows && index < codepoints.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 < code_pointss.size()) {
if (index < codepoints.size()) {
StringBuilder builder;
builder.append(Utf32View(&code_pointss[index++], 1));
builder.append(Utf32View(&codepoints[index++], 1));
auto emoji_text = builder.to_string();
auto& button = horizontal_container.add<Button>(emoji_text);
button.set_button_style(Gfx::ButtonStyle::CoolBar);

View file

@ -298,7 +298,7 @@ public:
String text() const
{
StringBuilder sb;
sb.append_code_points(m_code_point);
sb.append_codepoint(m_code_point);
return sb.to_string();
}
u32 scancode() const { return m_scancode; }

View file

@ -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 code_points = code_pointss()[i];
if (!isspace(code_points))
auto codepoint = codepoints()[i];
if (!isspace(codepoint))
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 code_points : utf8_view)
m_text.append(code_points);
for (auto codepoint : utf8_view)
m_text.append(codepoint);
document.update_views({});
}
void TextDocumentLine::append(TextDocument& document, const u32* code_pointss, size_t length)
void TextDocumentLine::append(TextDocument& document, const u32* codepoints, size_t length)
{
if (length == 0)
return;
m_text.append(code_pointss, length);
m_text.append(codepoints, length);
document.update_views({});
}
void TextDocumentLine::append(TextDocument& document, u32 code_points)
void TextDocumentLine::append(TextDocument& document, u32 codepoint)
{
insert(document, length(), code_points);
insert(document, length(), codepoint);
}
void TextDocumentLine::prepend(TextDocument& document, u32 code_points)
void TextDocumentLine::prepend(TextDocument& document, u32 codepoint)
{
insert(document, 0, code_points);
insert(document, 0, codepoint);
}
void TextDocumentLine::insert(TextDocument& document, size_t index, u32 code_points)
void TextDocumentLine::insert(TextDocument& document, size_t index, u32 codepoint)
{
if (index == length()) {
m_text.append(code_points);
m_text.append(codepoint);
} else {
m_text.insert(index, code_points);
m_text.insert(index, codepoint);
}
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.code_pointss() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line));
builder.append(Utf32View(line.codepoints() + 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::code_points_at(const TextPosition& position) const
u32 TextDocument::codepoint_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.code_pointss()[position.column()];
return line.codepoints()[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 = code_points_at(position);
auto ch = codepoint_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 = code_points_at(position);
auto ch = codepoint_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.code_pointss()[target.column() - (start_at_column_before ? 1 : 0)]);
auto is_start_alphanumeric = isalnum(line.codepoints()[target.column() - (start_at_column_before ? 1 : 0)]);
while (target.column() > 0) {
auto prev_code_points = line.code_pointss()[target.column() - 1];
if ((is_start_alphanumeric && !isalnum(prev_code_points)) || (!is_start_alphanumeric && isalnum(prev_code_points)))
auto prev_codepoint = line.codepoints()[target.column() - 1];
if ((is_start_alphanumeric && !isalnum(prev_codepoint)) || (!is_start_alphanumeric && isalnum(prev_codepoint)))
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.code_pointss()[target.column()]);
auto is_start_alphanumeric = isalnum(line.codepoints()[target.column()]);
while (target.column() < line.length()) {
auto next_code_points = line.code_pointss()[target.column()];
if ((is_start_alphanumeric && !isalnum(next_code_points)) || (!is_start_alphanumeric && isalnum(next_code_points)))
auto next_codepoint = line.codepoints()[target.column()];
if ((is_start_alphanumeric && !isalnum(next_codepoint)) || (!is_start_alphanumeric && isalnum(next_codepoint)))
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 code_points : utf8_view)
cursor = insert_at(cursor, code_points, client);
for (auto codepoint : utf8_view)
cursor = insert_at(cursor, codepoint, client);
return cursor;
}
TextPosition TextDocument::insert_at(const TextPosition& position, u32 code_points, const Client* client)
TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint, 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 (code_points == '\n') {
if (codepoint == '\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.code_pointss()[i] == ' ')
if (old_line.codepoints()[i] == ' ')
++leading_spaces;
else
break;
@ -586,23 +586,23 @@ TextPosition TextDocument::insert_at(const TextPosition& position, u32 code_poin
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).code_pointss()[i]);
line_content.append(line(row).codepoints()[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()).code_pointss() + position.column(), line(position.line()).length() - position.column());
new_line->append(*this, line(position.line()).codepoints() + 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->code_pointss()[i]);
line_content.append(new_line->codepoints()[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 (code_points == '\t') {
if (codepoint == '\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 code_poin
notify_did_change();
return { position.line(), next_soft_tab_stop };
}
line(position.line()).insert(*this, position.column(), code_points);
line(position.line()).insert(*this, position.column(), codepoint);
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> code_pointss;
code_pointss.append(first_line.code_pointss(), range.start().column());
code_pointss.append(second_line.code_pointss() + range.end().column(), second_line.length() - range.end().column());
first_line.set_text(*this, move(code_pointss));
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));
remove_line(range.end().line());
}

View file

@ -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 code_points_at(const TextPosition&) const;
u32 codepoint_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 { code_pointss(), length() }; }
const u32* code_pointss() const { return m_text.data(); }
Utf32View view() const { return { codepoints(), length() }; }
const u32* codepoints() 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>);

View file

@ -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.code_pointss()[i]) + font().glyph_spacing();
int advance = font().glyph_width(view.codepoints()[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 code_points = visual_line_text.substring_view(i, 1).code_pointss()[0];
u32 codepoint = visual_line_text.substring_view(i, 1).codepoints()[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(code_points) + font->glyph_spacing());
character_rect.set_width(font->glyph_width(codepoint) + 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.code_pointss()) {
if (visual_line_text.codepoints()) {
Utf32View visual_selected_text {
visual_line_text.code_pointss() + start_of_selection_within_visual_line,
visual_line_text.codepoints() + 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.code_pointss(), b.code_pointss(), min(a.length(), b.length())) < 0;
return strcmp_utf32(a.codepoints(), b.codepoints(), 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_code_points(event.code_point());
sb.append_codepoint(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 code_points = line.code_pointss()[i];
auto glyph_width = font().glyph_or_emoji_width(code_points);
auto codepoint = line.codepoints()[i];
auto glyph_width = font().glyph_or_emoji_width(codepoint);
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.code_pointss() + start_of_line, visual_line_break - start_of_line);
auto visual_line_view = Utf32View(line.codepoints() + 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()),

View file

@ -33,21 +33,21 @@ namespace Gfx {
static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis;
const Bitmap* Emoji::emoji_for_code_points(u32 code_points)
const Bitmap* Emoji::emoji_for_codepoint(u32 codepoint)
{
auto it = s_emojis.find(code_points);
auto it = s_emojis.find(codepoint);
if (it != s_emojis.end())
return (*it).value.ptr();
String path = String::format("/res/emoji/U+%X.png", code_points);
String path = String::format("/res/emoji/U+%X.png", codepoint);
auto bitmap = Bitmap::load_from_file(path);
if (!bitmap) {
s_emojis.set(code_points, nullptr);
s_emojis.set(codepoint, nullptr);
return nullptr;
}
s_emojis.set(code_points, bitmap);
s_emojis.set(codepoint, bitmap);
return bitmap.ptr();
}

View file

@ -34,7 +34,7 @@ class Bitmap;
class Emoji {
public:
static const Gfx::Bitmap* emoji_for_code_points(u32 code_points);
static const Gfx::Bitmap* emoji_for_codepoint(u32 codepoint);
};
}

View file

@ -255,20 +255,20 @@ bool Font::write_to_file(const StringView& path)
return true;
}
GlyphBitmap Font::glyph_bitmap(u32 code_points) const
GlyphBitmap Font::glyph_bitmap(u32 codepoint) const
{
return GlyphBitmap(&m_rows[code_points * m_glyph_height], { glyph_width(code_points), m_glyph_height });
return GlyphBitmap(&m_rows[codepoint * m_glyph_height], { glyph_width(codepoint), m_glyph_height });
}
int Font::glyph_or_emoji_width(u32 code_points) const
int Font::glyph_or_emoji_width(u32 codepoint) const
{
if (code_points < m_glyph_count)
return glyph_width(code_points);
if (codepoint < m_glyph_count)
return glyph_width(codepoint);
if (m_fixed_width)
return m_glyph_width;
auto* emoji = Emoji::emoji_for_code_points(code_points);
auto* emoji = Emoji::emoji_for_codepoint(codepoint);
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 code_points : utf8) {
for (u32 codepoint : utf8) {
if (!first)
width += glyph_spacing();
first = false;
width += glyph_or_emoji_width(code_points);
width += glyph_or_emoji_width(codepoint);
}
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.code_pointss()[i]);
width += glyph_or_emoji_width(view.codepoints()[i]);
return width;
}

View file

@ -89,10 +89,10 @@ public:
~Font();
GlyphBitmap glyph_bitmap(u32 code_points) const;
GlyphBitmap glyph_bitmap(u32 codepoint) 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 code_points) const;
int glyph_or_emoji_width(u32 codepoint) 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; }

View file

@ -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 code_points, Color color)
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, Color color)
{
draw_glyph(point, code_points, font(), color);
draw_glyph(point, codepoint, font(), color);
}
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_points, const Font& font, Color color)
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, const Font& font, Color color)
{
draw_bitmap(point, font.glyph_bitmap(code_points), color);
draw_bitmap(point, font.glyph_bitmap(codepoint), 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 code_points, const Font& font, Color color)
void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 codepoint, const Font& font, Color color)
{
if (code_points < (u32)font.glyph_count()) {
if (codepoint < (u32)font.glyph_count()) {
// This looks like a regular character.
draw_glyph(point, (size_t)code_points, font, color);
draw_glyph(point, (size_t)codepoint, font, color);
return;
}
// Perhaps it's an emoji?
auto* emoji = Emoji::emoji_for_code_points(code_points);
auto* emoji = Emoji::emoji_for_codepoint(codepoint);
if (emoji == nullptr) {
#ifdef EMOJI_DEBUG
dbg() << "Failed to find an emoji for code_points " << code_points;
dbg() << "Failed to find an emoji for codepoint " << codepoint;
#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 code_points = *it;
int glyph_width = font.glyph_or_emoji_width(code_points);
u32 codepoint = *it;
int glyph_width = font.glyph_or_emoji_width(codepoint);
// 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 code_points : final_text) {
if (code_points == ' ') {
for (u32 codepoint : final_text) {
if (codepoint == ' ') {
point.move_by(space_width, 0);
continue;
}
draw_glyph_or_emoji(point, code_points, font, color);
point.move_by(font.glyph_or_emoji_width(code_points) + font.glyph_spacing(), 0);
draw_glyph_or_emoji(point, codepoint, font, color);
point.move_by(font.glyph_or_emoji_width(codepoint) + 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 code_points = text.code_pointss()[i];
int glyph_width = font.glyph_or_emoji_width(code_points);
u32 codepoint = text.codepoints()[i];
int glyph_width = font.glyph_or_emoji_width(codepoint);
// 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.code_pointss(), i);
elided_text.append(final_text.codepoints(), 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 code_points = final_text.code_pointss()[i];
if (code_points == ' ') {
auto codepoint = final_text.codepoints()[i];
if (codepoint == ' ') {
point.move_by(space_width, 0);
continue;
}
draw_glyph_or_emoji(point, code_points, font, color);
point.move_by(font.glyph_or_emoji_width(code_points) + font.glyph_spacing(), 0);
draw_glyph_or_emoji(point, codepoint, font, color);
point.move_by(font.glyph_or_emoji_width(codepoint) + 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 code_points = *it;
if (code_points == '\n') {
u32 codepoint = *it;
if (codepoint == '\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 code_points = text.code_pointss()[i];
if (code_points == '\n') {
u32 codepoint = text.codepoints()[i];
if (codepoint == '\n') {
Utf32View line = text.substring_view(start_of_current_line, i - start_of_current_line);
lines.append(line);
start_of_current_line = i + 1;

View file

@ -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 code_points, const Font&, Color);
void draw_glyph_or_emoji(const IntPoint&, u32 codepoint, 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&)>&&);

View file

@ -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 code_points must not be greater than 0x10ffff in escape sequence";
message = "Unicode codepoint must not be greater than 0x10ffff in escape sequence";
}
syntax_error(

View file

@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next)
}
StringBuilder builder;
builder.append_code_points(*utf8_iterator);
builder.append_codepoint(*utf8_iterator);
++utf8_iterator;
return create_iterator_result_object(global_object, js_string(interpreter, builder.to_string()), false);

View file

@ -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 code_points view of the string.
// FIXME: index_start and index_end should index a UTF-16 codepoint 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 code_points view of the string.
// FIXME: position should index a UTF-16 codepoint 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 code_points view of the string.
// FIXME: index_start and index_end should index a UTF-16 codepoint 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 code_points view of the string.
// FIXME: from_index should index a UTF-16 codepoint view of the string.
from_index = min(interpreter.argument(1).to_size_t(interpreter), max_index);
if (interpreter.exception())
return {};

View file

@ -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_code_pointss { x_string };
Utf8View y_code_pointss { y_string };
for (auto k = x_code_pointss.begin(), l = y_code_pointss.begin();
k != x_code_pointss.end() && l != y_code_pointss.end();
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();
++k, ++l) {
if (*k != *l) {
if (*k < *l) {

View file

@ -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_code_points(hex2int(digit1) * 16 + hex2int(digit2));
builder.append_codepoint(hex2int(digit1) * 16 + hex2int(digit2));
break;
}
case 'u': {
@ -174,7 +174,7 @@ String Token::string_value(StringValueStatus& status) const
}
}
builder.append_code_points(code_point);
builder.append_codepoint(code_point);
break;
}
default:

View file

@ -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.code_pointss()[i]);
insert(string.codepoints()[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 code_points_length_in_utf8(u32 code_points)
static size_t codepoint_length_in_utf8(u32 codepoint)
{
if (code_points <= 0x7f)
if (codepoint <= 0x7f)
return 1;
if (code_points <= 0x07ff)
if (codepoint <= 0x07ff)
return 2;
if (code_points <= 0xffff)
if (codepoint <= 0xffff)
return 3;
if (code_points <= 0x10ffff)
if (codepoint <= 0x10ffff)
return 4;
return 3;
}
@ -156,20 +156,20 @@ static size_t code_points_length_in_utf8(u32 code_points)
// | | +- 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 code_points 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 codepoint 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_code_points_offset_range(size_t start_byte_offset, size_t end_byte_offset, size_t scan_code_points_offset, bool reverse) const
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
{
size_t byte_offset = 0;
size_t code_points_offset = scan_code_points_offset + (reverse ? 1 : 0);
size_t codepoint_offset = scan_codepoint_offset + (reverse ? 1 : 0);
CodepointRange range;
for (;;) {
if (!reverse) {
if (code_points_offset >= m_buffer.size())
if (codepoint_offset >= m_buffer.size())
break;
} else {
if (code_points_offset == 0)
if (codepoint_offset == 0)
break;
}
@ -182,7 +182,7 @@ Editor::CodepointRange Editor::byte_offset_range_to_code_points_offset_range(siz
if (byte_offset < end_byte_offset)
++range.end;
byte_offset += code_points_length_in_utf8(m_buffer[reverse ? --code_points_offset : code_points_offset++]);
byte_offset += codepoint_length_in_utf8(m_buffer[reverse ? --codepoint_offset : codepoint_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_code_points_offset_range(start, end, 0);
auto offsets = byte_offset_range_to_codepoint_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_code_points_offset_range(internal_static_offset, internal_invariant_offset + internal_static_offset, m_cursor - 1, true);
auto offsets = byte_offset_range_to_codepoint_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_code_pointss = 0;
size_t consumed_codepoints = 0;
enum Amount {
Character,
@ -552,18 +552,18 @@ void Editor::handle_read_event()
m_refresh_needed = true;
};
for (auto code_points : input_view) {
for (auto codepoint : input_view) {
if (m_finish)
break;
++consumed_code_pointss;
++consumed_codepoints;
if (code_points == 0)
if (codepoint == 0)
continue;
switch (m_state) {
case InputState::ExpectBracket:
if (code_points == '[') {
if (codepoint == '[') {
m_state = InputState::ExpectFinal;
continue;
} else {
@ -571,7 +571,7 @@ void Editor::handle_read_event()
break;
}
case InputState::ExpectFinal:
switch (code_points) {
switch (codepoint) {
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", code_points, code_points);
dbgprintf("LibLine: Unhandled final: %02x (%c)\r\n", codepoint, codepoint);
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 (code_points == 27) {
if (codepoint == 27) {
m_state = InputState::ExpectBracket;
continue;
}
break;
}
auto cb = m_key_callbacks.get(code_points);
auto cb = m_key_callbacks.get(codepoint);
if (cb.has_value()) {
if (!cb.value()->callback(*this)) {
continue;
@ -646,19 +646,19 @@ void Editor::handle_read_event()
}
// ^N
if (code_points == ctrl('N')) {
if (codepoint == ctrl('N')) {
do_search_forwards();
continue;
}
// ^P
if (code_points == ctrl('P')) {
if (codepoint == ctrl('P')) {
do_search_backwards();
continue;
}
m_search_offset = 0; // reset search offset on any key
if (code_points == '\t' || reverse_tab) {
if (codepoint == '\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 (code_points == m_termios.c_cc[VWERASE]) {
if (codepoint == 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 (code_points == m_termios.c_cc[VKILL]) {
if (codepoint == 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 (code_points == m_termios.c_cc[VEOF] && m_buffer.is_empty()) {
if (codepoint == 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 (code_points == ctrl('A')) {
if (codepoint == ctrl('A')) {
m_cursor = 0;
continue;
}
// ^B
if (code_points == ctrl('B')) {
if (codepoint == ctrl('B')) {
do_cursor_left(Character);
continue;
}
// ^D
if (code_points == ctrl('D')) {
if (codepoint == ctrl('D')) {
do_delete();
continue;
}
// ^E
if (code_points == ctrl('E')) {
if (codepoint == ctrl('E')) {
m_cursor = m_buffer.size();
continue;
}
// ^F
if (code_points == ctrl('F')) {
if (codepoint == ctrl('F')) {
do_cursor_right(Character);
continue;
}
// ^H: ctrl('H') == '\b'
if (code_points == '\b' || code_points == m_termios.c_cc[VERASE]) {
if (codepoint == '\b' || codepoint == m_termios.c_cc[VERASE]) {
do_backspace();
continue;
}
// ^L
if (code_points == ctrl('L')) {
if (codepoint == 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 (code_points == ctrl('R')) {
if (codepoint == 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 code_points : m_buffer)
m_pre_search_buffer.append(code_points);
for (auto codepoint : m_buffer)
m_pre_search_buffer.append(codepoint);
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 (code_points == ctrl('T')) {
if (codepoint == 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 (code_points == '\n') {
if (codepoint == '\n') {
finish();
continue;
}
insert(code_points);
insert(codepoint);
}
if (consumed_code_pointss == m_incomplete_data.size()) {
if (consumed_codepoints == m_incomplete_data.size()) {
m_incomplete_data.clear();
} else {
for (size_t i = 0; i < consumed_code_pointss; ++i)
for (size_t i = 0; i < consumed_codepoints; ++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.code_pointss()[i];
auto next_c = i + 1 < view.length() ? view.code_pointss()[i + 1] : 0;
auto c = view.codepoints()[i];
auto next_c = i + 1 < view.length() ? view.codepoints()[i + 1] : 0;
state = actual_rendered_string_length_step(metrics, length, c, next_c, state);
}

View file

@ -310,7 +310,7 @@ private:
size_t start { 0 };
size_t end { 0 };
};
CodepointRange byte_offset_range_to_code_points_offset_range(size_t byte_start, size_t byte_end, size_t code_points_scan_offset, bool reverse = false) const;
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;
void get_terminal_size();

View file

@ -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_code_points;
u32 last_valid_suggestion_codepoint;
for (;; ++common_suggestion_prefix) {
if (m_suggestions[0].text_view.length() <= common_suggestion_prefix)
goto no_more_commons;
last_valid_suggestion_code_points = m_suggestions[0].text_view.code_pointss()[common_suggestion_prefix];
last_valid_suggestion_codepoint = m_suggestions[0].text_view.codepoints()[common_suggestion_prefix];
for (auto& suggestion : m_suggestions) {
if (suggestion.text_view.length() <= common_suggestion_prefix || suggestion.text_view.code_pointss()[common_suggestion_prefix] != last_valid_suggestion_code_points) {
if (suggestion.text_view.length() <= common_suggestion_prefix || suggestion.text_view.codepoints()[common_suggestion_prefix] != last_valid_suggestion_codepoint) {
goto no_more_commons;
}
}

View file

@ -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 code_pointss, so no mapping is needed, just utf-8 encoding.
builder.append_code_points(ch);
// Latin1 is the same as the first 256 Unicode codepoints, so no mapping is needed, just utf-8 encoding.
builder.append_codepoint(ch);
}
return builder.to_string();
}

View file

@ -37,25 +37,25 @@ Line::Line(u16 length)
Line::~Line()
{
if (m_utf32)
delete[] m_code_pointss.as_u32;
delete[] m_codepoints.as_u32;
else
delete[] m_code_pointss.as_u8;
delete[] m_codepoints.as_u8;
delete[] m_attributes;
}
template<typename CodepointType>
static CodepointType* create_new_code_points_array(size_t new_length, const CodepointType* old_code_pointss, size_t old_length)
static CodepointType* create_new_codepoint_array(size_t new_length, const CodepointType* old_codepoints, size_t old_length)
{
auto* new_code_pointss = new CodepointType[new_length];
auto* new_codepoints = new CodepointType[new_length];
for (size_t i = 0; i < new_length; ++i)
new_code_pointss[i] = ' ';
if (old_code_pointss) {
new_codepoints[i] = ' ';
if (old_codepoints) {
for (size_t i = 0; i < min(old_length, new_length); ++i) {
new_code_pointss[i] = old_code_pointss[i];
new_codepoints[i] = old_codepoints[i];
}
}
delete[] old_code_pointss;
return new_code_pointss;
delete[] old_codepoints;
return new_codepoints;
}
void Line::set_length(u16 new_length)
@ -64,9 +64,9 @@ void Line::set_length(u16 new_length)
return;
if (m_utf32)
m_code_pointss.as_u32 = create_new_code_points_array<u32>(new_length, m_code_pointss.as_u32, m_length);
m_codepoints.as_u32 = create_new_codepoint_array<u32>(new_length, m_codepoints.as_u32, m_length);
else
m_code_pointss.as_u8 = create_new_code_points_array<u8>(new_length, m_code_pointss.as_u8, m_length);
m_codepoints.as_u8 = create_new_codepoint_array<u8>(new_length, m_codepoints.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_code_points(i, ' ');
set_codepoint(i, ' ');
m_attributes[i] = attribute;
}
return;
}
for (unsigned i = 0; i < m_length; ++i) {
if (code_points(i) != ' ')
if (codepoint(i) != ' ')
m_dirty = true;
set_code_points(i, ' ');
set_codepoint(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_code_pointss = new u32[m_length];
auto* new_codepoints = new u32[m_length];
for (size_t i = 0; i < m_length; ++i) {
new_code_pointss[i] = m_code_pointss.as_u8[i];
new_codepoints[i] = m_codepoints.as_u8[i];
}
delete m_code_pointss.as_u8;
m_code_pointss.as_u32 = new_code_pointss;
delete m_codepoints.as_u8;
m_codepoints.as_u32 = new_codepoints;
m_utf32 = true;
}

View file

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

View file

@ -361,7 +361,7 @@ void Terminal::escape$b(const ParamVector& params)
return;
for (unsigned i = 0; i < params[0]; ++i)
put_character_at(m_cursor_row, m_cursor_column++, m_last_code_points);
put_character_at(m_cursor_row, m_cursor_column++, m_last_codepoint);
}
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_code_points(i, line.code_points(i + num));
line.set_codepoint(i, line.codepoint(i + num));
// Fill remainder of line with blanks
for (int i = line.length() - num; i < line.length(); i++)
line.set_code_points(i, ' ');
line.set_codepoint(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 code_points)
void Terminal::put_character_at(unsigned row, unsigned column, u32 codepoint)
{
ASSERT(row < rows());
ASSERT(column < columns());
auto& line = m_lines[row];
line.set_code_points(column, code_points);
line.set_codepoint(column, codepoint);
line.attributes()[column] = m_current_attribute;
line.attributes()[column].flags |= Attribute::Touched;
line.set_dirty(true);
m_last_code_points = code_points;
m_last_codepoint = codepoint;
}
void Terminal::NEL()
@ -820,14 +820,14 @@ void Terminal::on_input(u8 ch)
auto fail_utf8_parse = [this] {
m_parser_state = Normal;
on_code_points('%');
on_codepoint('%');
};
auto advance_utf8_parse = [this, ch] {
m_parser_code_points <<= 6;
m_parser_code_points |= ch & 0x3f;
m_parser_codepoint <<= 6;
m_parser_codepoint |= ch & 0x3f;
if (m_parser_state == UTF8Needs1Byte) {
on_code_points(m_parser_code_points);
on_codepoint(m_parser_codepoint);
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_code_points = ch & 0x1f;
m_parser_codepoint = ch & 0x1f;
return;
}
if ((ch & 0xf0) == 0xe0) {
m_parser_state = UTF8Needs2Bytes;
m_parser_code_points = ch & 0x0f;
m_parser_codepoint = ch & 0x0f;
return;
}
if ((ch & 0xf8) == 0xf0) {
m_parser_state = UTF8Needs3Bytes;
m_parser_code_points = ch & 0x07;
m_parser_codepoint = ch & 0x07;
return;
}
fail_utf8_parse();
@ -978,26 +978,26 @@ void Terminal::on_input(u8 ch)
return;
}
on_code_points(ch);
on_codepoint(ch);
}
void Terminal::on_code_points(u32 code_points)
void Terminal::on_codepoint(u32 codepoint)
{
auto new_column = m_cursor_column + 1;
if (new_column < columns()) {
put_character_at(m_cursor_row, m_cursor_column, code_points);
put_character_at(m_cursor_row, m_cursor_column, codepoint);
set_cursor(m_cursor_row, new_column);
return;
}
if (m_stomp) {
m_stomp = false;
newline();
put_character_at(m_cursor_row, m_cursor_column, code_points);
put_character_at(m_cursor_row, m_cursor_column, codepoint);
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, code_points);
put_character_at(m_cursor_row, m_cursor_column, codepoint);
}
}
@ -1078,7 +1078,7 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
emit_string("\033");
StringBuilder sb;
sb.append_code_points(code_point);
sb.append_codepoint(code_point);
emit_string(sb.to_string());
}

View file

@ -106,7 +106,7 @@ public:
private:
typedef Vector<unsigned, 4> ParamVector;
void on_code_points(u32);
void on_codepoint(u32);
void scroll_up();
void scroll_down();
@ -193,13 +193,13 @@ private:
};
ParserState m_parser_state { Normal };
u32 m_parser_code_points { 0 };
u32 m_parser_codepoint { 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_code_points { 0 };
u32 m_last_codepoint { 0 };
};
}

View file

@ -294,7 +294,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
painter.clear_rect(row_rect, color_from_rgb(line.attributes()[0].background_color).with_alpha(m_opacity));
for (size_t column = 0; column < line.length(); ++column) {
u32 code_points = line.code_points(column);
u32 codepoint = line.codepoint(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 (code_points == ' ')
if (codepoint == ' ')
continue;
painter.draw_glyph_or_emoji(
character_rect.location(),
code_points,
codepoint,
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.code_points(position.column()) == ' ';
bool want_whitespace = line.codepoint(position.column()) == ' ';
int start_column = 0;
int end_column = 0;
for (int column = position.column(); column >= 0 && (line.code_points(column) == ' ') == want_whitespace; --column) {
for (int column = position.column(); column >= 0 && (line.codepoint(column) == ' ') == want_whitespace; --column) {
start_column = column;
}
for (int column = position.column(); column < m_terminal.columns() && (line.code_points(column) == ' ') == want_whitespace; ++column) {
for (int column = position.column(); column < m_terminal.columns() && (line.codepoint(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 code_points = line.code_points(column);
builder.append(Utf32View(&code_points, 1));
u32 codepoint = line.codepoint(column);
builder.append(Utf32View(&codepoint, 1));
} else {
builder.append(line.code_points(column));
builder.append(line.codepoint(column));
}
if (column == line.length() - 1 || (m_rectangle_selection && column == last_column)) {
builder.append('\n');

View file

@ -272,10 +272,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
Vector<u8> byte_string;
byte_string.ensure_capacity(string.length());
for (u32 code_points : Utf8View(string)) {
if (code_points > 0xff)
for (u32 codepoint : Utf8View(string)) {
if (codepoint > 0xff)
return interpreter.throw_exception<JS::InvalidCharacterError>(JS::ErrorType::NotAByteString, "btoa");
byte_string.append(code_points);
byte_string.append(codepoint);
}
auto encoded = encode_base64(byte_string.span());

View file

@ -31,12 +31,12 @@
namespace Web {
namespace HTML {
Optional<EntityMatch> code_pointss_from_entity(const StringView& entity)
Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
{
constexpr struct {
StringView entity;
u32 code_points;
} single_code_points_entities[] = {
u32 codepoint;
} single_codepoint_entities[] = {
{ "AElig;", 0x000C6 },
{ "AElig", 0x000C6 },
{ "AMP;", 0x00026 },
@ -2179,9 +2179,9 @@ Optional<EntityMatch> code_pointss_from_entity(const StringView& entity)
constexpr struct {
StringView entity;
u32 code_points1;
u32 code_points2;
} double_code_points_entities[] = {
u32 codepoint1;
u32 codepoint2;
} double_codepoint_entities[] = {
{ "NotEqualTilde;", 0x02242, 0x00338 },
{ "NotGreaterFullEqual;", 0x02267, 0x00338 },
{ "NotGreaterGreater;", 0x0226B, 0x00338 },
@ -2279,17 +2279,17 @@ Optional<EntityMatch> code_pointss_from_entity(const StringView& entity)
EntityMatch match;
for (auto& single_code_points_entity : single_code_points_entities) {
if (entity.starts_with(single_code_points_entity.entity)) {
if (match.entity.is_null() || single_code_points_entity.entity.length() > match.entity.length())
match = { { single_code_points_entity.code_points }, single_code_points_entity.entity };
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& double_code_points_entity : double_code_points_entities) {
if (entity.starts_with(double_code_points_entity.entity)) {
if (match.entity.is_null() || double_code_points_entity.entity.length() > match.entity.length())
match = EntityMatch { { double_code_points_entity.code_points1, double_code_points_entity.code_points2 }, StringView(double_code_points_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) };
}
}

View file

@ -33,11 +33,11 @@ namespace Web {
namespace HTML {
struct EntityMatch {
Vector<u32, 2> code_pointss;
Vector<u32, 2> codepoints;
StringView entity;
};
Optional<EntityMatch> code_pointss_from_entity(const StringView&);
Optional<EntityMatch> codepoints_from_entity(const StringView&);
}
}

View file

@ -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.code_points());
insert_character(token.codepoint());
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.code_points());
insert_character(token.codepoint());
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.code_points() == 0) {
if (token.codepoint() == 0) {
PARSE_ERROR();
return;
}
if (token.is_parser_whitespace()) {
reconstruct_the_active_formatting_elements();
insert_character(token.code_points());
insert_character(token.codepoint());
return;
}
reconstruct_the_active_formatting_elements();
insert_character(token.code_points());
insert_character(token.codepoint());
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().code_points() == '\n') {
if (next_token.has_value() && next_token.value().is_character() && next_token.value().codepoint() == '\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().code_points() == '\n') {
if (next_token.has_value() && next_token.value().is_character() && next_token.value().codepoint() == '\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.code_points());
insert_character(token.codepoint());
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.code_points() == 0) {
if (token.codepoint() == 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.code_points());
insert_character(pending_token.codepoint());
}
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.code_points() == 0) {
if (token.codepoint() == 0) {
PARSE_ERROR();
return;
}
insert_character(token.code_points());
insert_character(token.codepoint());
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.code_points());
insert_character(token.codepoint());
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.code_points());
insert_character(token.codepoint());
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.code_points());
insert_character(token.codepoint());
return;
}

View file

@ -50,11 +50,11 @@ public:
EndOfFile,
};
static HTMLToken make_character(u32 code_points)
static HTMLToken make_character(u32 codepoint)
{
HTMLToken token;
token.m_type = Type::Character;
token.m_comment_or_character.data.append(code_points);
token.m_comment_or_character.data.append(codepoint);
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 code_points() const
u32 codepoint() const
{
ASSERT(is_character());
Utf8View view(m_comment_or_character.data.string_view());
ASSERT(view.length_in_code_pointss() == 1);
ASSERT(view.length_in_codepoints() == 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 (code_points()) {
switch (codepoint()) {
case '\t':
case '\n':
case '\f':

View file

@ -46,7 +46,7 @@ namespace Web::HTML {
#endif
#define CONSUME_NEXT_INPUT_CHARACTER \
current_input_character = next_code_points();
current_input_character = next_codepoint();
#define SWITCH_TO(new_state) \
do { \
@ -86,22 +86,22 @@ namespace Web::HTML {
return m_queued_tokens.dequeue(); \
} while (0)
#define EMIT_CHARACTER_AND_RECONSUME_IN(code_points, new_state) \
#define EMIT_CHARACTER_AND_RECONSUME_IN(codepoint, new_state) \
do { \
m_queued_tokens.enqueue(HTMLToken::make_character(code_points)); \
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); \
will_reconsume_in(State::new_state); \
m_state = State::new_state; \
goto new_state; \
} while (0)
#define FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \
#define FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \
do { \
for (auto code_points : m_temporary_buffer) { \
for (auto codepoint : m_temporary_buffer) { \
if (consumed_as_part_of_an_attribute()) { \
m_current_token.m_tag.attributes.last().value_builder.append_code_points(code_points); \
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(codepoint); \
} else { \
create_new_token(HTMLToken::Type::Character); \
m_current_token.m_comment_or_character.data.append_code_points(code_points); \
m_current_token.m_comment_or_character.data.append_codepoint(codepoint); \
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(code_points) \
if (current_input_character.has_value() && current_input_character.value() == code_points)
#define ON(codepoint) \
if (current_input_character.has_value() && current_input_character.value() == codepoint)
#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(code_points) \
#define EMIT_CHARACTER(codepoint) \
do { \
create_new_token(HTMLToken::Type::Character); \
m_current_token.m_comment_or_character.data.append_code_points(code_points); \
m_current_token.m_comment_or_character.data.append_codepoint(codepoint); \
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(code_points, new_state) \
#define SWITCH_TO_AND_EMIT_CHARACTER(codepoint, new_state) \
do { \
will_switch_to(State::new_state); \
m_state = State::new_state; \
EMIT_CHARACTER(code_points); \
EMIT_CHARACTER(codepoint); \
} while (0)
#define SWITCH_TO_AND_EMIT_CURRENT_CHARACTER(new_state) \
@ -193,39 +193,39 @@ namespace Web::HTML {
} \
}
static inline bool is_surrogate(u32 code_points)
static inline bool is_surrogate(u32 codepoint)
{
return (code_points & 0xfffff800) == 0xd800;
return (codepoint & 0xfffff800) == 0xd800;
}
static inline bool is_noncharacter(u32 code_points)
static inline bool is_noncharacter(u32 codepoint)
{
return code_points >= 0xfdd0 && (code_points <= 0xfdef || (code_points & 0xfffe) == 0xfffe) && code_points <= 0x10ffff;
return codepoint >= 0xfdd0 && (codepoint <= 0xfdef || (codepoint & 0xfffe) == 0xfffe) && codepoint <= 0x10ffff;
}
static inline bool is_c0_control(u32 code_points)
static inline bool is_c0_control(u32 codepoint)
{
return code_points <= 0x1f;
return codepoint <= 0x1f;
}
static inline bool is_control(u32 code_points)
static inline bool is_control(u32 codepoint)
{
return is_c0_control(code_points) || (code_points >= 0x7f && code_points <= 0x9f);
return is_c0_control(codepoint) || (codepoint >= 0x7f && codepoint <= 0x9f);
}
Optional<u32> HTMLTokenizer::next_code_points()
Optional<u32> HTMLTokenizer::next_codepoint()
{
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 code_points: " << (char)*m_prev_utf8_iterator;
dbg() << "(Tokenizer) Next codepoint: " << (char)*m_prev_utf8_iterator;
#endif
return *m_prev_utf8_iterator;
}
Optional<u32> HTMLTokenizer::peek_code_points(size_t offset) const
Optional<u32> HTMLTokenizer::peek_codepoint(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_code_points();
auto current_input_character = next_codepoint();
switch (m_state) {
BEGIN_STATE(Data)
{
@ -328,7 +328,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_tag.tag_name.append_code_points(0xFFFD);
m_current_token.m_tag.tag_name.append_codepoint(0xFFFD);
continue;
}
ON_EOF
@ -338,7 +338,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_tag.tag_name.append_code_points(current_input_character.value());
m_current_token.m_tag.tag_name.append_codepoint(current_input_character.value());
continue;
}
}
@ -408,12 +408,12 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_comment_or_character.data.append_code_points(0xFFFD);
m_current_token.m_comment_or_character.data.append_codepoint(0xFFFD);
continue;
}
ANYTHING_ELSE
{
m_current_token.m_comment_or_character.data.append_code_points(current_input_character.value());
m_current_token.m_comment_or_character.data.append_codepoint(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_code_points(0xFFFD);
m_current_token.m_doctype.name.append_codepoint(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_code_points(current_input_character.value());
m_current_token.m_doctype.name.append_codepoint(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_code_points(0xFFFD);
m_current_token.m_doctype.name.append_codepoint(0xFFFD);
continue;
}
ON_EOF
@ -521,7 +521,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_doctype.name.append_code_points(current_input_character.value());
m_current_token.m_doctype.name.append_codepoint(current_input_character.value());
continue;
}
}
@ -732,7 +732,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_doctype.public_identifier.append_code_points(0xFFFD);
m_current_token.m_doctype.public_identifier.append_codepoint(0xFFFD);
continue;
}
ON('>')
@ -750,7 +750,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_doctype.public_identifier.append_code_points(current_input_character.value());
m_current_token.m_doctype.public_identifier.append_codepoint(current_input_character.value());
continue;
}
}
@ -765,7 +765,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_doctype.public_identifier.append_code_points(0xFFFD);
m_current_token.m_doctype.public_identifier.append_codepoint(0xFFFD);
continue;
}
ON('>')
@ -783,7 +783,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_doctype.public_identifier.append_code_points(current_input_character.value());
m_current_token.m_doctype.public_identifier.append_codepoint(current_input_character.value());
continue;
}
}
@ -798,7 +798,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_doctype.system_identifier.append_code_points(0xFFFD);
m_current_token.m_doctype.system_identifier.append_codepoint(0xFFFD);
continue;
}
ON('>')
@ -816,7 +816,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_doctype.system_identifier.append_code_points(current_input_character.value());
m_current_token.m_doctype.system_identifier.append_codepoint(current_input_character.value());
continue;
}
}
@ -831,7 +831,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_doctype.system_identifier.append_code_points(0xFFFD);
m_current_token.m_doctype.system_identifier.append_codepoint(0xFFFD);
continue;
}
ON('>')
@ -849,7 +849,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_doctype.system_identifier.append_code_points(current_input_character.value());
m_current_token.m_doctype.system_identifier.append_codepoint(current_input_character.value());
continue;
}
}
@ -1003,7 +1003,7 @@ _StartOfFunction:
{
PARSE_ERROR();
auto new_attribute = HTMLToken::AttributeBuilder();
new_attribute.local_name_builder.append_code_points(current_input_character.value());
new_attribute.local_name_builder.append_codepoint(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_code_points(tolower(current_input_character.value()));
m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(tolower(current_input_character.value()));
continue;
}
ON(0)
{
PARSE_ERROR();
m_current_token.m_tag.attributes.last().local_name_builder.append_code_points(0xFFFD);
m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(0xFFFD);
continue;
}
ON('"')
@ -1086,7 +1086,7 @@ _StartOfFunction:
ANYTHING_ELSE
{
AnythingElseAttributeName:
m_current_token.m_tag.attributes.last().local_name_builder.append_code_points(current_input_character.value());
m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(current_input_character.value());
continue;
}
}
@ -1163,7 +1163,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_tag.attributes.last().value_builder.append_code_points(0xFFFD);
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD);
continue;
}
ON_EOF
@ -1173,7 +1173,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_tag.attributes.last().value_builder.append_code_points(current_input_character.value());
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
continue;
}
}
@ -1193,7 +1193,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_tag.attributes.last().value_builder.append_code_points(0xFFFD);
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD);
continue;
}
ON_EOF
@ -1203,7 +1203,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_tag.attributes.last().value_builder.append_code_points(current_input_character.value());
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
continue;
}
}
@ -1227,7 +1227,7 @@ _StartOfFunction:
ON(0)
{
PARSE_ERROR();
m_current_token.m_tag.attributes.last().value_builder.append_code_points(0xFFFD);
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD);
continue;
}
ON('"')
@ -1263,7 +1263,7 @@ _StartOfFunction:
ANYTHING_ELSE
{
AnythingElseAttributeValueUnquoted:
m_current_token.m_tag.attributes.last().value_builder.append_code_points(current_input_character.value());
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
continue;
}
}
@ -1343,7 +1343,7 @@ _StartOfFunction:
{
ON('<')
{
m_current_token.m_comment_or_character.data.append_code_points(current_input_character.value());
m_current_token.m_comment_or_character.data.append_codepoint(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_code_points(0xFFFD);
m_current_token.m_comment_or_character.data.append_codepoint(0xFFFD);
continue;
}
ON_EOF
@ -1364,7 +1364,7 @@ _StartOfFunction:
}
ANYTHING_ELSE
{
m_current_token.m_comment_or_character.data.append_code_points(current_input_character.value());
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
continue;
}
}
@ -1449,12 +1449,12 @@ _StartOfFunction:
{
ON('!')
{
m_current_token.m_comment_or_character.data.append_code_points(current_input_character.value());
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
SWITCH_TO(CommentLessThanSignBang);
}
ON('<')
{
m_current_token.m_comment_or_character.data.append_code_points(current_input_character.value());
m_current_token.m_comment_or_character.data.append_codepoint(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::code_pointss_from_entity(m_decoded_input.substring_view(byte_offset, m_decoded_input.length() - byte_offset - 1));
auto match = HTML::codepoints_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,18 +1543,18 @@ _StartOfFunction:
for (auto ch : match.value().entity)
m_temporary_buffer.append(ch);
if (consumed_as_part_of_an_attribute() && match.value().code_pointss.last() != ';') {
auto next = peek_code_points(0);
if (consumed_as_part_of_an_attribute() && match.value().codepoints.last() != ';') {
auto next = peek_codepoint(0);
if (next.has_value() && (next.value() == '=' || isalnum(next.value()))) {
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
SWITCH_TO_RETURN_STATE;
}
}
if (consumed_as_part_of_an_attribute() && match.value().entity.ends_with(';')) {
auto next_code_points = peek_code_points(0);
if (next_code_points.has_value() && next_code_points.value() == '=') {
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
auto next_codepoint = peek_codepoint(0);
if (next_codepoint.has_value() && next_codepoint.value() == '=') {
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
SWITCH_TO_RETURN_STATE;
}
}
@ -1564,12 +1564,12 @@ _StartOfFunction:
}
m_temporary_buffer.clear();
m_temporary_buffer.append(match.value().code_pointss);
m_temporary_buffer.append(match.value().codepoints);
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
SWITCH_TO_RETURN_STATE;
} else {
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
SWITCH_TO(AmbiguousAmpersand);
}
}
@ -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_code_points(current_input_character.value());
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
continue;
} else {
EMIT_CURRENT_CHARACTER;
@ -1628,7 +1628,7 @@ _StartOfFunction:
ANYTHING_ELSE
{
PARSE_ERROR();
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
RECONSUME_IN_RETURN_STATE;
}
}
@ -1643,7 +1643,7 @@ _StartOfFunction:
ANYTHING_ELSE
{
PARSE_ERROR();
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
RECONSUME_IN_RETURN_STATE;
}
}
@ -1724,7 +1724,7 @@ _StartOfFunction:
PARSE_ERROR();
constexpr struct {
u32 number;
u32 code_points;
u32 codepoint;
} 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.code_points;
m_character_reference_code = entry.codepoint;
break;
}
}
@ -1764,7 +1764,7 @@ _StartOfFunction:
m_temporary_buffer.clear();
m_temporary_buffer.append(m_character_reference_code);
FLUSH_CODE_POINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
SWITCH_TO_RETURN_STATE;
}
END_STATE
@ -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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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_code_points(current_input_character.value());
m_current_token.m_tag.tag_name.append_codepoint(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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
RECONSUME_IN(RAWTEXT);
}
}
@ -2155,8 +2155,8 @@ _StartOfFunction:
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
for (auto code_points : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
}
RECONSUME_IN(ScriptDataEscaped);
}
@ -2167,8 +2167,8 @@ _StartOfFunction:
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
for (auto code_points : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
}
RECONSUME_IN(ScriptDataEscaped);
}
@ -2179,8 +2179,8 @@ _StartOfFunction:
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
for (auto code_points : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
}
RECONSUME_IN(ScriptDataEscaped);
}
@ -2200,8 +2200,8 @@ _StartOfFunction:
{
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
for (auto code_points : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer) {
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
}
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(code_points));
for (auto codepoint : m_temporary_buffer)
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
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 code_points = peek_code_points(i);
if (!code_points.has_value())
auto codepoint = peek_codepoint(i);
if (!codepoint.has_value())
return false;
// FIXME: This should be more Unicode-aware.
if (case_sensitivity == CaseSensitivity::CaseInsensitive) {
if (code_points.value() < 0x80) {
if (tolower(code_points.value()) != tolower(string[i]))
if (codepoint.value() < 0x80) {
if (tolower(codepoint.value()) != tolower(string[i]))
return false;
continue;
}
}
if (code_points.value() != (u32)string[i])
if (codepoint.value() != (u32)string[i])
return false;
}
for (size_t i = 0; i < string.length(); ++i) {

View file

@ -137,8 +137,8 @@ public:
String source() const { return m_decoded_input; }
private:
Optional<u32> next_code_points();
Optional<u32> peek_code_points(size_t offset) const;
Optional<u32> next_codepoint();
Optional<u32> peek_codepoint(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;

View file

@ -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.code_points_length_in_bytes());
builder.append(utf8_view.as_string().characters_without_null_termination() + utf8_view.byte_offset_of(it), it.codepoint_length_in_bytes());
} else {
builder.append(' ');
skip_over_whitespace();

View file

@ -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_code_points(code_point);
builder.append_codepoint(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.)

View file

@ -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_code_points(key_event.code_point());
m_current_search.append_codepoint(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();

View file

@ -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_code_pointss();
return utf8_name.length_in_codepoints();
}
for (int i = 0; name[i] != '\0'; i++) {