mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran: git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
This commit is contained in:
parent
19ac1f6368
commit
ce95628b7f
Notes:
sideshowbarker
2024-07-19 04:15:29 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/ce95628b7f9 Pull-request: https://github.com/SerenityOS/serenity/pull/3018
45 changed files with 441 additions and 441 deletions
|
@ -126,9 +126,9 @@ String JsonParser::consume_quoted_string()
|
||||||
sb.append(consume());
|
sb.append(consume());
|
||||||
sb.append(consume());
|
sb.append(consume());
|
||||||
|
|
||||||
auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
|
auto code_point = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
|
||||||
if (codepoint.has_value()) {
|
if (code_point.has_value()) {
|
||||||
final_sb.append_codepoint(codepoint.value());
|
final_sb.append_code_point(code_point.value());
|
||||||
} else {
|
} else {
|
||||||
final_sb.append('?');
|
final_sb.append('?');
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,22 +113,22 @@ void StringBuilder::clear()
|
||||||
m_length = 0;
|
m_length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder::append_codepoint(u32 codepoint)
|
void StringBuilder::append_code_point(u32 code_point)
|
||||||
{
|
{
|
||||||
if (codepoint <= 0x7f) {
|
if (code_point <= 0x7f) {
|
||||||
append((char)codepoint);
|
append((char)code_point);
|
||||||
} else if (codepoint <= 0x07ff) {
|
} else if (code_point <= 0x07ff) {
|
||||||
append((char)(((codepoint >> 6) & 0x1f) | 0xc0));
|
append((char)(((code_point >> 6) & 0x1f) | 0xc0));
|
||||||
append((char)(((codepoint >> 0) & 0x3f) | 0x80));
|
append((char)(((code_point >> 0) & 0x3f) | 0x80));
|
||||||
} else if (codepoint <= 0xffff) {
|
} else if (code_point <= 0xffff) {
|
||||||
append((char)(((codepoint >> 12) & 0x0f) | 0xe0));
|
append((char)(((code_point >> 12) & 0x0f) | 0xe0));
|
||||||
append((char)(((codepoint >> 6) & 0x3f) | 0x80));
|
append((char)(((code_point >> 6) & 0x3f) | 0x80));
|
||||||
append((char)(((codepoint >> 0) & 0x3f) | 0x80));
|
append((char)(((code_point >> 0) & 0x3f) | 0x80));
|
||||||
} else if (codepoint <= 0x10ffff) {
|
} else if (code_point <= 0x10ffff) {
|
||||||
append((char)(((codepoint >> 18) & 0x07) | 0xf0));
|
append((char)(((code_point >> 18) & 0x07) | 0xf0));
|
||||||
append((char)(((codepoint >> 12) & 0x3f) | 0x80));
|
append((char)(((code_point >> 12) & 0x3f) | 0x80));
|
||||||
append((char)(((codepoint >> 6) & 0x3f) | 0x80));
|
append((char)(((code_point >> 6) & 0x3f) | 0x80));
|
||||||
append((char)(((codepoint >> 0) & 0x3f) | 0x80));
|
append((char)(((code_point >> 0) & 0x3f) | 0x80));
|
||||||
} else {
|
} else {
|
||||||
append(0xef);
|
append(0xef);
|
||||||
append(0xbf);
|
append(0xbf);
|
||||||
|
@ -139,8 +139,8 @@ void StringBuilder::append_codepoint(u32 codepoint)
|
||||||
void StringBuilder::append(const Utf32View& utf32_view)
|
void StringBuilder::append(const Utf32View& utf32_view)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < utf32_view.length(); ++i) {
|
for (size_t i = 0; i < utf32_view.length(); ++i) {
|
||||||
auto codepoint = utf32_view.codepoints()[i];
|
auto code_point = utf32_view.code_points()[i];
|
||||||
append_codepoint(codepoint);
|
append_code_point(code_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
void append(const StringView&);
|
void append(const StringView&);
|
||||||
void append(const Utf32View&);
|
void append(const Utf32View&);
|
||||||
void append(char);
|
void append(char);
|
||||||
void append_codepoint(u32);
|
void append_code_point(u32);
|
||||||
void append(const char*, size_t);
|
void append(const char*, size_t);
|
||||||
void appendf(const char*, ...);
|
void appendf(const char*, ...);
|
||||||
void appendvf(const char*, va_list);
|
void appendvf(const char*, va_list);
|
||||||
|
|
|
@ -37,9 +37,9 @@ TEST_CASE(decode_ascii)
|
||||||
size_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
size_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (u32 codepoint : utf8) {
|
for (u32 code_point : utf8) {
|
||||||
ASSERT(i < expected_size);
|
ASSERT(i < expected_size);
|
||||||
EXPECT_EQ(codepoint, expected[i]);
|
EXPECT_EQ(code_point, expected[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(i, expected_size);
|
EXPECT_EQ(i, expected_size);
|
||||||
|
@ -56,9 +56,9 @@ TEST_CASE(decode_utf8)
|
||||||
size_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
size_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (u32 codepoint : utf8) {
|
for (u32 code_point : utf8) {
|
||||||
ASSERT(i < expected_size);
|
ASSERT(i < expected_size);
|
||||||
EXPECT_EQ(codepoint, expected[i]);
|
EXPECT_EQ(code_point, expected[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(i, expected_size);
|
EXPECT_EQ(i, expected_size);
|
||||||
|
|
|
@ -35,14 +35,14 @@ namespace AK {
|
||||||
class Utf32View {
|
class Utf32View {
|
||||||
public:
|
public:
|
||||||
Utf32View() { }
|
Utf32View() { }
|
||||||
Utf32View(const u32* codepoints, size_t length)
|
Utf32View(const u32* code_points, size_t length)
|
||||||
: m_codepoints(codepoints)
|
: m_code_points(code_points)
|
||||||
, m_length(length)
|
, m_length(length)
|
||||||
{
|
{
|
||||||
ASSERT(codepoints || length == 0);
|
ASSERT(code_points || length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32* codepoints() const { return m_codepoints; }
|
const u32* code_points() const { return m_code_points; }
|
||||||
bool is_empty() const { return m_length == 0; }
|
bool is_empty() const { return m_length == 0; }
|
||||||
size_t length() const { return m_length; }
|
size_t length() const { return m_length; }
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ public:
|
||||||
ASSERT(offset < m_length);
|
ASSERT(offset < m_length);
|
||||||
ASSERT(!Checked<size_t>::addition_would_overflow(offset, length));
|
ASSERT(!Checked<size_t>::addition_would_overflow(offset, length));
|
||||||
ASSERT((offset + length) <= m_length);
|
ASSERT((offset + length) <= m_length);
|
||||||
return Utf32View(m_codepoints + offset, length);
|
return Utf32View(m_code_points + offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const u32* m_codepoints { nullptr };
|
const u32* m_code_points { nullptr };
|
||||||
size_t m_length { 0 };
|
size_t m_length { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,12 +81,12 @@ Utf8View Utf8View::substring_view(int byte_offset, int byte_length) const
|
||||||
|
|
||||||
static inline bool decode_first_byte(
|
static inline bool decode_first_byte(
|
||||||
unsigned char byte,
|
unsigned char byte,
|
||||||
int& out_codepoint_length_in_bytes,
|
int& out_code_point_length_in_bytes,
|
||||||
u32& out_value)
|
u32& out_value)
|
||||||
{
|
{
|
||||||
if ((byte & 128) == 0) {
|
if ((byte & 128) == 0) {
|
||||||
out_value = byte;
|
out_value = byte;
|
||||||
out_codepoint_length_in_bytes = 1;
|
out_code_point_length_in_bytes = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((byte & 64) == 0) {
|
if ((byte & 64) == 0) {
|
||||||
|
@ -94,17 +94,17 @@ static inline bool decode_first_byte(
|
||||||
}
|
}
|
||||||
if ((byte & 32) == 0) {
|
if ((byte & 32) == 0) {
|
||||||
out_value = byte & 31;
|
out_value = byte & 31;
|
||||||
out_codepoint_length_in_bytes = 2;
|
out_code_point_length_in_bytes = 2;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((byte & 16) == 0) {
|
if ((byte & 16) == 0) {
|
||||||
out_value = byte & 15;
|
out_value = byte & 15;
|
||||||
out_codepoint_length_in_bytes = 3;
|
out_code_point_length_in_bytes = 3;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((byte & 8) == 0) {
|
if ((byte & 8) == 0) {
|
||||||
out_value = byte & 7;
|
out_value = byte & 7;
|
||||||
out_codepoint_length_in_bytes = 4;
|
out_code_point_length_in_bytes = 4;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,13 +115,13 @@ bool Utf8View::validate(size_t& valid_bytes) const
|
||||||
{
|
{
|
||||||
valid_bytes = 0;
|
valid_bytes = 0;
|
||||||
for (auto ptr = begin_ptr(); ptr < end_ptr(); ptr++) {
|
for (auto ptr = begin_ptr(); ptr < end_ptr(); ptr++) {
|
||||||
int codepoint_length_in_bytes;
|
int code_point_length_in_bytes;
|
||||||
u32 value;
|
u32 value;
|
||||||
bool first_byte_makes_sense = decode_first_byte(*ptr, codepoint_length_in_bytes, value);
|
bool first_byte_makes_sense = decode_first_byte(*ptr, code_point_length_in_bytes, value);
|
||||||
if (!first_byte_makes_sense)
|
if (!first_byte_makes_sense)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i = 1; i < codepoint_length_in_bytes; i++) {
|
for (int i = 1; i < code_point_length_in_bytes; i++) {
|
||||||
ptr++;
|
ptr++;
|
||||||
if (ptr >= end_ptr())
|
if (ptr >= end_ptr())
|
||||||
return false;
|
return false;
|
||||||
|
@ -129,17 +129,17 @@ bool Utf8View::validate(size_t& valid_bytes) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
valid_bytes += codepoint_length_in_bytes;
|
valid_bytes += code_point_length_in_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Utf8View::length_in_codepoints() const
|
size_t Utf8View::length_in_code_points() const
|
||||||
{
|
{
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
for (auto codepoint : *this) {
|
for (auto code_point : *this) {
|
||||||
(void)codepoint;
|
(void)code_point;
|
||||||
++length;
|
++length;
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
|
@ -165,54 +165,54 @@ Utf8CodepointIterator& Utf8CodepointIterator::operator++()
|
||||||
{
|
{
|
||||||
ASSERT(m_length > 0);
|
ASSERT(m_length > 0);
|
||||||
|
|
||||||
int codepoint_length_in_bytes = 0;
|
int code_point_length_in_bytes = 0;
|
||||||
u32 value;
|
u32 value;
|
||||||
bool first_byte_makes_sense = decode_first_byte(*m_ptr, codepoint_length_in_bytes, value);
|
bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_point_length_in_bytes, value);
|
||||||
|
|
||||||
ASSERT(first_byte_makes_sense);
|
ASSERT(first_byte_makes_sense);
|
||||||
(void)value;
|
(void)value;
|
||||||
|
|
||||||
ASSERT(codepoint_length_in_bytes <= m_length);
|
ASSERT(code_point_length_in_bytes <= m_length);
|
||||||
m_ptr += codepoint_length_in_bytes;
|
m_ptr += code_point_length_in_bytes;
|
||||||
m_length -= codepoint_length_in_bytes;
|
m_length -= code_point_length_in_bytes;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utf8CodepointIterator::codepoint_length_in_bytes() const
|
int Utf8CodepointIterator::code_point_length_in_bytes() const
|
||||||
{
|
{
|
||||||
ASSERT(m_length > 0);
|
ASSERT(m_length > 0);
|
||||||
int codepoint_length_in_bytes = 0;
|
int code_point_length_in_bytes = 0;
|
||||||
u32 value;
|
u32 value;
|
||||||
bool first_byte_makes_sense = decode_first_byte(*m_ptr, codepoint_length_in_bytes, value);
|
bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_point_length_in_bytes, value);
|
||||||
ASSERT(first_byte_makes_sense);
|
ASSERT(first_byte_makes_sense);
|
||||||
return codepoint_length_in_bytes;
|
return code_point_length_in_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Utf8CodepointIterator::operator*() const
|
u32 Utf8CodepointIterator::operator*() const
|
||||||
{
|
{
|
||||||
ASSERT(m_length > 0);
|
ASSERT(m_length > 0);
|
||||||
|
|
||||||
u32 codepoint_value_so_far = 0;
|
u32 code_point_value_so_far = 0;
|
||||||
int codepoint_length_in_bytes = 0;
|
int code_point_length_in_bytes = 0;
|
||||||
|
|
||||||
bool first_byte_makes_sense = decode_first_byte(m_ptr[0], codepoint_length_in_bytes, codepoint_value_so_far);
|
bool first_byte_makes_sense = decode_first_byte(m_ptr[0], code_point_length_in_bytes, code_point_value_so_far);
|
||||||
if (!first_byte_makes_sense) {
|
if (!first_byte_makes_sense) {
|
||||||
dbg() << "First byte doesn't make sense, bytes: " << StringView((const char*)m_ptr, m_length);
|
dbg() << "First byte doesn't make sense, bytes: " << StringView((const char*)m_ptr, m_length);
|
||||||
}
|
}
|
||||||
ASSERT(first_byte_makes_sense);
|
ASSERT(first_byte_makes_sense);
|
||||||
if (codepoint_length_in_bytes > m_length) {
|
if (code_point_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;
|
dbg() << "Not enough bytes (need " << code_point_length_in_bytes << ", have " << m_length << "), first byte is: " << m_ptr[0] << " " << (const char*)m_ptr;
|
||||||
}
|
}
|
||||||
ASSERT(codepoint_length_in_bytes <= m_length);
|
ASSERT(code_point_length_in_bytes <= m_length);
|
||||||
|
|
||||||
for (int offset = 1; offset < codepoint_length_in_bytes; offset++) {
|
for (int offset = 1; offset < code_point_length_in_bytes; offset++) {
|
||||||
ASSERT(m_ptr[offset] >> 6 == 2);
|
ASSERT(m_ptr[offset] >> 6 == 2);
|
||||||
codepoint_value_so_far <<= 6;
|
code_point_value_so_far <<= 6;
|
||||||
codepoint_value_so_far |= m_ptr[offset] & 63;
|
code_point_value_so_far |= m_ptr[offset] & 63;
|
||||||
}
|
}
|
||||||
|
|
||||||
return codepoint_value_so_far;
|
return code_point_value_so_far;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
Utf8CodepointIterator& operator++();
|
Utf8CodepointIterator& operator++();
|
||||||
u32 operator*() const;
|
u32 operator*() const;
|
||||||
|
|
||||||
int codepoint_length_in_bytes() const;
|
int code_point_length_in_bytes() const;
|
||||||
bool done() const { return !m_length; }
|
bool done() const { return !m_length; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
return validate(valid_bytes);
|
return validate(valid_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t length_in_codepoints() const;
|
size_t length_in_code_points() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const unsigned char* begin_ptr() const;
|
const unsigned char* begin_ptr() const;
|
||||||
|
|
|
@ -267,7 +267,7 @@ void KeyboardMapperWidget::set_current_map(const String current_map)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AK::StringBuilder sb;
|
AK::StringBuilder sb;
|
||||||
sb.append_codepoint(map[index]);
|
sb.append_code_point(map[index]);
|
||||||
|
|
||||||
m_keys.at(k)->set_text(sb.to_string());
|
m_keys.at(k)->set_text(sb.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,10 +287,10 @@ void VirtualConsole::flush_dirty_lines()
|
||||||
if (!line.is_dirty() && !m_terminal.m_need_full_flush)
|
if (!line.is_dirty() && !m_terminal.m_need_full_flush)
|
||||||
continue;
|
continue;
|
||||||
for (size_t column = 0; column < line.length(); ++column) {
|
for (size_t column = 0; column < line.length(); ++column) {
|
||||||
u32 codepoint = line.codepoint(column);
|
u32 code_point = line.code_point(column);
|
||||||
auto attribute = line.attributes()[column];
|
auto attribute = line.attributes()[column];
|
||||||
u16 vga_index = (visual_row * 160) + (column * 2);
|
u16 vga_index = (visual_row * 160) + (column * 2);
|
||||||
m_current_vga_window[vga_index] = codepoint < 128 ? codepoint : '?';
|
m_current_vga_window[vga_index] = code_point < 128 ? code_point : '?';
|
||||||
m_current_vga_window[vga_index + 1] = attribute_to_vga(attribute);
|
m_current_vga_window[vga_index + 1] = attribute_to_vga(attribute);
|
||||||
}
|
}
|
||||||
line.set_dirty(false);
|
line.set_dirty(false);
|
||||||
|
|
|
@ -37,9 +37,9 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
static Vector<u32> supported_emoji_codepoints()
|
static Vector<u32> supported_emoji_code_points()
|
||||||
{
|
{
|
||||||
Vector<u32> codepoints;
|
Vector<u32> code_points;
|
||||||
Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots);
|
Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots);
|
||||||
while (dt.has_next()) {
|
while (dt.has_next()) {
|
||||||
auto filename = dt.next_path();
|
auto filename = dt.next_path();
|
||||||
|
@ -49,10 +49,10 @@ static Vector<u32> supported_emoji_codepoints()
|
||||||
auto basename = lexical_path.basename();
|
auto basename = lexical_path.basename();
|
||||||
if (!basename.starts_with("U+"))
|
if (!basename.starts_with("U+"))
|
||||||
continue;
|
continue;
|
||||||
u32 codepoint = strtoul(basename.characters() + 2, nullptr, 16);
|
u32 code_point = strtoul(basename.characters() + 2, nullptr, 16);
|
||||||
codepoints.append(codepoint);
|
code_points.append(code_point);
|
||||||
}
|
}
|
||||||
return codepoints;
|
return code_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
||||||
|
@ -67,20 +67,20 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
||||||
auto& main_layout = main_widget.set_layout<VerticalBoxLayout>();
|
auto& main_layout = main_widget.set_layout<VerticalBoxLayout>();
|
||||||
main_layout.set_spacing(0);
|
main_layout.set_spacing(0);
|
||||||
|
|
||||||
auto codepoints = supported_emoji_codepoints();
|
auto code_points = supported_emoji_code_points();
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
size_t columns = 6;
|
size_t columns = 6;
|
||||||
size_t rows = ceil_div(codepoints.size(), columns);
|
size_t rows = ceil_div(code_points.size(), columns);
|
||||||
|
|
||||||
for (size_t row = 0; row < rows && index < codepoints.size(); ++row) {
|
for (size_t row = 0; row < rows && index < code_points.size(); ++row) {
|
||||||
auto& horizontal_container = main_widget.add<Widget>();
|
auto& horizontal_container = main_widget.add<Widget>();
|
||||||
auto& horizontal_layout = horizontal_container.set_layout<HorizontalBoxLayout>();
|
auto& horizontal_layout = horizontal_container.set_layout<HorizontalBoxLayout>();
|
||||||
horizontal_layout.set_spacing(0);
|
horizontal_layout.set_spacing(0);
|
||||||
for (size_t column = 0; column < columns; ++column) {
|
for (size_t column = 0; column < columns; ++column) {
|
||||||
if (index < codepoints.size()) {
|
if (index < code_points.size()) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(Utf32View(&codepoints[index++], 1));
|
builder.append(Utf32View(&code_points[index++], 1));
|
||||||
auto emoji_text = builder.to_string();
|
auto emoji_text = builder.to_string();
|
||||||
auto& button = horizontal_container.add<Button>(emoji_text);
|
auto& button = horizontal_container.add<Button>(emoji_text);
|
||||||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||||
|
|
|
@ -298,7 +298,7 @@ public:
|
||||||
String text() const
|
String text() const
|
||||||
{
|
{
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
sb.append_codepoint(m_code_point);
|
sb.append_code_point(m_code_point);
|
||||||
return sb.to_string();
|
return sb.to_string();
|
||||||
}
|
}
|
||||||
u32 scancode() const { return m_scancode; }
|
u32 scancode() const { return m_scancode; }
|
||||||
|
|
|
@ -87,8 +87,8 @@ void TextDocument::set_text(const StringView& text)
|
||||||
size_t TextDocumentLine::first_non_whitespace_column() const
|
size_t TextDocumentLine::first_non_whitespace_column() const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < length(); ++i) {
|
for (size_t i = 0; i < length(); ++i) {
|
||||||
auto codepoint = codepoints()[i];
|
auto code_point = code_points()[i];
|
||||||
if (!isspace(codepoint))
|
if (!isspace(code_point))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return length();
|
return length();
|
||||||
|
@ -131,35 +131,35 @@ void TextDocumentLine::set_text(TextDocument& document, const StringView& text)
|
||||||
}
|
}
|
||||||
m_text.clear();
|
m_text.clear();
|
||||||
Utf8View utf8_view(text);
|
Utf8View utf8_view(text);
|
||||||
for (auto codepoint : utf8_view)
|
for (auto code_point : utf8_view)
|
||||||
m_text.append(codepoint);
|
m_text.append(code_point);
|
||||||
document.update_views({});
|
document.update_views({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDocumentLine::append(TextDocument& document, const u32* codepoints, size_t length)
|
void TextDocumentLine::append(TextDocument& document, const u32* code_points, size_t length)
|
||||||
{
|
{
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return;
|
return;
|
||||||
m_text.append(codepoints, length);
|
m_text.append(code_points, length);
|
||||||
document.update_views({});
|
document.update_views({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDocumentLine::append(TextDocument& document, u32 codepoint)
|
void TextDocumentLine::append(TextDocument& document, u32 code_point)
|
||||||
{
|
{
|
||||||
insert(document, length(), codepoint);
|
insert(document, length(), code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDocumentLine::prepend(TextDocument& document, u32 codepoint)
|
void TextDocumentLine::prepend(TextDocument& document, u32 code_point)
|
||||||
{
|
{
|
||||||
insert(document, 0, codepoint);
|
insert(document, 0, code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDocumentLine::insert(TextDocument& document, size_t index, u32 codepoint)
|
void TextDocumentLine::insert(TextDocument& document, size_t index, u32 code_point)
|
||||||
{
|
{
|
||||||
if (index == length()) {
|
if (index == length()) {
|
||||||
m_text.append(codepoint);
|
m_text.append(code_point);
|
||||||
} else {
|
} else {
|
||||||
m_text.insert(index, codepoint);
|
m_text.insert(index, code_point);
|
||||||
}
|
}
|
||||||
document.update_views({});
|
document.update_views({});
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ String TextDocument::text_in_range(const TextRange& a_range) const
|
||||||
auto& line = this->line(i);
|
auto& line = this->line(i);
|
||||||
size_t selection_start_column_on_line = range.start().line() == i ? range.start().column() : 0;
|
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();
|
size_t selection_end_column_on_line = range.end().line() == i ? range.end().column() : line.length();
|
||||||
builder.append(Utf32View(line.codepoints() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line));
|
builder.append(Utf32View(line.code_points() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line));
|
||||||
if (i != range.end().line())
|
if (i != range.end().line())
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
}
|
}
|
||||||
|
@ -282,13 +282,13 @@ String TextDocument::text_in_range(const TextRange& a_range) const
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 TextDocument::codepoint_at(const TextPosition& position) const
|
u32 TextDocument::code_point_at(const TextPosition& position) const
|
||||||
{
|
{
|
||||||
ASSERT(position.line() < line_count());
|
ASSERT(position.line() < line_count());
|
||||||
auto& line = this->line(position.line());
|
auto& line = this->line(position.line());
|
||||||
if (position.column() == line.length())
|
if (position.column() == line.length())
|
||||||
return '\n';
|
return '\n';
|
||||||
return line.codepoints()[position.column()];
|
return line.code_points()[position.column()];
|
||||||
}
|
}
|
||||||
|
|
||||||
TextPosition TextDocument::next_position_after(const TextPosition& position, SearchShouldWrap should_wrap) const
|
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;
|
size_t needle_index = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
auto ch = codepoint_at(position);
|
auto ch = code_point_at(position);
|
||||||
// FIXME: This is not the right way to use a Unicode needle!
|
// FIXME: This is not the right way to use a Unicode needle!
|
||||||
if (ch == (u32)needle[needle_index]) {
|
if (ch == (u32)needle[needle_index]) {
|
||||||
if (needle_index == 0)
|
if (needle_index == 0)
|
||||||
|
@ -365,7 +365,7 @@ TextRange TextDocument::find_previous(const StringView& needle, const TextPositi
|
||||||
size_t needle_index = needle.length() - 1;
|
size_t needle_index = needle.length() - 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
auto ch = codepoint_at(position);
|
auto ch = code_point_at(position);
|
||||||
// FIXME: This is not the right way to use a Unicode needle!
|
// FIXME: This is not the right way to use a Unicode needle!
|
||||||
if (ch == (u32)needle[needle_index]) {
|
if (ch == (u32)needle[needle_index]) {
|
||||||
if (needle_index == needle.length() - 1)
|
if (needle_index == needle.length() - 1)
|
||||||
|
@ -439,11 +439,11 @@ TextPosition TextDocument::first_word_break_before(const TextPosition& position,
|
||||||
|
|
||||||
auto target = position;
|
auto target = position;
|
||||||
auto line = this->line(target.line());
|
auto line = this->line(target.line());
|
||||||
auto is_start_alphanumeric = isalnum(line.codepoints()[target.column() - (start_at_column_before ? 1 : 0)]);
|
auto is_start_alphanumeric = isalnum(line.code_points()[target.column() - (start_at_column_before ? 1 : 0)]);
|
||||||
|
|
||||||
while (target.column() > 0) {
|
while (target.column() > 0) {
|
||||||
auto prev_codepoint = line.codepoints()[target.column() - 1];
|
auto prev_code_point = line.code_points()[target.column() - 1];
|
||||||
if ((is_start_alphanumeric && !isalnum(prev_codepoint)) || (!is_start_alphanumeric && isalnum(prev_codepoint)))
|
if ((is_start_alphanumeric && !isalnum(prev_code_point)) || (!is_start_alphanumeric && isalnum(prev_code_point)))
|
||||||
break;
|
break;
|
||||||
target.set_column(target.column() - 1);
|
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);
|
return TextPosition(position.line() + 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto is_start_alphanumeric = isalnum(line.codepoints()[target.column()]);
|
auto is_start_alphanumeric = isalnum(line.code_points()[target.column()]);
|
||||||
|
|
||||||
while (target.column() < line.length()) {
|
while (target.column() < line.length()) {
|
||||||
auto next_codepoint = line.codepoints()[target.column()];
|
auto next_code_point = line.code_points()[target.column()];
|
||||||
if ((is_start_alphanumeric && !isalnum(next_codepoint)) || (!is_start_alphanumeric && isalnum(next_codepoint)))
|
if ((is_start_alphanumeric && !isalnum(next_code_point)) || (!is_start_alphanumeric && isalnum(next_code_point)))
|
||||||
break;
|
break;
|
||||||
target.set_column(target.column() + 1);
|
target.set_column(target.column() + 1);
|
||||||
}
|
}
|
||||||
|
@ -555,26 +555,26 @@ TextPosition TextDocument::insert_at(const TextPosition& position, const StringV
|
||||||
{
|
{
|
||||||
TextPosition cursor = position;
|
TextPosition cursor = position;
|
||||||
Utf8View utf8_view(text);
|
Utf8View utf8_view(text);
|
||||||
for (auto codepoint : utf8_view)
|
for (auto code_point : utf8_view)
|
||||||
cursor = insert_at(cursor, codepoint, client);
|
cursor = insert_at(cursor, code_point, client);
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint, const Client* client)
|
TextPosition TextDocument::insert_at(const TextPosition& position, u32 code_point, const Client* client)
|
||||||
{
|
{
|
||||||
bool automatic_indentation_enabled = client ? client->is_automatic_indentation_enabled() : false;
|
bool automatic_indentation_enabled = client ? client->is_automatic_indentation_enabled() : false;
|
||||||
size_t m_soft_tab_width = client ? client->soft_tab_width() : 4;
|
size_t m_soft_tab_width = client ? client->soft_tab_width() : 4;
|
||||||
|
|
||||||
bool at_head = position.column() == 0;
|
bool at_head = position.column() == 0;
|
||||||
bool at_tail = position.column() == line(position.line()).length();
|
bool at_tail = position.column() == line(position.line()).length();
|
||||||
if (codepoint == '\n') {
|
if (code_point == '\n') {
|
||||||
if (at_tail || at_head) {
|
if (at_tail || at_head) {
|
||||||
String new_line_contents;
|
String new_line_contents;
|
||||||
if (automatic_indentation_enabled && at_tail) {
|
if (automatic_indentation_enabled && at_tail) {
|
||||||
size_t leading_spaces = 0;
|
size_t leading_spaces = 0;
|
||||||
auto& old_line = lines()[position.line()];
|
auto& old_line = lines()[position.line()];
|
||||||
for (size_t i = 0; i < old_line.length(); ++i) {
|
for (size_t i = 0; i < old_line.length(); ++i) {
|
||||||
if (old_line.codepoints()[i] == ' ')
|
if (old_line.code_points()[i] == ' ')
|
||||||
++leading_spaces;
|
++leading_spaces;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
@ -586,23 +586,23 @@ TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint
|
||||||
size_t row = position.line();
|
size_t row = position.line();
|
||||||
Vector<u32> line_content;
|
Vector<u32> line_content;
|
||||||
for (size_t i = position.column(); i < line(row).length(); i++)
|
for (size_t i = position.column(); i < line(row).length(); i++)
|
||||||
line_content.append(line(row).codepoints()[i]);
|
line_content.append(line(row).code_points()[i]);
|
||||||
insert_line(position.line() + (at_tail ? 1 : 0), make<TextDocumentLine>(*this, new_line_contents));
|
insert_line(position.line() + (at_tail ? 1 : 0), make<TextDocumentLine>(*this, new_line_contents));
|
||||||
notify_did_change();
|
notify_did_change();
|
||||||
return { position.line() + 1, line(position.line() + 1).length() };
|
return { position.line() + 1, line(position.line() + 1).length() };
|
||||||
}
|
}
|
||||||
auto new_line = make<TextDocumentLine>(*this);
|
auto new_line = make<TextDocumentLine>(*this);
|
||||||
new_line->append(*this, line(position.line()).codepoints() + position.column(), line(position.line()).length() - position.column());
|
new_line->append(*this, line(position.line()).code_points() + position.column(), line(position.line()).length() - position.column());
|
||||||
|
|
||||||
Vector<u32> line_content;
|
Vector<u32> line_content;
|
||||||
for (size_t i = 0; i < new_line->length(); i++)
|
for (size_t i = 0; i < new_line->length(); i++)
|
||||||
line_content.append(new_line->codepoints()[i]);
|
line_content.append(new_line->code_points()[i]);
|
||||||
line(position.line()).truncate(*this, position.column());
|
line(position.line()).truncate(*this, position.column());
|
||||||
insert_line(position.line() + 1, move(new_line));
|
insert_line(position.line() + 1, move(new_line));
|
||||||
notify_did_change();
|
notify_did_change();
|
||||||
return { position.line() + 1, 0 };
|
return { position.line() + 1, 0 };
|
||||||
}
|
}
|
||||||
if (codepoint == '\t') {
|
if (code_point == '\t') {
|
||||||
size_t next_soft_tab_stop = ((position.column() + m_soft_tab_width) / m_soft_tab_width) * m_soft_tab_width;
|
size_t 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();
|
size_t spaces_to_insert = next_soft_tab_stop - position.column();
|
||||||
for (size_t i = 0; i < spaces_to_insert; ++i) {
|
for (size_t i = 0; i < spaces_to_insert; ++i) {
|
||||||
|
@ -611,7 +611,7 @@ TextPosition TextDocument::insert_at(const TextPosition& position, u32 codepoint
|
||||||
notify_did_change();
|
notify_did_change();
|
||||||
return { position.line(), next_soft_tab_stop };
|
return { position.line(), next_soft_tab_stop };
|
||||||
}
|
}
|
||||||
line(position.line()).insert(*this, position.column(), codepoint);
|
line(position.line()).insert(*this, position.column(), code_point);
|
||||||
notify_did_change();
|
notify_did_change();
|
||||||
return { position.line(), position.column() + 1 };
|
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);
|
ASSERT(range.start().line() == range.end().line() - 1);
|
||||||
auto& first_line = line(range.start().line());
|
auto& first_line = line(range.start().line());
|
||||||
auto& second_line = line(range.end().line());
|
auto& second_line = line(range.end().line());
|
||||||
Vector<u32> codepoints;
|
Vector<u32> code_points;
|
||||||
codepoints.append(first_line.codepoints(), range.start().column());
|
code_points.append(first_line.code_points(), range.start().column());
|
||||||
codepoints.append(second_line.codepoints() + range.end().column(), second_line.length() - range.end().column());
|
code_points.append(second_line.code_points() + range.end().column(), second_line.length() - range.end().column());
|
||||||
first_line.set_text(*this, move(codepoints));
|
first_line.set_text(*this, move(code_points));
|
||||||
remove_line(range.end().line());
|
remove_line(range.end().line());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ public:
|
||||||
TextPosition next_position_after(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
|
TextPosition next_position_after(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
|
||||||
TextPosition previous_position_before(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
|
TextPosition previous_position_before(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
|
||||||
|
|
||||||
u32 codepoint_at(const TextPosition&) const;
|
u32 code_point_at(const TextPosition&) const;
|
||||||
|
|
||||||
TextRange range_for_entire_line(size_t line_index) const;
|
TextRange range_for_entire_line(size_t line_index) const;
|
||||||
|
|
||||||
|
@ -159,8 +159,8 @@ public:
|
||||||
|
|
||||||
String to_utf8() const;
|
String to_utf8() const;
|
||||||
|
|
||||||
Utf32View view() const { return { codepoints(), length() }; }
|
Utf32View view() const { return { code_points(), length() }; }
|
||||||
const u32* codepoints() const { return m_text.data(); }
|
const u32* code_points() const { return m_text.data(); }
|
||||||
size_t length() const { return m_text.size(); }
|
size_t length() const { return m_text.size(); }
|
||||||
void set_text(TextDocument&, const StringView&);
|
void set_text(TextDocument&, const StringView&);
|
||||||
void set_text(TextDocument&, Vector<u32>);
|
void set_text(TextDocument&, Vector<u32>);
|
||||||
|
|
|
@ -172,7 +172,7 @@ TextPosition TextEditor::text_position_at(const Gfx::IntPoint& a_position) const
|
||||||
int glyph_x = 0;
|
int glyph_x = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; i < view.length(); ++i) {
|
for (; i < view.length(); ++i) {
|
||||||
int advance = font().glyph_width(view.codepoints()[i]) + font().glyph_spacing();
|
int advance = font().glyph_width(view.code_points()[i]) + font().glyph_spacing();
|
||||||
if ((glyph_x + (advance / 2)) >= position.x())
|
if ((glyph_x + (advance / 2)) >= position.x())
|
||||||
break;
|
break;
|
||||||
glyph_x += advance;
|
glyph_x += advance;
|
||||||
|
@ -465,7 +465,7 @@ void TextEditor::paint_event(PaintEvent& event)
|
||||||
} else {
|
} else {
|
||||||
Gfx::IntRect character_rect = { visual_line_rect.location(), { 0, line_height() } };
|
Gfx::IntRect character_rect = { visual_line_rect.location(), { 0, line_height() } };
|
||||||
for (size_t i = 0; i < visual_line_text.length(); ++i) {
|
for (size_t i = 0; i < visual_line_text.length(); ++i) {
|
||||||
u32 codepoint = visual_line_text.substring_view(i, 1).codepoints()[0];
|
u32 code_point = visual_line_text.substring_view(i, 1).code_points()[0];
|
||||||
const Gfx::Font* font = &this->font();
|
const Gfx::Font* font = &this->font();
|
||||||
Color color;
|
Color color;
|
||||||
Optional<Color> background_color;
|
Optional<Color> background_color;
|
||||||
|
@ -482,7 +482,7 @@ void TextEditor::paint_event(PaintEvent& event)
|
||||||
underline = span.is_underlined;
|
underline = span.is_underlined;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
character_rect.set_width(font->glyph_width(codepoint) + font->glyph_spacing());
|
character_rect.set_width(font->glyph_width(code_point) + font->glyph_spacing());
|
||||||
if (background_color.has_value())
|
if (background_color.has_value())
|
||||||
painter.fill_rect(character_rect, background_color.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);
|
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);
|
painter.fill_rect(selection_rect, background_color);
|
||||||
|
|
||||||
if (visual_line_text.codepoints()) {
|
if (visual_line_text.code_points()) {
|
||||||
Utf32View visual_selected_text {
|
Utf32View visual_selected_text {
|
||||||
visual_line_text.codepoints() + start_of_selection_within_visual_line,
|
visual_line_text.code_points() + start_of_selection_within_visual_line,
|
||||||
end_of_selection_within_visual_line - start_of_selection_within_visual_line
|
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;
|
auto end = lines.begin() + (int)last_line + 1;
|
||||||
|
|
||||||
quick_sort(start, end, [](auto& a, auto& b) {
|
quick_sort(start, end, [](auto& a, auto& b) {
|
||||||
return strcmp_utf32(a.codepoints(), b.codepoints(), min(a.length(), b.length())) < 0;
|
return strcmp_utf32(a.code_points(), b.code_points(), min(a.length(), b.length())) < 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
did_change();
|
did_change();
|
||||||
|
@ -939,7 +939,7 @@ void TextEditor::keydown_event(KeyEvent& event)
|
||||||
|
|
||||||
if (is_editable() && !event.ctrl() && !event.alt() && event.code_point() != 0) {
|
if (is_editable() && !event.ctrl() && !event.alt() && event.code_point() != 0) {
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
sb.append_codepoint(event.code_point());
|
sb.append_code_point(event.code_point());
|
||||||
|
|
||||||
insert_at_cursor_or_replace_selection(sb.to_string());
|
insert_at_cursor_or_replace_selection(sb.to_string());
|
||||||
return;
|
return;
|
||||||
|
@ -1525,8 +1525,8 @@ void TextEditor::recompute_visual_lines(size_t line_index)
|
||||||
|
|
||||||
auto glyph_spacing = font().glyph_spacing();
|
auto glyph_spacing = font().glyph_spacing();
|
||||||
for (size_t i = 0; i < line.length(); ++i) {
|
for (size_t i = 0; i < line.length(); ++i) {
|
||||||
auto codepoint = line.codepoints()[i];
|
auto code_point = line.code_points()[i];
|
||||||
auto glyph_width = font().glyph_or_emoji_width(codepoint);
|
auto glyph_width = font().glyph_or_emoji_width(code_point);
|
||||||
if ((line_width_so_far + glyph_width + glyph_spacing) > available_width) {
|
if ((line_width_so_far + glyph_width + glyph_spacing) > available_width) {
|
||||||
visual_data.visual_line_breaks.append(i);
|
visual_data.visual_line_breaks.append(i);
|
||||||
line_width_so_far = glyph_width + glyph_spacing;
|
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];
|
auto& visual_data = m_line_visual_data[line_index];
|
||||||
|
|
||||||
for (auto visual_line_break : visual_data.visual_line_breaks) {
|
for (auto visual_line_break : visual_data.visual_line_breaks) {
|
||||||
auto visual_line_view = Utf32View(line.codepoints() + start_of_line, visual_line_break - start_of_line);
|
auto visual_line_view = Utf32View(line.code_points() + start_of_line, visual_line_break - start_of_line);
|
||||||
Gfx::IntRect visual_line_rect {
|
Gfx::IntRect visual_line_rect {
|
||||||
visual_data.visual_rect.x(),
|
visual_data.visual_rect.x(),
|
||||||
visual_data.visual_rect.y() + ((int)visual_line_index * line_height()),
|
visual_data.visual_rect.y() + ((int)visual_line_index * line_height()),
|
||||||
|
|
|
@ -33,21 +33,21 @@ namespace Gfx {
|
||||||
|
|
||||||
static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis;
|
static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis;
|
||||||
|
|
||||||
const Bitmap* Emoji::emoji_for_codepoint(u32 codepoint)
|
const Bitmap* Emoji::emoji_for_code_point(u32 code_point)
|
||||||
{
|
{
|
||||||
auto it = s_emojis.find(codepoint);
|
auto it = s_emojis.find(code_point);
|
||||||
if (it != s_emojis.end())
|
if (it != s_emojis.end())
|
||||||
return (*it).value.ptr();
|
return (*it).value.ptr();
|
||||||
|
|
||||||
String path = String::format("/res/emoji/U+%X.png", codepoint);
|
String path = String::format("/res/emoji/U+%X.png", code_point);
|
||||||
|
|
||||||
auto bitmap = Bitmap::load_from_file(path);
|
auto bitmap = Bitmap::load_from_file(path);
|
||||||
if (!bitmap) {
|
if (!bitmap) {
|
||||||
s_emojis.set(codepoint, nullptr);
|
s_emojis.set(code_point, nullptr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_emojis.set(codepoint, bitmap);
|
s_emojis.set(code_point, bitmap);
|
||||||
return bitmap.ptr();
|
return bitmap.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Bitmap;
|
||||||
|
|
||||||
class Emoji {
|
class Emoji {
|
||||||
public:
|
public:
|
||||||
static const Gfx::Bitmap* emoji_for_codepoint(u32 codepoint);
|
static const Gfx::Bitmap* emoji_for_code_point(u32 code_point);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,20 +255,20 @@ bool Font::write_to_file(const StringView& path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphBitmap Font::glyph_bitmap(u32 codepoint) const
|
GlyphBitmap Font::glyph_bitmap(u32 code_point) const
|
||||||
{
|
{
|
||||||
return GlyphBitmap(&m_rows[codepoint * m_glyph_height], { glyph_width(codepoint), m_glyph_height });
|
return GlyphBitmap(&m_rows[code_point * m_glyph_height], { glyph_width(code_point), m_glyph_height });
|
||||||
}
|
}
|
||||||
|
|
||||||
int Font::glyph_or_emoji_width(u32 codepoint) const
|
int Font::glyph_or_emoji_width(u32 code_point) const
|
||||||
{
|
{
|
||||||
if (codepoint < m_glyph_count)
|
if (code_point < m_glyph_count)
|
||||||
return glyph_width(codepoint);
|
return glyph_width(code_point);
|
||||||
|
|
||||||
if (m_fixed_width)
|
if (m_fixed_width)
|
||||||
return m_glyph_width;
|
return m_glyph_width;
|
||||||
|
|
||||||
auto* emoji = Emoji::emoji_for_codepoint(codepoint);
|
auto* emoji = Emoji::emoji_for_code_point(code_point);
|
||||||
if (emoji == nullptr)
|
if (emoji == nullptr)
|
||||||
return glyph_width('?');
|
return glyph_width('?');
|
||||||
return emoji->size().width();
|
return emoji->size().width();
|
||||||
|
@ -285,11 +285,11 @@ int Font::width(const Utf8View& utf8) const
|
||||||
bool first = true;
|
bool first = true;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
|
||||||
for (u32 codepoint : utf8) {
|
for (u32 code_point : utf8) {
|
||||||
if (!first)
|
if (!first)
|
||||||
width += glyph_spacing();
|
width += glyph_spacing();
|
||||||
first = false;
|
first = false;
|
||||||
width += glyph_or_emoji_width(codepoint);
|
width += glyph_or_emoji_width(code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
|
@ -301,7 +301,7 @@ int Font::width(const Utf32View& view) const
|
||||||
return 0;
|
return 0;
|
||||||
int width = (view.length() - 1) * glyph_spacing();
|
int width = (view.length() - 1) * glyph_spacing();
|
||||||
for (size_t i = 0; i < view.length(); ++i)
|
for (size_t i = 0; i < view.length(); ++i)
|
||||||
width += glyph_or_emoji_width(view.codepoints()[i]);
|
width += glyph_or_emoji_width(view.code_points()[i]);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,10 @@ public:
|
||||||
|
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
GlyphBitmap glyph_bitmap(u32 codepoint) const;
|
GlyphBitmap glyph_bitmap(u32 code_point) const;
|
||||||
|
|
||||||
u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; }
|
u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; }
|
||||||
int glyph_or_emoji_width(u32 codepoint) const;
|
int glyph_or_emoji_width(u32 code_point) const;
|
||||||
u8 glyph_height() const { return m_glyph_height; }
|
u8 glyph_height() const { return m_glyph_height; }
|
||||||
u8 min_glyph_width() const { return m_min_glyph_width; }
|
u8 min_glyph_width() const { return m_min_glyph_width; }
|
||||||
u8 max_glyph_width() const { return m_max_glyph_width; }
|
u8 max_glyph_width() const { return m_max_glyph_width; }
|
||||||
|
|
|
@ -803,14 +803,14 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, Color color)
|
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, Color color)
|
||||||
{
|
{
|
||||||
draw_glyph(point, codepoint, font(), color);
|
draw_glyph(point, code_point, font(), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 codepoint, const Font& font, Color color)
|
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, const Font& font, Color color)
|
||||||
{
|
{
|
||||||
draw_bitmap(point, font.glyph_bitmap(codepoint), color);
|
draw_bitmap(point, font.glyph_bitmap(code_point), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const Font& font)
|
void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const Font& font)
|
||||||
|
@ -828,19 +828,19 @@ void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 codepoint, const Font& font, Color color)
|
void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 code_point, const Font& font, Color color)
|
||||||
{
|
{
|
||||||
if (codepoint < (u32)font.glyph_count()) {
|
if (code_point < (u32)font.glyph_count()) {
|
||||||
// This looks like a regular character.
|
// This looks like a regular character.
|
||||||
draw_glyph(point, (size_t)codepoint, font, color);
|
draw_glyph(point, (size_t)code_point, font, color);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perhaps it's an emoji?
|
// Perhaps it's an emoji?
|
||||||
auto* emoji = Emoji::emoji_for_codepoint(codepoint);
|
auto* emoji = Emoji::emoji_for_code_point(code_point);
|
||||||
if (emoji == nullptr) {
|
if (emoji == nullptr) {
|
||||||
#ifdef EMOJI_DEBUG
|
#ifdef EMOJI_DEBUG
|
||||||
dbg() << "Failed to find an emoji for codepoint " << codepoint;
|
dbg() << "Failed to find an emoji for code_point " << code_point;
|
||||||
#endif
|
#endif
|
||||||
draw_glyph(point, '?', font, color);
|
draw_glyph(point, '?', font, color);
|
||||||
return;
|
return;
|
||||||
|
@ -862,8 +862,8 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf8View& text, const
|
||||||
int new_width = font.width("...");
|
int new_width = font.width("...");
|
||||||
if (new_width < text_width) {
|
if (new_width < text_width) {
|
||||||
for (auto it = final_text.begin(); it != final_text.end(); ++it) {
|
for (auto it = final_text.begin(); it != final_text.end(); ++it) {
|
||||||
u32 codepoint = *it;
|
u32 code_point = *it;
|
||||||
int glyph_width = font.glyph_or_emoji_width(codepoint);
|
int glyph_width = font.glyph_or_emoji_width(code_point);
|
||||||
// NOTE: Glyph spacing should not be added after the last glyph on the line,
|
// 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,
|
// but since we are here because the last glyph does not actually fit on the line,
|
||||||
// we don't have to worry about spacing.
|
// 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();
|
auto point = rect.location();
|
||||||
int space_width = font.glyph_width(' ') + font.glyph_spacing();
|
int space_width = font.glyph_width(' ') + font.glyph_spacing();
|
||||||
|
|
||||||
for (u32 codepoint : final_text) {
|
for (u32 code_point : final_text) {
|
||||||
if (codepoint == ' ') {
|
if (code_point == ' ') {
|
||||||
point.move_by(space_width, 0);
|
point.move_by(space_width, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
draw_glyph_or_emoji(point, codepoint, font, color);
|
draw_glyph_or_emoji(point, code_point, font, color);
|
||||||
point.move_by(font.glyph_or_emoji_width(codepoint) + font.glyph_spacing(), 0);
|
point.move_by(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -927,8 +927,8 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf32View& text, const
|
||||||
if (new_width < text_width) {
|
if (new_width < text_width) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; i < text.length(); ++i) {
|
for (; i < text.length(); ++i) {
|
||||||
u32 codepoint = text.codepoints()[i];
|
u32 code_point = text.code_points()[i];
|
||||||
int glyph_width = font.glyph_or_emoji_width(codepoint);
|
int glyph_width = font.glyph_or_emoji_width(code_point);
|
||||||
// NOTE: Glyph spacing should not be added after the last glyph on the line,
|
// 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,
|
// but since we are here because the last glyph does not actually fit on the line,
|
||||||
// we don't have to worry about spacing.
|
// 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;
|
new_width += glyph_width + glyph_spacing;
|
||||||
}
|
}
|
||||||
elided_text.clear();
|
elided_text.clear();
|
||||||
elided_text.append(final_text.codepoints(), i);
|
elided_text.append(final_text.code_points(), i);
|
||||||
elided_text.append('.');
|
elided_text.append('.');
|
||||||
elided_text.append('.');
|
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();
|
int space_width = font.glyph_width(' ') + font.glyph_spacing();
|
||||||
|
|
||||||
for (size_t i = 0; i < final_text.length(); ++i) {
|
for (size_t i = 0; i < final_text.length(); ++i) {
|
||||||
auto codepoint = final_text.codepoints()[i];
|
auto code_point = final_text.code_points()[i];
|
||||||
if (codepoint == ' ') {
|
if (code_point == ' ') {
|
||||||
point.move_by(space_width, 0);
|
point.move_by(space_width, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
draw_glyph_or_emoji(point, codepoint, font, color);
|
draw_glyph_or_emoji(point, code_point, font, color);
|
||||||
point.move_by(font.glyph_or_emoji_width(codepoint) + font.glyph_spacing(), 0);
|
point.move_by(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,8 +997,8 @@ void Painter::draw_text(const IntRect& rect, const StringView& raw_text, const F
|
||||||
|
|
||||||
int start_of_current_line = 0;
|
int start_of_current_line = 0;
|
||||||
for (auto it = text.begin(); it != text.end(); ++it) {
|
for (auto it = text.begin(); it != text.end(); ++it) {
|
||||||
u32 codepoint = *it;
|
u32 code_point = *it;
|
||||||
if (codepoint == '\n') {
|
if (code_point == '\n') {
|
||||||
int byte_offset = text.byte_offset_of(it);
|
int byte_offset = text.byte_offset_of(it);
|
||||||
Utf8View line = text.substring_view(start_of_current_line, byte_offset - start_of_current_line);
|
Utf8View line = text.substring_view(start_of_current_line, byte_offset - start_of_current_line);
|
||||||
lines.append(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;
|
size_t start_of_current_line = 0;
|
||||||
for (size_t i = 0; i < text.length(); ++i) {
|
for (size_t i = 0; i < text.length(); ++i) {
|
||||||
u32 codepoint = text.codepoints()[i];
|
u32 code_point = text.code_points()[i];
|
||||||
if (codepoint == '\n') {
|
if (code_point == '\n') {
|
||||||
Utf32View line = text.substring_view(start_of_current_line, i - start_of_current_line);
|
Utf32View line = text.substring_view(start_of_current_line, i - start_of_current_line);
|
||||||
lines.append(line);
|
lines.append(line);
|
||||||
start_of_current_line = i + 1;
|
start_of_current_line = i + 1;
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
void draw_glyph(const IntPoint&, u32, Color);
|
void draw_glyph(const IntPoint&, u32, Color);
|
||||||
void draw_glyph(const IntPoint&, u32, const Font&, Color);
|
void draw_glyph(const IntPoint&, u32, const Font&, Color);
|
||||||
void draw_emoji(const IntPoint&, const Gfx::Bitmap&, const Font&);
|
void draw_emoji(const IntPoint&, const Gfx::Bitmap&, const Font&);
|
||||||
void draw_glyph_or_emoji(const IntPoint&, u32 codepoint, const Font&, Color);
|
void draw_glyph_or_emoji(const IntPoint&, u32 code_point, const Font&, Color);
|
||||||
|
|
||||||
static void for_each_line_segment_on_bezier_curve(const FloatPoint& control_point, const FloatPoint& p1, const FloatPoint& p2, Function<void(const FloatPoint&, const FloatPoint&)>&);
|
static void for_each_line_segment_on_bezier_curve(const FloatPoint& control_point, const FloatPoint& p1, const FloatPoint& p2, Function<void(const FloatPoint&, const FloatPoint&)>&);
|
||||||
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&)>&&);
|
||||||
|
|
|
@ -834,7 +834,7 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(Token token)
|
||||||
auto type = status == Token::StringValueStatus::MalformedUnicodeEscape ? "unicode" : "hexadecimal";
|
auto type = status == Token::StringValueStatus::MalformedUnicodeEscape ? "unicode" : "hexadecimal";
|
||||||
message = String::format("Malformed %s escape sequence", type);
|
message = String::format("Malformed %s escape sequence", type);
|
||||||
} else if (status == Token::StringValueStatus::UnicodeEscapeOverflow) {
|
} else if (status == Token::StringValueStatus::UnicodeEscapeOverflow) {
|
||||||
message = "Unicode codepoint must not be greater than 0x10ffff in escape sequence";
|
message = "Unicode code_point must not be greater than 0x10ffff in escape sequence";
|
||||||
}
|
}
|
||||||
|
|
||||||
syntax_error(
|
syntax_error(
|
||||||
|
|
|
@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next)
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append_codepoint(*utf8_iterator);
|
builder.append_code_point(*utf8_iterator);
|
||||||
++utf8_iterator;
|
++utf8_iterator;
|
||||||
|
|
||||||
return create_iterator_result_object(global_object, js_string(interpreter, builder.to_string()), false);
|
return create_iterator_result_object(global_object, js_string(interpreter, builder.to_string()), false);
|
||||||
|
|
|
@ -321,7 +321,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
|
||||||
if (interpreter.argument_count() == 0)
|
if (interpreter.argument_count() == 0)
|
||||||
return js_string(interpreter, string);
|
return js_string(interpreter, string);
|
||||||
|
|
||||||
// FIXME: index_start and index_end should index a UTF-16 codepoint view of the string.
|
// FIXME: index_start and index_end should index a UTF-16 code_point view of the string.
|
||||||
auto string_length = string.length();
|
auto string_length = string.length();
|
||||||
auto index_start = min(interpreter.argument(0).to_size_t(interpreter), string_length);
|
auto index_start = min(interpreter.argument(0).to_size_t(interpreter), string_length);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -358,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// FIXME: position should index a UTF-16 codepoint view of the string.
|
// FIXME: position should index a UTF-16 code_point view of the string.
|
||||||
size_t position = 0;
|
size_t position = 0;
|
||||||
if (interpreter.argument_count() >= 2) {
|
if (interpreter.argument_count() >= 2) {
|
||||||
position = interpreter.argument(1).to_size_t(interpreter);
|
position = interpreter.argument(1).to_size_t(interpreter);
|
||||||
|
@ -385,7 +385,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
||||||
if (interpreter.argument_count() == 0)
|
if (interpreter.argument_count() == 0)
|
||||||
return js_string(interpreter, string);
|
return js_string(interpreter, string);
|
||||||
|
|
||||||
// FIXME: index_start and index_end should index a UTF-16 codepoint view of the string.
|
// FIXME: index_start and index_end should index a UTF-16 code_point view of the string.
|
||||||
auto string_length = static_cast<i32>(string.length());
|
auto string_length = static_cast<i32>(string.length());
|
||||||
auto index_start = interpreter.argument(0).to_i32(interpreter);
|
auto index_start = interpreter.argument(0).to_i32(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -437,7 +437,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of)
|
||||||
auto max_index = string.length() - search_string.length();
|
auto max_index = string.length() - search_string.length();
|
||||||
auto from_index = max_index;
|
auto from_index = max_index;
|
||||||
if (interpreter.argument_count() >= 2) {
|
if (interpreter.argument_count() >= 2) {
|
||||||
// FIXME: from_index should index a UTF-16 codepoint view of the string.
|
// FIXME: from_index should index a UTF-16 code_point view of the string.
|
||||||
from_index = min(interpreter.argument(1).to_size_t(interpreter), max_index);
|
from_index = min(interpreter.argument(1).to_size_t(interpreter), max_index);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -917,10 +917,10 @@ TriState abstract_relation(Interpreter& interpreter, bool left_first, Value lhs,
|
||||||
if (y_string.starts_with(x_string))
|
if (y_string.starts_with(x_string))
|
||||||
return TriState::True;
|
return TriState::True;
|
||||||
|
|
||||||
Utf8View x_codepoints { x_string };
|
Utf8View x_code_points { x_string };
|
||||||
Utf8View y_codepoints { y_string };
|
Utf8View y_code_points { y_string };
|
||||||
for (auto k = x_codepoints.begin(), l = y_codepoints.begin();
|
for (auto k = x_code_points.begin(), l = y_code_points.begin();
|
||||||
k != x_codepoints.end() && l != y_codepoints.end();
|
k != x_code_points.end() && l != y_code_points.end();
|
||||||
++k, ++l) {
|
++k, ++l) {
|
||||||
if (*k != *l) {
|
if (*k != *l) {
|
||||||
if (*k < *l) {
|
if (*k < *l) {
|
||||||
|
|
|
@ -136,7 +136,7 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
auto digit2 = m_value[++i];
|
auto digit2 = m_value[++i];
|
||||||
if (!isxdigit(digit1) || !isxdigit(digit2))
|
if (!isxdigit(digit1) || !isxdigit(digit2))
|
||||||
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
||||||
builder.append_codepoint(hex2int(digit1) * 16 + hex2int(digit2));
|
builder.append_code_point(hex2int(digit1) * 16 + hex2int(digit2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'u': {
|
case 'u': {
|
||||||
|
@ -174,7 +174,7 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append_codepoint(code_point);
|
builder.append_code_point(code_point);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -97,7 +97,7 @@ void Editor::clear_line()
|
||||||
void Editor::insert(const Utf32View& string)
|
void Editor::insert(const Utf32View& string)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < string.length(); ++i)
|
for (size_t i = 0; i < string.length(); ++i)
|
||||||
insert(string.codepoints()[i]);
|
insert(string.code_points()[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::insert(const String& string)
|
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)));
|
m_key_callbacks.set(ch, make<KeyCallback>(move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t codepoint_length_in_utf8(u32 codepoint)
|
static size_t code_point_length_in_utf8(u32 code_point)
|
||||||
{
|
{
|
||||||
if (codepoint <= 0x7f)
|
if (code_point <= 0x7f)
|
||||||
return 1;
|
return 1;
|
||||||
if (codepoint <= 0x07ff)
|
if (code_point <= 0x07ff)
|
||||||
return 2;
|
return 2;
|
||||||
if (codepoint <= 0xffff)
|
if (code_point <= 0xffff)
|
||||||
return 3;
|
return 3;
|
||||||
if (codepoint <= 0x10ffff)
|
if (code_point <= 0x10ffff)
|
||||||
return 4;
|
return 4;
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
@ -156,20 +156,20 @@ static size_t codepoint_length_in_utf8(u32 codepoint)
|
||||||
// | | +- scan offset = M
|
// | | +- scan offset = M
|
||||||
// | +- range end = M - B
|
// | +- range end = M - B
|
||||||
// +- range start = M - A
|
// +- range start = M - A
|
||||||
// This method converts a byte range defined by [start_byte_offset, end_byte_offset] to a codepoint range [M - A, M - B] as shown in the diagram above.
|
// This method converts a byte range defined by [start_byte_offset, end_byte_offset] to a code_point range [M - A, M - B] as shown in the diagram above.
|
||||||
// If `reverse' is true, A and B are before M, if not, A and B are after M.
|
// If `reverse' is true, A and B are before M, if not, A and B are after M.
|
||||||
Editor::CodepointRange Editor::byte_offset_range_to_codepoint_offset_range(size_t start_byte_offset, size_t end_byte_offset, size_t scan_codepoint_offset, bool reverse) const
|
Editor::CodepointRange Editor::byte_offset_range_to_code_point_offset_range(size_t start_byte_offset, size_t end_byte_offset, size_t scan_code_point_offset, bool reverse) const
|
||||||
{
|
{
|
||||||
size_t byte_offset = 0;
|
size_t byte_offset = 0;
|
||||||
size_t codepoint_offset = scan_codepoint_offset + (reverse ? 1 : 0);
|
size_t code_point_offset = scan_code_point_offset + (reverse ? 1 : 0);
|
||||||
CodepointRange range;
|
CodepointRange range;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!reverse) {
|
if (!reverse) {
|
||||||
if (codepoint_offset >= m_buffer.size())
|
if (code_point_offset >= m_buffer.size())
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (codepoint_offset == 0)
|
if (code_point_offset == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ Editor::CodepointRange Editor::byte_offset_range_to_codepoint_offset_range(size_
|
||||||
if (byte_offset < end_byte_offset)
|
if (byte_offset < end_byte_offset)
|
||||||
++range.end;
|
++range.end;
|
||||||
|
|
||||||
byte_offset += codepoint_length_in_utf8(m_buffer[reverse ? --codepoint_offset : codepoint_offset++]);
|
byte_offset += code_point_length_in_utf8(m_buffer[reverse ? --code_point_offset : code_point_offset++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return range;
|
return range;
|
||||||
|
@ -197,7 +197,7 @@ void Editor::stylize(const Span& span, const Style& style)
|
||||||
auto end = span.end();
|
auto end = span.end();
|
||||||
|
|
||||||
if (span.mode() == Span::ByteOriented) {
|
if (span.mode() == Span::ByteOriented) {
|
||||||
auto offsets = byte_offset_range_to_codepoint_offset_range(start, end, 0);
|
auto offsets = byte_offset_range_to_code_point_offset_range(start, end, 0);
|
||||||
|
|
||||||
start = offsets.start;
|
start = offsets.start;
|
||||||
end = offsets.end;
|
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) {
|
if (offset_mode == Span::Mode::ByteOriented) {
|
||||||
// FIXME: We're assuming that invariant_offset points to the end of the available data
|
// 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.
|
// this is not necessarily true, but is true in most cases.
|
||||||
auto offsets = byte_offset_range_to_codepoint_offset_range(internal_static_offset, internal_invariant_offset + internal_static_offset, m_cursor - 1, true);
|
auto offsets = byte_offset_range_to_code_point_offset_range(internal_static_offset, internal_invariant_offset + internal_static_offset, m_cursor - 1, true);
|
||||||
|
|
||||||
internal_static_offset = offsets.start;
|
internal_static_offset = offsets.start;
|
||||||
internal_invariant_offset = offsets.end - 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 } };
|
Utf8View input_view { StringView { m_incomplete_data.data(), valid_bytes } };
|
||||||
size_t consumed_codepoints = 0;
|
size_t consumed_code_points = 0;
|
||||||
|
|
||||||
enum Amount {
|
enum Amount {
|
||||||
Character,
|
Character,
|
||||||
|
@ -552,18 +552,18 @@ void Editor::handle_read_event()
|
||||||
m_refresh_needed = true;
|
m_refresh_needed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto codepoint : input_view) {
|
for (auto code_point : input_view) {
|
||||||
if (m_finish)
|
if (m_finish)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
++consumed_codepoints;
|
++consumed_code_points;
|
||||||
|
|
||||||
if (codepoint == 0)
|
if (code_point == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case InputState::ExpectBracket:
|
case InputState::ExpectBracket:
|
||||||
if (codepoint == '[') {
|
if (code_point == '[') {
|
||||||
m_state = InputState::ExpectFinal;
|
m_state = InputState::ExpectFinal;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -571,7 +571,7 @@ void Editor::handle_read_event()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case InputState::ExpectFinal:
|
case InputState::ExpectFinal:
|
||||||
switch (codepoint) {
|
switch (code_point) {
|
||||||
case 'O': // mod_ctrl
|
case 'O': // mod_ctrl
|
||||||
ctrl_held = true;
|
ctrl_held = true;
|
||||||
continue;
|
continue;
|
||||||
|
@ -621,7 +621,7 @@ void Editor::handle_read_event()
|
||||||
ctrl_held = false;
|
ctrl_held = false;
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
dbgprintf("LibLine: Unhandled final: %02x (%c)\r\n", codepoint, codepoint);
|
dbgprintf("LibLine: Unhandled final: %02x (%c)\r\n", code_point, code_point);
|
||||||
m_state = InputState::Free;
|
m_state = InputState::Free;
|
||||||
ctrl_held = false;
|
ctrl_held = false;
|
||||||
continue;
|
continue;
|
||||||
|
@ -631,14 +631,14 @@ void Editor::handle_read_event()
|
||||||
m_state = InputState::Free;
|
m_state = InputState::Free;
|
||||||
continue;
|
continue;
|
||||||
case InputState::Free:
|
case InputState::Free:
|
||||||
if (codepoint == 27) {
|
if (code_point == 27) {
|
||||||
m_state = InputState::ExpectBracket;
|
m_state = InputState::ExpectBracket;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cb = m_key_callbacks.get(codepoint);
|
auto cb = m_key_callbacks.get(code_point);
|
||||||
if (cb.has_value()) {
|
if (cb.has_value()) {
|
||||||
if (!cb.value()->callback(*this)) {
|
if (!cb.value()->callback(*this)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -646,19 +646,19 @@ void Editor::handle_read_event()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ^N
|
// ^N
|
||||||
if (codepoint == ctrl('N')) {
|
if (code_point == ctrl('N')) {
|
||||||
do_search_forwards();
|
do_search_forwards();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^P
|
// ^P
|
||||||
if (codepoint == ctrl('P')) {
|
if (code_point == ctrl('P')) {
|
||||||
do_search_backwards();
|
do_search_backwards();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_search_offset = 0; // reset search offset on any key
|
m_search_offset = 0; // reset search offset on any key
|
||||||
|
|
||||||
if (codepoint == '\t' || reverse_tab) {
|
if (code_point == '\t' || reverse_tab) {
|
||||||
if (!on_tab_complete)
|
if (!on_tab_complete)
|
||||||
continue;
|
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
|
m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB
|
||||||
|
|
||||||
if (codepoint == m_termios.c_cc[VWERASE]) {
|
if (code_point == m_termios.c_cc[VWERASE]) {
|
||||||
bool has_seen_nonspace = false;
|
bool has_seen_nonspace = false;
|
||||||
while (m_cursor > 0) {
|
while (m_cursor > 0) {
|
||||||
if (isspace(m_buffer[m_cursor - 1])) {
|
if (isspace(m_buffer[m_cursor - 1])) {
|
||||||
|
@ -786,7 +786,7 @@ void Editor::handle_read_event()
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (codepoint == m_termios.c_cc[VKILL]) {
|
if (code_point == m_termios.c_cc[VKILL]) {
|
||||||
for (size_t i = 0; i < m_cursor; ++i)
|
for (size_t i = 0; i < m_cursor; ++i)
|
||||||
remove_at_index(0);
|
remove_at_index(0);
|
||||||
m_cursor = 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.
|
// 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.
|
// Handle it before ctrl shortcuts below and only continue if the buffer is empty, so that the editing shortcuts can take effect else.
|
||||||
if (codepoint == m_termios.c_cc[VEOF] && m_buffer.is_empty()) {
|
if (code_point == m_termios.c_cc[VEOF] && m_buffer.is_empty()) {
|
||||||
printf("<EOF>\n");
|
printf("<EOF>\n");
|
||||||
if (!m_always_refresh) {
|
if (!m_always_refresh) {
|
||||||
m_input_error = Error::Eof;
|
m_input_error = Error::Eof;
|
||||||
|
@ -804,37 +804,37 @@ void Editor::handle_read_event()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^A
|
// ^A
|
||||||
if (codepoint == ctrl('A')) {
|
if (code_point == ctrl('A')) {
|
||||||
m_cursor = 0;
|
m_cursor = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^B
|
// ^B
|
||||||
if (codepoint == ctrl('B')) {
|
if (code_point == ctrl('B')) {
|
||||||
do_cursor_left(Character);
|
do_cursor_left(Character);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^D
|
// ^D
|
||||||
if (codepoint == ctrl('D')) {
|
if (code_point == ctrl('D')) {
|
||||||
do_delete();
|
do_delete();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^E
|
// ^E
|
||||||
if (codepoint == ctrl('E')) {
|
if (code_point == ctrl('E')) {
|
||||||
m_cursor = m_buffer.size();
|
m_cursor = m_buffer.size();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^F
|
// ^F
|
||||||
if (codepoint == ctrl('F')) {
|
if (code_point == ctrl('F')) {
|
||||||
do_cursor_right(Character);
|
do_cursor_right(Character);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^H: ctrl('H') == '\b'
|
// ^H: ctrl('H') == '\b'
|
||||||
if (codepoint == '\b' || codepoint == m_termios.c_cc[VERASE]) {
|
if (code_point == '\b' || code_point == m_termios.c_cc[VERASE]) {
|
||||||
do_backspace();
|
do_backspace();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^L
|
// ^L
|
||||||
if (codepoint == ctrl('L')) {
|
if (code_point == ctrl('L')) {
|
||||||
printf("\033[3J\033[H\033[2J"); // Clear screen.
|
printf("\033[3J\033[H\033[2J"); // Clear screen.
|
||||||
VT::move_absolute(1, 1);
|
VT::move_absolute(1, 1);
|
||||||
set_origin(1, 1);
|
set_origin(1, 1);
|
||||||
|
@ -842,7 +842,7 @@ void Editor::handle_read_event()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^R
|
// ^R
|
||||||
if (codepoint == ctrl('R')) {
|
if (code_point == ctrl('R')) {
|
||||||
if (m_is_searching) {
|
if (m_is_searching) {
|
||||||
// how did we get here?
|
// how did we get here?
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
@ -850,8 +850,8 @@ void Editor::handle_read_event()
|
||||||
m_is_searching = true;
|
m_is_searching = true;
|
||||||
m_search_offset = 0;
|
m_search_offset = 0;
|
||||||
m_pre_search_buffer.clear();
|
m_pre_search_buffer.clear();
|
||||||
for (auto codepoint : m_buffer)
|
for (auto code_point : m_buffer)
|
||||||
m_pre_search_buffer.append(codepoint);
|
m_pre_search_buffer.append(code_point);
|
||||||
m_pre_search_cursor = m_cursor;
|
m_pre_search_cursor = m_cursor;
|
||||||
|
|
||||||
// Disable our own notifier so as to avoid interfering with the search editor.
|
// Disable our own notifier so as to avoid interfering with the search editor.
|
||||||
|
@ -958,7 +958,7 @@ void Editor::handle_read_event()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ^T
|
// ^T
|
||||||
if (codepoint == ctrl('T')) {
|
if (code_point == ctrl('T')) {
|
||||||
if (m_cursor > 0 && m_buffer.size() >= 2) {
|
if (m_cursor > 0 && m_buffer.size() >= 2) {
|
||||||
if (m_cursor < m_buffer.size())
|
if (m_cursor < m_buffer.size())
|
||||||
++m_cursor;
|
++m_cursor;
|
||||||
|
@ -968,18 +968,18 @@ void Editor::handle_read_event()
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (codepoint == '\n') {
|
if (code_point == '\n') {
|
||||||
finish();
|
finish();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
insert(codepoint);
|
insert(code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consumed_codepoints == m_incomplete_data.size()) {
|
if (consumed_code_points == m_incomplete_data.size()) {
|
||||||
m_incomplete_data.clear();
|
m_incomplete_data.clear();
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < consumed_codepoints; ++i)
|
for (size_t i = 0; i < consumed_code_points; ++i)
|
||||||
m_incomplete_data.take_first();
|
m_incomplete_data.take_first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1425,8 +1425,8 @@ StringMetrics Editor::actual_rendered_string_metrics(const Utf32View& view) cons
|
||||||
VTState state { Free };
|
VTState state { Free };
|
||||||
|
|
||||||
for (size_t i = 0; i < view.length(); ++i) {
|
for (size_t i = 0; i < view.length(); ++i) {
|
||||||
auto c = view.codepoints()[i];
|
auto c = view.code_points()[i];
|
||||||
auto next_c = i + 1 < view.length() ? view.codepoints()[i + 1] : 0;
|
auto next_c = i + 1 < view.length() ? view.code_points()[i + 1] : 0;
|
||||||
state = actual_rendered_string_length_step(metrics, length, c, next_c, state);
|
state = actual_rendered_string_length_step(metrics, length, c, next_c, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -310,7 +310,7 @@ private:
|
||||||
size_t start { 0 };
|
size_t start { 0 };
|
||||||
size_t end { 0 };
|
size_t end { 0 };
|
||||||
};
|
};
|
||||||
CodepointRange byte_offset_range_to_codepoint_offset_range(size_t byte_start, size_t byte_end, size_t codepoint_scan_offset, bool reverse = false) const;
|
CodepointRange byte_offset_range_to_code_point_offset_range(size_t byte_start, size_t byte_end, size_t code_point_scan_offset, bool reverse = false) const;
|
||||||
|
|
||||||
void get_terminal_size();
|
void get_terminal_size();
|
||||||
|
|
||||||
|
|
|
@ -59,16 +59,16 @@ void SuggestionManager::set_suggestions(Vector<CompletionSuggestion>&& suggestio
|
||||||
if (m_suggestions.size() == 1) {
|
if (m_suggestions.size() == 1) {
|
||||||
m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length();
|
m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length();
|
||||||
} else if (m_suggestions.size()) {
|
} else if (m_suggestions.size()) {
|
||||||
u32 last_valid_suggestion_codepoint;
|
u32 last_valid_suggestion_code_point;
|
||||||
|
|
||||||
for (;; ++common_suggestion_prefix) {
|
for (;; ++common_suggestion_prefix) {
|
||||||
if (m_suggestions[0].text_view.length() <= common_suggestion_prefix)
|
if (m_suggestions[0].text_view.length() <= common_suggestion_prefix)
|
||||||
goto no_more_commons;
|
goto no_more_commons;
|
||||||
|
|
||||||
last_valid_suggestion_codepoint = m_suggestions[0].text_view.codepoints()[common_suggestion_prefix];
|
last_valid_suggestion_code_point = m_suggestions[0].text_view.code_points()[common_suggestion_prefix];
|
||||||
|
|
||||||
for (auto& suggestion : m_suggestions) {
|
for (auto& suggestion : m_suggestions) {
|
||||||
if (suggestion.text_view.length() <= common_suggestion_prefix || suggestion.text_view.codepoints()[common_suggestion_prefix] != last_valid_suggestion_codepoint) {
|
if (suggestion.text_view.length() <= common_suggestion_prefix || suggestion.text_view.code_points()[common_suggestion_prefix] != last_valid_suggestion_code_point) {
|
||||||
goto no_more_commons;
|
goto no_more_commons;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,8 @@ String Latin1Decoder::to_utf8(const StringView& input)
|
||||||
StringBuilder builder(input.length());
|
StringBuilder builder(input.length());
|
||||||
for (size_t i = 0; i < input.length(); ++i) {
|
for (size_t i = 0; i < input.length(); ++i) {
|
||||||
u8 ch = input[i];
|
u8 ch = input[i];
|
||||||
// Latin1 is the same as the first 256 Unicode codepoints, so no mapping is needed, just utf-8 encoding.
|
// Latin1 is the same as the first 256 Unicode code_points, so no mapping is needed, just utf-8 encoding.
|
||||||
builder.append_codepoint(ch);
|
builder.append_code_point(ch);
|
||||||
}
|
}
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,25 +37,25 @@ Line::Line(u16 length)
|
||||||
Line::~Line()
|
Line::~Line()
|
||||||
{
|
{
|
||||||
if (m_utf32)
|
if (m_utf32)
|
||||||
delete[] m_codepoints.as_u32;
|
delete[] m_code_points.as_u32;
|
||||||
else
|
else
|
||||||
delete[] m_codepoints.as_u8;
|
delete[] m_code_points.as_u8;
|
||||||
delete[] m_attributes;
|
delete[] m_attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CodepointType>
|
template<typename CodepointType>
|
||||||
static CodepointType* create_new_codepoint_array(size_t new_length, const CodepointType* old_codepoints, size_t old_length)
|
static CodepointType* create_new_code_point_array(size_t new_length, const CodepointType* old_code_points, size_t old_length)
|
||||||
{
|
{
|
||||||
auto* new_codepoints = new CodepointType[new_length];
|
auto* new_code_points = new CodepointType[new_length];
|
||||||
for (size_t i = 0; i < new_length; ++i)
|
for (size_t i = 0; i < new_length; ++i)
|
||||||
new_codepoints[i] = ' ';
|
new_code_points[i] = ' ';
|
||||||
if (old_codepoints) {
|
if (old_code_points) {
|
||||||
for (size_t i = 0; i < min(old_length, new_length); ++i) {
|
for (size_t i = 0; i < min(old_length, new_length); ++i) {
|
||||||
new_codepoints[i] = old_codepoints[i];
|
new_code_points[i] = old_code_points[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] old_codepoints;
|
delete[] old_code_points;
|
||||||
return new_codepoints;
|
return new_code_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Line::set_length(u16 new_length)
|
void Line::set_length(u16 new_length)
|
||||||
|
@ -64,9 +64,9 @@ void Line::set_length(u16 new_length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_utf32)
|
if (m_utf32)
|
||||||
m_codepoints.as_u32 = create_new_codepoint_array<u32>(new_length, m_codepoints.as_u32, m_length);
|
m_code_points.as_u32 = create_new_code_point_array<u32>(new_length, m_code_points.as_u32, m_length);
|
||||||
else
|
else
|
||||||
m_codepoints.as_u8 = create_new_codepoint_array<u8>(new_length, m_codepoints.as_u8, m_length);
|
m_code_points.as_u8 = create_new_code_point_array<u8>(new_length, m_code_points.as_u8, m_length);
|
||||||
|
|
||||||
auto* new_attributes = new Attribute[new_length];
|
auto* new_attributes = new Attribute[new_length];
|
||||||
if (m_attributes) {
|
if (m_attributes) {
|
||||||
|
@ -82,15 +82,15 @@ void Line::clear(Attribute attribute)
|
||||||
{
|
{
|
||||||
if (m_dirty) {
|
if (m_dirty) {
|
||||||
for (u16 i = 0; i < m_length; ++i) {
|
for (u16 i = 0; i < m_length; ++i) {
|
||||||
set_codepoint(i, ' ');
|
set_code_point(i, ' ');
|
||||||
m_attributes[i] = attribute;
|
m_attributes[i] = attribute;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i < m_length; ++i) {
|
for (unsigned i = 0; i < m_length; ++i) {
|
||||||
if (codepoint(i) != ' ')
|
if (code_point(i) != ' ')
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
set_codepoint(i, ' ');
|
set_code_point(i, ' ');
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i < m_length; ++i) {
|
for (unsigned i = 0; i < m_length; ++i) {
|
||||||
if (m_attributes[i] != attribute)
|
if (m_attributes[i] != attribute)
|
||||||
|
@ -115,12 +115,12 @@ bool Line::has_only_one_background_color() const
|
||||||
void Line::convert_to_utf32()
|
void Line::convert_to_utf32()
|
||||||
{
|
{
|
||||||
ASSERT(!m_utf32);
|
ASSERT(!m_utf32);
|
||||||
auto* new_codepoints = new u32[m_length];
|
auto* new_code_points = new u32[m_length];
|
||||||
for (size_t i = 0; i < m_length; ++i) {
|
for (size_t i = 0; i < m_length; ++i) {
|
||||||
new_codepoints[i] = m_codepoints.as_u8[i];
|
new_code_points[i] = m_code_points.as_u8[i];
|
||||||
}
|
}
|
||||||
delete m_codepoints.as_u8;
|
delete m_code_points.as_u8;
|
||||||
m_codepoints.as_u32 = new_codepoints;
|
m_code_points.as_u32 = new_code_points;
|
||||||
m_utf32 = true;
|
m_utf32 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,22 +90,22 @@ public:
|
||||||
|
|
||||||
u16 length() const { return m_length; }
|
u16 length() const { return m_length; }
|
||||||
|
|
||||||
u32 codepoint(size_t index) const
|
u32 code_point(size_t index) const
|
||||||
{
|
{
|
||||||
if (m_utf32)
|
if (m_utf32)
|
||||||
return m_codepoints.as_u32[index];
|
return m_code_points.as_u32[index];
|
||||||
return m_codepoints.as_u8[index];
|
return m_code_points.as_u8[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_codepoint(size_t index, u32 codepoint)
|
void set_code_point(size_t index, u32 code_point)
|
||||||
{
|
{
|
||||||
if (!m_utf32 && codepoint & 0xffffff80u)
|
if (!m_utf32 && code_point & 0xffffff80u)
|
||||||
convert_to_utf32();
|
convert_to_utf32();
|
||||||
|
|
||||||
if (m_utf32)
|
if (m_utf32)
|
||||||
m_codepoints.as_u32[index] = codepoint;
|
m_code_points.as_u32[index] = code_point;
|
||||||
else
|
else
|
||||||
m_codepoints.as_u8[index] = codepoint;
|
m_code_points.as_u8[index] = code_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_dirty() const { return m_dirty; }
|
bool is_dirty() const { return m_dirty; }
|
||||||
|
@ -122,7 +122,7 @@ private:
|
||||||
union {
|
union {
|
||||||
u8* as_u8;
|
u8* as_u8;
|
||||||
u32* as_u32;
|
u32* as_u32;
|
||||||
} m_codepoints { nullptr };
|
} m_code_points { nullptr };
|
||||||
Attribute* m_attributes { nullptr };
|
Attribute* m_attributes { nullptr };
|
||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
bool m_utf32 { false };
|
bool m_utf32 { false };
|
||||||
|
|
|
@ -361,7 +361,7 @@ void Terminal::escape$b(const ParamVector& params)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (unsigned i = 0; i < params[0]; ++i)
|
for (unsigned i = 0; i < params[0]; ++i)
|
||||||
put_character_at(m_cursor_row, m_cursor_column++, m_last_codepoint);
|
put_character_at(m_cursor_row, m_cursor_column++, m_last_code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::escape$d(const ParamVector& params)
|
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
|
// Move n characters of line to the left
|
||||||
for (int i = m_cursor_column; i < line.length() - num; i++)
|
for (int i = m_cursor_column; i < line.length() - num; i++)
|
||||||
line.set_codepoint(i, line.codepoint(i + num));
|
line.set_code_point(i, line.code_point(i + num));
|
||||||
|
|
||||||
// Fill remainder of line with blanks
|
// Fill remainder of line with blanks
|
||||||
for (int i = line.length() - num; i < line.length(); i++)
|
for (int i = line.length() - num; i < line.length(); i++)
|
||||||
line.set_codepoint(i, ' ');
|
line.set_code_point(i, ' ');
|
||||||
|
|
||||||
line.set_dirty(true);
|
line.set_dirty(true);
|
||||||
}
|
}
|
||||||
|
@ -768,17 +768,17 @@ void Terminal::set_cursor(unsigned a_row, unsigned a_column)
|
||||||
invalidate_cursor();
|
invalidate_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::put_character_at(unsigned row, unsigned column, u32 codepoint)
|
void Terminal::put_character_at(unsigned row, unsigned column, u32 code_point)
|
||||||
{
|
{
|
||||||
ASSERT(row < rows());
|
ASSERT(row < rows());
|
||||||
ASSERT(column < columns());
|
ASSERT(column < columns());
|
||||||
auto& line = m_lines[row];
|
auto& line = m_lines[row];
|
||||||
line.set_codepoint(column, codepoint);
|
line.set_code_point(column, code_point);
|
||||||
line.attributes()[column] = m_current_attribute;
|
line.attributes()[column] = m_current_attribute;
|
||||||
line.attributes()[column].flags |= Attribute::Touched;
|
line.attributes()[column].flags |= Attribute::Touched;
|
||||||
line.set_dirty(true);
|
line.set_dirty(true);
|
||||||
|
|
||||||
m_last_codepoint = codepoint;
|
m_last_code_point = code_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::NEL()
|
void Terminal::NEL()
|
||||||
|
@ -820,14 +820,14 @@ void Terminal::on_input(u8 ch)
|
||||||
|
|
||||||
auto fail_utf8_parse = [this] {
|
auto fail_utf8_parse = [this] {
|
||||||
m_parser_state = Normal;
|
m_parser_state = Normal;
|
||||||
on_codepoint('%');
|
on_code_point('%');
|
||||||
};
|
};
|
||||||
|
|
||||||
auto advance_utf8_parse = [this, ch] {
|
auto advance_utf8_parse = [this, ch] {
|
||||||
m_parser_codepoint <<= 6;
|
m_parser_code_point <<= 6;
|
||||||
m_parser_codepoint |= ch & 0x3f;
|
m_parser_code_point |= ch & 0x3f;
|
||||||
if (m_parser_state == UTF8Needs1Byte) {
|
if (m_parser_state == UTF8Needs1Byte) {
|
||||||
on_codepoint(m_parser_codepoint);
|
on_code_point(m_parser_code_point);
|
||||||
m_parser_state = Normal;
|
m_parser_state = Normal;
|
||||||
} else {
|
} else {
|
||||||
m_parser_state = (ParserState)(m_parser_state + 1);
|
m_parser_state = (ParserState)(m_parser_state + 1);
|
||||||
|
@ -928,17 +928,17 @@ void Terminal::on_input(u8 ch)
|
||||||
break;
|
break;
|
||||||
if ((ch & 0xe0) == 0xc0) {
|
if ((ch & 0xe0) == 0xc0) {
|
||||||
m_parser_state = UTF8Needs1Byte;
|
m_parser_state = UTF8Needs1Byte;
|
||||||
m_parser_codepoint = ch & 0x1f;
|
m_parser_code_point = ch & 0x1f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((ch & 0xf0) == 0xe0) {
|
if ((ch & 0xf0) == 0xe0) {
|
||||||
m_parser_state = UTF8Needs2Bytes;
|
m_parser_state = UTF8Needs2Bytes;
|
||||||
m_parser_codepoint = ch & 0x0f;
|
m_parser_code_point = ch & 0x0f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((ch & 0xf8) == 0xf0) {
|
if ((ch & 0xf8) == 0xf0) {
|
||||||
m_parser_state = UTF8Needs3Bytes;
|
m_parser_state = UTF8Needs3Bytes;
|
||||||
m_parser_codepoint = ch & 0x07;
|
m_parser_code_point = ch & 0x07;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fail_utf8_parse();
|
fail_utf8_parse();
|
||||||
|
@ -978,26 +978,26 @@ void Terminal::on_input(u8 ch)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
on_codepoint(ch);
|
on_code_point(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::on_codepoint(u32 codepoint)
|
void Terminal::on_code_point(u32 code_point)
|
||||||
{
|
{
|
||||||
auto new_column = m_cursor_column + 1;
|
auto new_column = m_cursor_column + 1;
|
||||||
if (new_column < columns()) {
|
if (new_column < columns()) {
|
||||||
put_character_at(m_cursor_row, m_cursor_column, codepoint);
|
put_character_at(m_cursor_row, m_cursor_column, code_point);
|
||||||
set_cursor(m_cursor_row, new_column);
|
set_cursor(m_cursor_row, new_column);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_stomp) {
|
if (m_stomp) {
|
||||||
m_stomp = false;
|
m_stomp = false;
|
||||||
newline();
|
newline();
|
||||||
put_character_at(m_cursor_row, m_cursor_column, codepoint);
|
put_character_at(m_cursor_row, m_cursor_column, code_point);
|
||||||
set_cursor(m_cursor_row, 1);
|
set_cursor(m_cursor_row, 1);
|
||||||
} else {
|
} else {
|
||||||
// Curious: We wait once on the right-hand side
|
// Curious: We wait once on the right-hand side
|
||||||
m_stomp = true;
|
m_stomp = true;
|
||||||
put_character_at(m_cursor_row, m_cursor_column, codepoint);
|
put_character_at(m_cursor_row, m_cursor_column, code_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1078,7 +1078,7 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
|
||||||
emit_string("\033");
|
emit_string("\033");
|
||||||
|
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
sb.append_codepoint(code_point);
|
sb.append_code_point(code_point);
|
||||||
|
|
||||||
emit_string(sb.to_string());
|
emit_string(sb.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ public:
|
||||||
private:
|
private:
|
||||||
typedef Vector<unsigned, 4> ParamVector;
|
typedef Vector<unsigned, 4> ParamVector;
|
||||||
|
|
||||||
void on_codepoint(u32);
|
void on_code_point(u32);
|
||||||
|
|
||||||
void scroll_up();
|
void scroll_up();
|
||||||
void scroll_down();
|
void scroll_down();
|
||||||
|
@ -193,13 +193,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
ParserState m_parser_state { Normal };
|
ParserState m_parser_state { Normal };
|
||||||
u32 m_parser_codepoint { 0 };
|
u32 m_parser_code_point { 0 };
|
||||||
Vector<u8> m_parameters;
|
Vector<u8> m_parameters;
|
||||||
Vector<u8> m_intermediates;
|
Vector<u8> m_intermediates;
|
||||||
Vector<u8> m_xterm_parameters;
|
Vector<u8> m_xterm_parameters;
|
||||||
Vector<bool> m_horizontal_tabs;
|
Vector<bool> m_horizontal_tabs;
|
||||||
u8 m_final { 0 };
|
u8 m_final { 0 };
|
||||||
u32 m_last_codepoint { 0 };
|
u32 m_last_code_point { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
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) {
|
for (size_t column = 0; column < line.length(); ++column) {
|
||||||
u32 codepoint = line.codepoint(column);
|
u32 code_point = line.code_point(column);
|
||||||
bool should_reverse_fill_for_cursor_or_selection = m_cursor_blink_state
|
bool should_reverse_fill_for_cursor_or_selection = m_cursor_blink_state
|
||||||
&& m_has_logical_focus
|
&& m_has_logical_focus
|
||||||
&& visual_row == row_with_cursor
|
&& visual_row == row_with_cursor
|
||||||
|
@ -342,12 +342,12 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codepoint == ' ')
|
if (code_point == ' ')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
painter.draw_glyph_or_emoji(
|
painter.draw_glyph_or_emoji(
|
||||||
character_rect.location(),
|
character_rect.location(),
|
||||||
codepoint,
|
code_point,
|
||||||
attribute.flags & VT::Attribute::Bold ? bold_font() : font(),
|
attribute.flags & VT::Attribute::Bold ? bold_font() : font(),
|
||||||
text_color);
|
text_color);
|
||||||
}
|
}
|
||||||
|
@ -524,16 +524,16 @@ void TerminalWidget::doubleclick_event(GUI::MouseEvent& event)
|
||||||
|
|
||||||
auto position = buffer_position_at(event.position());
|
auto position = buffer_position_at(event.position());
|
||||||
auto& line = m_terminal.line(position.row());
|
auto& line = m_terminal.line(position.row());
|
||||||
bool want_whitespace = line.codepoint(position.column()) == ' ';
|
bool want_whitespace = line.code_point(position.column()) == ' ';
|
||||||
|
|
||||||
int start_column = 0;
|
int start_column = 0;
|
||||||
int end_column = 0;
|
int end_column = 0;
|
||||||
|
|
||||||
for (int column = position.column(); column >= 0 && (line.codepoint(column) == ' ') == want_whitespace; --column) {
|
for (int column = position.column(); column >= 0 && (line.code_point(column) == ' ') == want_whitespace; --column) {
|
||||||
start_column = column;
|
start_column = column;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int column = position.column(); column < m_terminal.columns() && (line.codepoint(column) == ' ') == want_whitespace; ++column) {
|
for (int column = position.column(); column < m_terminal.columns() && (line.code_point(column) == ' ') == want_whitespace; ++column) {
|
||||||
end_column = column;
|
end_column = column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,10 +715,10 @@ String TerminalWidget::selected_text() const
|
||||||
}
|
}
|
||||||
// FIXME: This is a bit hackish.
|
// FIXME: This is a bit hackish.
|
||||||
if (line.is_utf32()) {
|
if (line.is_utf32()) {
|
||||||
u32 codepoint = line.codepoint(column);
|
u32 code_point = line.code_point(column);
|
||||||
builder.append(Utf32View(&codepoint, 1));
|
builder.append(Utf32View(&code_point, 1));
|
||||||
} else {
|
} else {
|
||||||
builder.append(line.codepoint(column));
|
builder.append(line.code_point(column));
|
||||||
}
|
}
|
||||||
if (column == line.length() - 1 || (m_rectangle_selection && column == last_column)) {
|
if (column == line.length() - 1 || (m_rectangle_selection && column == last_column)) {
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
|
@ -272,10 +272,10 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
||||||
|
|
||||||
Vector<u8> byte_string;
|
Vector<u8> byte_string;
|
||||||
byte_string.ensure_capacity(string.length());
|
byte_string.ensure_capacity(string.length());
|
||||||
for (u32 codepoint : Utf8View(string)) {
|
for (u32 code_point : Utf8View(string)) {
|
||||||
if (codepoint > 0xff)
|
if (code_point > 0xff)
|
||||||
return interpreter.throw_exception<JS::InvalidCharacterError>(JS::ErrorType::NotAByteString, "btoa");
|
return interpreter.throw_exception<JS::InvalidCharacterError>(JS::ErrorType::NotAByteString, "btoa");
|
||||||
byte_string.append(codepoint);
|
byte_string.append(code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encoded = encode_base64(byte_string.span());
|
auto encoded = encode_base64(byte_string.span());
|
||||||
|
|
|
@ -31,12 +31,12 @@
|
||||||
namespace Web {
|
namespace Web {
|
||||||
namespace HTML {
|
namespace HTML {
|
||||||
|
|
||||||
Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
|
Optional<EntityMatch> code_points_from_entity(const StringView& entity)
|
||||||
{
|
{
|
||||||
constexpr struct {
|
constexpr struct {
|
||||||
StringView entity;
|
StringView entity;
|
||||||
u32 codepoint;
|
u32 code_point;
|
||||||
} single_codepoint_entities[] = {
|
} single_code_point_entities[] = {
|
||||||
{ "AElig;", 0x000C6 },
|
{ "AElig;", 0x000C6 },
|
||||||
{ "AElig", 0x000C6 },
|
{ "AElig", 0x000C6 },
|
||||||
{ "AMP;", 0x00026 },
|
{ "AMP;", 0x00026 },
|
||||||
|
@ -2179,9 +2179,9 @@ Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
|
||||||
|
|
||||||
constexpr struct {
|
constexpr struct {
|
||||||
StringView entity;
|
StringView entity;
|
||||||
u32 codepoint1;
|
u32 code_point1;
|
||||||
u32 codepoint2;
|
u32 code_point2;
|
||||||
} double_codepoint_entities[] = {
|
} double_code_point_entities[] = {
|
||||||
{ "NotEqualTilde;", 0x02242, 0x00338 },
|
{ "NotEqualTilde;", 0x02242, 0x00338 },
|
||||||
{ "NotGreaterFullEqual;", 0x02267, 0x00338 },
|
{ "NotGreaterFullEqual;", 0x02267, 0x00338 },
|
||||||
{ "NotGreaterGreater;", 0x0226B, 0x00338 },
|
{ "NotGreaterGreater;", 0x0226B, 0x00338 },
|
||||||
|
@ -2279,17 +2279,17 @@ Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
|
||||||
|
|
||||||
EntityMatch match;
|
EntityMatch match;
|
||||||
|
|
||||||
for (auto& single_codepoint_entity : single_codepoint_entities) {
|
for (auto& single_code_point_entity : single_code_point_entities) {
|
||||||
if (entity.starts_with(single_codepoint_entity.entity)) {
|
if (entity.starts_with(single_code_point_entity.entity)) {
|
||||||
if (match.entity.is_null() || single_codepoint_entity.entity.length() > match.entity.length())
|
if (match.entity.is_null() || single_code_point_entity.entity.length() > match.entity.length())
|
||||||
match = { { single_codepoint_entity.codepoint }, single_codepoint_entity.entity };
|
match = { { single_code_point_entity.code_point }, single_code_point_entity.entity };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& double_codepoint_entity : double_codepoint_entities) {
|
for (auto& double_code_point_entity : double_code_point_entities) {
|
||||||
if (entity.starts_with(double_codepoint_entity.entity)) {
|
if (entity.starts_with(double_code_point_entity.entity)) {
|
||||||
if (match.entity.is_null() || double_codepoint_entity.entity.length() > match.entity.length())
|
if (match.entity.is_null() || double_code_point_entity.entity.length() > match.entity.length())
|
||||||
match = EntityMatch { { double_codepoint_entity.codepoint1, double_codepoint_entity.codepoint2 }, StringView(double_codepoint_entity.entity) };
|
match = EntityMatch { { double_code_point_entity.code_point1, double_code_point_entity.code_point2 }, StringView(double_code_point_entity.entity) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ namespace Web {
|
||||||
namespace HTML {
|
namespace HTML {
|
||||||
|
|
||||||
struct EntityMatch {
|
struct EntityMatch {
|
||||||
Vector<u32, 2> codepoints;
|
Vector<u32, 2> code_points;
|
||||||
StringView entity;
|
StringView entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
Optional<EntityMatch> codepoints_from_entity(const StringView&);
|
Optional<EntityMatch> code_points_from_entity(const StringView&);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,7 +472,7 @@ void HTMLDocumentParser::insert_comment(HTMLToken& token)
|
||||||
void HTMLDocumentParser::handle_in_head(HTMLToken& token)
|
void HTMLDocumentParser::handle_in_head(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_parser_whitespace()) {
|
if (token.is_parser_whitespace()) {
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ void HTMLDocumentParser::insert_character(u32 data)
|
||||||
void HTMLDocumentParser::handle_after_head(HTMLToken& token)
|
void HTMLDocumentParser::handle_after_head(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character() && token.is_parser_whitespace()) {
|
if (token.is_character() && token.is_parser_whitespace()) {
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1004,17 +1004,17 @@ bool HTMLDocumentParser::is_special_tag(const FlyString& tag_name)
|
||||||
void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character()) {
|
if (token.is_character()) {
|
||||||
if (token.codepoint() == 0) {
|
if (token.code_point() == 0) {
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (token.is_parser_whitespace()) {
|
if (token.is_parser_whitespace()) {
|
||||||
reconstruct_the_active_formatting_elements();
|
reconstruct_the_active_formatting_elements();
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reconstruct_the_active_formatting_elements();
|
reconstruct_the_active_formatting_elements();
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
m_frameset_ok = false;
|
m_frameset_ok = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1162,7 +1162,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
||||||
// then ignore that token and move on to the next one.
|
// then ignore that token and move on to the next one.
|
||||||
// (Newlines at the start of pre blocks are ignored as an authoring convenience.)
|
// (Newlines at the start of pre blocks are ignored as an authoring convenience.)
|
||||||
auto next_token = m_tokenizer.next_token();
|
auto next_token = m_tokenizer.next_token();
|
||||||
if (next_token.has_value() && next_token.value().is_character() && next_token.value().codepoint() == '\n') {
|
if (next_token.has_value() && next_token.value().is_character() && next_token.value().code_point() == '\n') {
|
||||||
// Ignore it.
|
// Ignore it.
|
||||||
} else {
|
} else {
|
||||||
process_using_the_rules_for(m_insertion_mode, next_token.value());
|
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_frameset_ok = false;
|
||||||
m_insertion_mode = InsertionMode::Text;
|
m_insertion_mode = InsertionMode::Text;
|
||||||
|
|
||||||
if (next_token.has_value() && next_token.value().is_character() && next_token.value().codepoint() == '\n') {
|
if (next_token.has_value() && next_token.value().is_character() && next_token.value().code_point() == '\n') {
|
||||||
// Ignore it.
|
// Ignore it.
|
||||||
} else {
|
} else {
|
||||||
process_using_the_rules_for(m_insertion_mode, next_token.value());
|
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)
|
void HTMLDocumentParser::handle_text(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character()) {
|
if (token.is_character()) {
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (token.is_end_of_file()) {
|
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)
|
void HTMLDocumentParser::handle_in_table_text(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character()) {
|
if (token.is_character()) {
|
||||||
if (token.codepoint() == 0) {
|
if (token.code_point() == 0) {
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2000,7 +2000,7 @@ void HTMLDocumentParser::handle_in_table_text(HTMLToken& token)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& pending_token : m_pending_table_character_tokens) {
|
for (auto& pending_token : m_pending_table_character_tokens) {
|
||||||
insert_character(pending_token.codepoint());
|
insert_character(pending_token.code_point());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_insertion_mode = m_original_insertion_mode;
|
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)
|
void HTMLDocumentParser::handle_in_select(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character()) {
|
if (token.is_character()) {
|
||||||
if (token.codepoint() == 0) {
|
if (token.code_point() == 0) {
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2384,7 +2384,7 @@ void HTMLDocumentParser::handle_in_caption(HTMLToken& token)
|
||||||
void HTMLDocumentParser::handle_in_column_group(HTMLToken& token)
|
void HTMLDocumentParser::handle_in_column_group(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character() && token.is_parser_whitespace()) {
|
if (token.is_character() && token.is_parser_whitespace()) {
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2527,7 +2527,7 @@ void HTMLDocumentParser::handle_in_template(HTMLToken& token)
|
||||||
void HTMLDocumentParser::handle_in_frameset(HTMLToken& token)
|
void HTMLDocumentParser::handle_in_frameset(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character() && token.is_parser_whitespace()) {
|
if (token.is_character() && token.is_parser_whitespace()) {
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2587,7 +2587,7 @@ void HTMLDocumentParser::handle_in_frameset(HTMLToken& token)
|
||||||
void HTMLDocumentParser::handle_after_frameset(HTMLToken& token)
|
void HTMLDocumentParser::handle_after_frameset(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_character() && token.is_parser_whitespace()) {
|
if (token.is_character() && token.is_parser_whitespace()) {
|
||||||
insert_character(token.codepoint());
|
insert_character(token.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,11 +50,11 @@ public:
|
||||||
EndOfFile,
|
EndOfFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
static HTMLToken make_character(u32 codepoint)
|
static HTMLToken make_character(u32 code_point)
|
||||||
{
|
{
|
||||||
HTMLToken token;
|
HTMLToken token;
|
||||||
token.m_type = Type::Character;
|
token.m_type = Type::Character;
|
||||||
token.m_comment_or_character.data.append(codepoint);
|
token.m_comment_or_character.data.append(code_point);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,11 +73,11 @@ public:
|
||||||
bool is_character() const { return m_type == Type::Character; }
|
bool is_character() const { return m_type == Type::Character; }
|
||||||
bool is_end_of_file() const { return m_type == Type::EndOfFile; }
|
bool is_end_of_file() const { return m_type == Type::EndOfFile; }
|
||||||
|
|
||||||
u32 codepoint() const
|
u32 code_point() const
|
||||||
{
|
{
|
||||||
ASSERT(is_character());
|
ASSERT(is_character());
|
||||||
Utf8View view(m_comment_or_character.data.string_view());
|
Utf8View view(m_comment_or_character.data.string_view());
|
||||||
ASSERT(view.length_in_codepoints() == 1);
|
ASSERT(view.length_in_code_points() == 1);
|
||||||
return *view.begin();
|
return *view.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public:
|
||||||
// NOTE: The parser considers '\r' to be whitespace, while the tokenizer does not.
|
// NOTE: The parser considers '\r' to be whitespace, while the tokenizer does not.
|
||||||
if (!is_character())
|
if (!is_character())
|
||||||
return false;
|
return false;
|
||||||
switch (codepoint()) {
|
switch (code_point()) {
|
||||||
case '\t':
|
case '\t':
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\f':
|
case '\f':
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Web::HTML {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CONSUME_NEXT_INPUT_CHARACTER \
|
#define CONSUME_NEXT_INPUT_CHARACTER \
|
||||||
current_input_character = next_codepoint();
|
current_input_character = next_code_point();
|
||||||
|
|
||||||
#define SWITCH_TO(new_state) \
|
#define SWITCH_TO(new_state) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -86,9 +86,9 @@ namespace Web::HTML {
|
||||||
return m_queued_tokens.dequeue(); \
|
return m_queued_tokens.dequeue(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define EMIT_CHARACTER_AND_RECONSUME_IN(codepoint, new_state) \
|
#define EMIT_CHARACTER_AND_RECONSUME_IN(code_point, new_state) \
|
||||||
do { \
|
do { \
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint)); \
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point)); \
|
||||||
will_reconsume_in(State::new_state); \
|
will_reconsume_in(State::new_state); \
|
||||||
m_state = State::new_state; \
|
m_state = State::new_state; \
|
||||||
goto new_state; \
|
goto new_state; \
|
||||||
|
@ -96,12 +96,12 @@ namespace Web::HTML {
|
||||||
|
|
||||||
#define FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \
|
#define FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \
|
||||||
do { \
|
do { \
|
||||||
for (auto codepoint : m_temporary_buffer) { \
|
for (auto code_point : m_temporary_buffer) { \
|
||||||
if (consumed_as_part_of_an_attribute()) { \
|
if (consumed_as_part_of_an_attribute()) { \
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(codepoint); \
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(code_point); \
|
||||||
} else { \
|
} else { \
|
||||||
create_new_token(HTMLToken::Type::Character); \
|
create_new_token(HTMLToken::Type::Character); \
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(codepoint); \
|
m_current_token.m_comment_or_character.data.append_code_point(code_point); \
|
||||||
m_queued_tokens.enqueue(m_current_token); \
|
m_queued_tokens.enqueue(m_current_token); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
@ -112,8 +112,8 @@ namespace Web::HTML {
|
||||||
m_utf8_iterator = m_prev_utf8_iterator; \
|
m_utf8_iterator = m_prev_utf8_iterator; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ON(codepoint) \
|
#define ON(code_point) \
|
||||||
if (current_input_character.has_value() && current_input_character.value() == codepoint)
|
if (current_input_character.has_value() && current_input_character.value() == code_point)
|
||||||
|
|
||||||
#define ON_EOF \
|
#define ON_EOF \
|
||||||
if (!current_input_character.has_value())
|
if (!current_input_character.has_value())
|
||||||
|
@ -159,10 +159,10 @@ namespace Web::HTML {
|
||||||
return m_queued_tokens.dequeue(); \
|
return m_queued_tokens.dequeue(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define EMIT_CHARACTER(codepoint) \
|
#define EMIT_CHARACTER(code_point) \
|
||||||
do { \
|
do { \
|
||||||
create_new_token(HTMLToken::Type::Character); \
|
create_new_token(HTMLToken::Type::Character); \
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(codepoint); \
|
m_current_token.m_comment_or_character.data.append_code_point(code_point); \
|
||||||
m_queued_tokens.enqueue(m_current_token); \
|
m_queued_tokens.enqueue(m_current_token); \
|
||||||
return m_queued_tokens.dequeue(); \
|
return m_queued_tokens.dequeue(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -170,11 +170,11 @@ namespace Web::HTML {
|
||||||
#define EMIT_CURRENT_CHARACTER \
|
#define EMIT_CURRENT_CHARACTER \
|
||||||
EMIT_CHARACTER(current_input_character.value());
|
EMIT_CHARACTER(current_input_character.value());
|
||||||
|
|
||||||
#define SWITCH_TO_AND_EMIT_CHARACTER(codepoint, new_state) \
|
#define SWITCH_TO_AND_EMIT_CHARACTER(code_point, new_state) \
|
||||||
do { \
|
do { \
|
||||||
will_switch_to(State::new_state); \
|
will_switch_to(State::new_state); \
|
||||||
m_state = State::new_state; \
|
m_state = State::new_state; \
|
||||||
EMIT_CHARACTER(codepoint); \
|
EMIT_CHARACTER(code_point); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define SWITCH_TO_AND_EMIT_CURRENT_CHARACTER(new_state) \
|
#define SWITCH_TO_AND_EMIT_CURRENT_CHARACTER(new_state) \
|
||||||
|
@ -193,39 +193,39 @@ namespace Web::HTML {
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_surrogate(u32 codepoint)
|
static inline bool is_surrogate(u32 code_point)
|
||||||
{
|
{
|
||||||
return (codepoint & 0xfffff800) == 0xd800;
|
return (code_point & 0xfffff800) == 0xd800;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_noncharacter(u32 codepoint)
|
static inline bool is_noncharacter(u32 code_point)
|
||||||
{
|
{
|
||||||
return codepoint >= 0xfdd0 && (codepoint <= 0xfdef || (codepoint & 0xfffe) == 0xfffe) && codepoint <= 0x10ffff;
|
return code_point >= 0xfdd0 && (code_point <= 0xfdef || (code_point & 0xfffe) == 0xfffe) && code_point <= 0x10ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_c0_control(u32 codepoint)
|
static inline bool is_c0_control(u32 code_point)
|
||||||
{
|
{
|
||||||
return codepoint <= 0x1f;
|
return code_point <= 0x1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_control(u32 codepoint)
|
static inline bool is_control(u32 code_point)
|
||||||
{
|
{
|
||||||
return is_c0_control(codepoint) || (codepoint >= 0x7f && codepoint <= 0x9f);
|
return is_c0_control(code_point) || (code_point >= 0x7f && code_point <= 0x9f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<u32> HTMLTokenizer::next_codepoint()
|
Optional<u32> HTMLTokenizer::next_code_point()
|
||||||
{
|
{
|
||||||
if (m_utf8_iterator == m_utf8_view.end())
|
if (m_utf8_iterator == m_utf8_view.end())
|
||||||
return {};
|
return {};
|
||||||
m_prev_utf8_iterator = m_utf8_iterator;
|
m_prev_utf8_iterator = m_utf8_iterator;
|
||||||
++m_utf8_iterator;
|
++m_utf8_iterator;
|
||||||
#ifdef TOKENIZER_TRACE
|
#ifdef TOKENIZER_TRACE
|
||||||
dbg() << "(Tokenizer) Next codepoint: " << (char)*m_prev_utf8_iterator;
|
dbg() << "(Tokenizer) Next code_point: " << (char)*m_prev_utf8_iterator;
|
||||||
#endif
|
#endif
|
||||||
return *m_prev_utf8_iterator;
|
return *m_prev_utf8_iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<u32> HTMLTokenizer::peek_codepoint(size_t offset) const
|
Optional<u32> HTMLTokenizer::peek_code_point(size_t offset) const
|
||||||
{
|
{
|
||||||
auto it = m_utf8_iterator;
|
auto it = m_utf8_iterator;
|
||||||
for (size_t i = 0; i < offset && it != m_utf8_view.end(); ++i)
|
for (size_t i = 0; i < offset && it != m_utf8_view.end(); ++i)
|
||||||
|
@ -242,7 +242,7 @@ _StartOfFunction:
|
||||||
return m_queued_tokens.dequeue();
|
return m_queued_tokens.dequeue();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto current_input_character = next_codepoint();
|
auto current_input_character = next_code_point();
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
BEGIN_STATE(Data)
|
BEGIN_STATE(Data)
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_tag.tag_name.append_codepoint(0xFFFD);
|
m_current_token.m_tag.tag_name.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -338,7 +338,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.tag_name.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,12 +408,12 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(0xFFFD);
|
m_current_token.m_comment_or_character.data.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
|
m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
create_new_token(HTMLToken::Type::DOCTYPE);
|
create_new_token(HTMLToken::Type::DOCTYPE);
|
||||||
m_current_token.m_doctype.name.append_codepoint(0xFFFD);
|
m_current_token.m_doctype.name.append_code_point(0xFFFD);
|
||||||
m_current_token.m_doctype.missing_name = false;
|
m_current_token.m_doctype.missing_name = false;
|
||||||
SWITCH_TO(DOCTYPEName);
|
SWITCH_TO(DOCTYPEName);
|
||||||
}
|
}
|
||||||
|
@ -484,7 +484,7 @@ _StartOfFunction:
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
create_new_token(HTMLToken::Type::DOCTYPE);
|
create_new_token(HTMLToken::Type::DOCTYPE);
|
||||||
m_current_token.m_doctype.name.append_codepoint(current_input_character.value());
|
m_current_token.m_doctype.name.append_code_point(current_input_character.value());
|
||||||
m_current_token.m_doctype.missing_name = false;
|
m_current_token.m_doctype.missing_name = false;
|
||||||
SWITCH_TO(DOCTYPEName);
|
SWITCH_TO(DOCTYPEName);
|
||||||
}
|
}
|
||||||
|
@ -509,7 +509,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_doctype.name.append_codepoint(0xFFFD);
|
m_current_token.m_doctype.name.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -521,7 +521,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_doctype.name.append_codepoint(current_input_character.value());
|
m_current_token.m_doctype.name.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -732,7 +732,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_doctype.public_identifier.append_codepoint(0xFFFD);
|
m_current_token.m_doctype.public_identifier.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
|
@ -750,7 +750,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_doctype.public_identifier.append_codepoint(current_input_character.value());
|
m_current_token.m_doctype.public_identifier.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -765,7 +765,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_doctype.public_identifier.append_codepoint(0xFFFD);
|
m_current_token.m_doctype.public_identifier.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
|
@ -783,7 +783,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_doctype.public_identifier.append_codepoint(current_input_character.value());
|
m_current_token.m_doctype.public_identifier.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -798,7 +798,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_doctype.system_identifier.append_codepoint(0xFFFD);
|
m_current_token.m_doctype.system_identifier.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
|
@ -816,7 +816,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_doctype.system_identifier.append_codepoint(current_input_character.value());
|
m_current_token.m_doctype.system_identifier.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -831,7 +831,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_doctype.system_identifier.append_codepoint(0xFFFD);
|
m_current_token.m_doctype.system_identifier.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
|
@ -849,7 +849,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_doctype.system_identifier.append_codepoint(current_input_character.value());
|
m_current_token.m_doctype.system_identifier.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +1003,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
auto new_attribute = HTMLToken::AttributeBuilder();
|
auto new_attribute = HTMLToken::AttributeBuilder();
|
||||||
new_attribute.local_name_builder.append_codepoint(current_input_character.value());
|
new_attribute.local_name_builder.append_code_point(current_input_character.value());
|
||||||
m_current_token.m_tag.attributes.append(new_attribute);
|
m_current_token.m_tag.attributes.append(new_attribute);
|
||||||
SWITCH_TO(AttributeName);
|
SWITCH_TO(AttributeName);
|
||||||
}
|
}
|
||||||
|
@ -1059,13 +1059,13 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(tolower(current_input_character.value()));
|
m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(tolower(current_input_character.value()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(0xFFFD);
|
m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('"')
|
ON('"')
|
||||||
|
@ -1086,7 +1086,7 @@ _StartOfFunction:
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
AnythingElseAttributeName:
|
AnythingElseAttributeName:
|
||||||
m_current_token.m_tag.attributes.last().local_name_builder.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1163,7 +1163,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD);
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -1173,7 +1173,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1193,7 +1193,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD);
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -1203,7 +1203,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1227,7 +1227,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(0xFFFD);
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('"')
|
ON('"')
|
||||||
|
@ -1263,7 +1263,7 @@ _StartOfFunction:
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
AnythingElseAttributeValueUnquoted:
|
AnythingElseAttributeValueUnquoted:
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1343,7 +1343,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON('<')
|
ON('<')
|
||||||
{
|
{
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
|
m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value());
|
||||||
SWITCH_TO(CommentLessThanSign);
|
SWITCH_TO(CommentLessThanSign);
|
||||||
}
|
}
|
||||||
ON('-')
|
ON('-')
|
||||||
|
@ -1353,7 +1353,7 @@ _StartOfFunction:
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(0xFFFD);
|
m_current_token.m_comment_or_character.data.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -1364,7 +1364,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
|
m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1449,12 +1449,12 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON('!')
|
ON('!')
|
||||||
{
|
{
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
|
m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value());
|
||||||
SWITCH_TO(CommentLessThanSignBang);
|
SWITCH_TO(CommentLessThanSignBang);
|
||||||
}
|
}
|
||||||
ON('<')
|
ON('<')
|
||||||
{
|
{
|
||||||
m_current_token.m_comment_or_character.data.append_codepoint(current_input_character.value());
|
m_current_token.m_comment_or_character.data.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
|
@ -1533,7 +1533,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
size_t byte_offset = m_utf8_view.byte_offset_of(m_prev_utf8_iterator);
|
size_t byte_offset = m_utf8_view.byte_offset_of(m_prev_utf8_iterator);
|
||||||
|
|
||||||
auto match = HTML::codepoints_from_entity(m_decoded_input.substring_view(byte_offset, m_decoded_input.length() - byte_offset - 1));
|
auto match = HTML::code_points_from_entity(m_decoded_input.substring_view(byte_offset, m_decoded_input.length() - byte_offset - 1));
|
||||||
|
|
||||||
if (match.has_value()) {
|
if (match.has_value()) {
|
||||||
for (size_t i = 0; i < match.value().entity.length() - 1; ++i) {
|
for (size_t i = 0; i < match.value().entity.length() - 1; ++i) {
|
||||||
|
@ -1543,8 +1543,8 @@ _StartOfFunction:
|
||||||
for (auto ch : match.value().entity)
|
for (auto ch : match.value().entity)
|
||||||
m_temporary_buffer.append(ch);
|
m_temporary_buffer.append(ch);
|
||||||
|
|
||||||
if (consumed_as_part_of_an_attribute() && match.value().codepoints.last() != ';') {
|
if (consumed_as_part_of_an_attribute() && match.value().code_points.last() != ';') {
|
||||||
auto next = peek_codepoint(0);
|
auto next = peek_code_point(0);
|
||||||
if (next.has_value() && (next.value() == '=' || isalnum(next.value()))) {
|
if (next.has_value() && (next.value() == '=' || isalnum(next.value()))) {
|
||||||
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
|
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
|
||||||
SWITCH_TO_RETURN_STATE;
|
SWITCH_TO_RETURN_STATE;
|
||||||
|
@ -1552,8 +1552,8 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consumed_as_part_of_an_attribute() && match.value().entity.ends_with(';')) {
|
if (consumed_as_part_of_an_attribute() && match.value().entity.ends_with(';')) {
|
||||||
auto next_codepoint = peek_codepoint(0);
|
auto next_code_point = peek_code_point(0);
|
||||||
if (next_codepoint.has_value() && next_codepoint.value() == '=') {
|
if (next_code_point.has_value() && next_code_point.value() == '=') {
|
||||||
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
|
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
|
||||||
SWITCH_TO_RETURN_STATE;
|
SWITCH_TO_RETURN_STATE;
|
||||||
}
|
}
|
||||||
|
@ -1564,7 +1564,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
|
|
||||||
m_temporary_buffer.clear();
|
m_temporary_buffer.clear();
|
||||||
m_temporary_buffer.append(match.value().codepoints);
|
m_temporary_buffer.append(match.value().code_points);
|
||||||
|
|
||||||
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
|
FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE;
|
||||||
SWITCH_TO_RETURN_STATE;
|
SWITCH_TO_RETURN_STATE;
|
||||||
|
@ -1580,7 +1580,7 @@ _StartOfFunction:
|
||||||
ON_ASCII_ALPHANUMERIC
|
ON_ASCII_ALPHANUMERIC
|
||||||
{
|
{
|
||||||
if (consumed_as_part_of_an_attribute()) {
|
if (consumed_as_part_of_an_attribute()) {
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
EMIT_CURRENT_CHARACTER;
|
EMIT_CURRENT_CHARACTER;
|
||||||
|
@ -1724,7 +1724,7 @@ _StartOfFunction:
|
||||||
PARSE_ERROR();
|
PARSE_ERROR();
|
||||||
constexpr struct {
|
constexpr struct {
|
||||||
u32 number;
|
u32 number;
|
||||||
u32 codepoint;
|
u32 code_point;
|
||||||
} conversion_table[] = {
|
} conversion_table[] = {
|
||||||
{ 0x80, 0x20AC },
|
{ 0x80, 0x20AC },
|
||||||
{ 0x82, 0x201A },
|
{ 0x82, 0x201A },
|
||||||
|
@ -1756,7 +1756,7 @@ _StartOfFunction:
|
||||||
};
|
};
|
||||||
for (auto& entry : conversion_table) {
|
for (auto& entry : conversion_table) {
|
||||||
if (m_character_reference_code == entry.number) {
|
if (m_character_reference_code == entry.number) {
|
||||||
m_character_reference_code = entry.codepoint;
|
m_character_reference_code = entry.code_point;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1833,8 +1833,8 @@ _StartOfFunction:
|
||||||
if (!current_end_tag_token_is_appropriate()) {
|
if (!current_end_tag_token_is_appropriate()) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RCDATA);
|
RECONSUME_IN(RCDATA);
|
||||||
}
|
}
|
||||||
SWITCH_TO(BeforeAttributeName);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
|
@ -1844,8 +1844,8 @@ _StartOfFunction:
|
||||||
if (!current_end_tag_token_is_appropriate()) {
|
if (!current_end_tag_token_is_appropriate()) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RCDATA);
|
RECONSUME_IN(RCDATA);
|
||||||
}
|
}
|
||||||
SWITCH_TO(SelfClosingStartTag);
|
SWITCH_TO(SelfClosingStartTag);
|
||||||
|
@ -1855,8 +1855,8 @@ _StartOfFunction:
|
||||||
if (!current_end_tag_token_is_appropriate()) {
|
if (!current_end_tag_token_is_appropriate()) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RCDATA);
|
RECONSUME_IN(RCDATA);
|
||||||
}
|
}
|
||||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||||
|
@ -1869,7 +1869,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON_ASCII_LOWER_ALPHA
|
ON_ASCII_LOWER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append_codepoint(current_input_character.value());
|
m_current_token.m_tag.tag_name.append_code_point(current_input_character.value());
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1877,8 +1877,8 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RCDATA);
|
RECONSUME_IN(RCDATA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1943,8 +1943,8 @@ _StartOfFunction:
|
||||||
if (!current_end_tag_token_is_appropriate()) {
|
if (!current_end_tag_token_is_appropriate()) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RAWTEXT);
|
RECONSUME_IN(RAWTEXT);
|
||||||
}
|
}
|
||||||
SWITCH_TO(BeforeAttributeName);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
|
@ -1954,8 +1954,8 @@ _StartOfFunction:
|
||||||
if (!current_end_tag_token_is_appropriate()) {
|
if (!current_end_tag_token_is_appropriate()) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RAWTEXT);
|
RECONSUME_IN(RAWTEXT);
|
||||||
}
|
}
|
||||||
SWITCH_TO(SelfClosingStartTag);
|
SWITCH_TO(SelfClosingStartTag);
|
||||||
|
@ -1965,8 +1965,8 @@ _StartOfFunction:
|
||||||
if (!current_end_tag_token_is_appropriate()) {
|
if (!current_end_tag_token_is_appropriate()) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RAWTEXT);
|
RECONSUME_IN(RAWTEXT);
|
||||||
}
|
}
|
||||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
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('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(RAWTEXT);
|
RECONSUME_IN(RAWTEXT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2155,8 +2155,8 @@ _StartOfFunction:
|
||||||
|
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer) {
|
for (auto code_point : m_temporary_buffer) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
}
|
}
|
||||||
RECONSUME_IN(ScriptDataEscaped);
|
RECONSUME_IN(ScriptDataEscaped);
|
||||||
}
|
}
|
||||||
|
@ -2167,8 +2167,8 @@ _StartOfFunction:
|
||||||
|
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer) {
|
for (auto code_point : m_temporary_buffer) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
}
|
}
|
||||||
RECONSUME_IN(ScriptDataEscaped);
|
RECONSUME_IN(ScriptDataEscaped);
|
||||||
}
|
}
|
||||||
|
@ -2179,8 +2179,8 @@ _StartOfFunction:
|
||||||
|
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer) {
|
for (auto code_point : m_temporary_buffer) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
}
|
}
|
||||||
RECONSUME_IN(ScriptDataEscaped);
|
RECONSUME_IN(ScriptDataEscaped);
|
||||||
}
|
}
|
||||||
|
@ -2200,8 +2200,8 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer) {
|
for (auto code_point : m_temporary_buffer) {
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
}
|
}
|
||||||
RECONSUME_IN(ScriptDataEscaped);
|
RECONSUME_IN(ScriptDataEscaped);
|
||||||
}
|
}
|
||||||
|
@ -2479,8 +2479,8 @@ _StartOfFunction:
|
||||||
SWITCH_TO(BeforeAttributeName);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(ScriptData);
|
RECONSUME_IN(ScriptData);
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
|
@ -2489,8 +2489,8 @@ _StartOfFunction:
|
||||||
SWITCH_TO(SelfClosingStartTag);
|
SWITCH_TO(SelfClosingStartTag);
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(ScriptData);
|
RECONSUME_IN(ScriptData);
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
|
@ -2499,8 +2499,8 @@ _StartOfFunction:
|
||||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(ScriptData);
|
RECONSUME_IN(ScriptData);
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
|
@ -2519,8 +2519,8 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||||
for (auto codepoint : m_temporary_buffer)
|
for (auto code_point : m_temporary_buffer)
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character(codepoint));
|
m_queued_tokens.enqueue(HTMLToken::make_character(code_point));
|
||||||
RECONSUME_IN(ScriptData);
|
RECONSUME_IN(ScriptData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2585,18 +2585,18 @@ _StartOfFunction:
|
||||||
bool HTMLTokenizer::consume_next_if_match(const StringView& string, CaseSensitivity case_sensitivity)
|
bool HTMLTokenizer::consume_next_if_match(const StringView& string, CaseSensitivity case_sensitivity)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < string.length(); ++i) {
|
for (size_t i = 0; i < string.length(); ++i) {
|
||||||
auto codepoint = peek_codepoint(i);
|
auto code_point = peek_code_point(i);
|
||||||
if (!codepoint.has_value())
|
if (!code_point.has_value())
|
||||||
return false;
|
return false;
|
||||||
// FIXME: This should be more Unicode-aware.
|
// FIXME: This should be more Unicode-aware.
|
||||||
if (case_sensitivity == CaseSensitivity::CaseInsensitive) {
|
if (case_sensitivity == CaseSensitivity::CaseInsensitive) {
|
||||||
if (codepoint.value() < 0x80) {
|
if (code_point.value() < 0x80) {
|
||||||
if (tolower(codepoint.value()) != tolower(string[i]))
|
if (tolower(code_point.value()) != tolower(string[i]))
|
||||||
return false;
|
return false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (codepoint.value() != (u32)string[i])
|
if (code_point.value() != (u32)string[i])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < string.length(); ++i) {
|
for (size_t i = 0; i < string.length(); ++i) {
|
||||||
|
|
|
@ -137,8 +137,8 @@ public:
|
||||||
String source() const { return m_decoded_input; }
|
String source() const { return m_decoded_input; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Optional<u32> next_codepoint();
|
Optional<u32> next_code_point();
|
||||||
Optional<u32> peek_codepoint(size_t offset) const;
|
Optional<u32> peek_code_point(size_t offset) const;
|
||||||
bool consume_next_if_match(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive);
|
bool consume_next_if_match(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive);
|
||||||
void create_new_token(HTMLToken::Type);
|
void create_new_token(HTMLToken::Type);
|
||||||
bool current_end_tag_token_is_appropriate() const;
|
bool current_end_tag_token_is_appropriate() const;
|
||||||
|
|
|
@ -209,7 +209,7 @@ void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode la
|
||||||
skip_over_whitespace();
|
skip_over_whitespace();
|
||||||
for (; it != utf8_view.end(); ++it) {
|
for (; it != utf8_view.end(); ++it) {
|
||||||
if (!isspace(*it)) {
|
if (!isspace(*it)) {
|
||||||
builder.append(utf8_view.as_string().characters_without_null_termination() + utf8_view.byte_offset_of(it), it.codepoint_length_in_bytes());
|
builder.append(utf8_view.as_string().characters_without_null_termination() + utf8_view.byte_offset_of(it), it.code_point_length_in_bytes());
|
||||||
} else {
|
} else {
|
||||||
builder.append(' ');
|
builder.append(' ');
|
||||||
skip_over_whitespace();
|
skip_over_whitespace();
|
||||||
|
|
|
@ -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());
|
auto& text_node = downcast<DOM::Text>(*m_frame.cursor_position().node());
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(text_node.data().substring_view(0, m_frame.cursor_position().offset()));
|
builder.append(text_node.data().substring_view(0, m_frame.cursor_position().offset()));
|
||||||
builder.append_codepoint(code_point);
|
builder.append_code_point(code_point);
|
||||||
builder.append(text_node.data().substring_view(m_frame.cursor_position().offset(), text_node.data().length() - m_frame.cursor_position().offset()));
|
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());
|
text_node.set_data(builder.to_string());
|
||||||
// FIXME: This will advance the cursor incorrectly when inserting multiple whitespaces (DOM vs layout whitespace collapse difference.)
|
// FIXME: This will advance the cursor incorrectly when inserting multiple whitespaces (DOM vs layout whitespace collapse difference.)
|
||||||
|
|
|
@ -146,7 +146,7 @@ void MenuManager::event(Core::Event& event)
|
||||||
if (m_current_menu && event.type() == Event::KeyDown
|
if (m_current_menu && event.type() == Event::KeyDown
|
||||||
&& ((key_event.key() >= Key_A && key_event.key() <= Key_Z)
|
&& ((key_event.key() >= Key_A && key_event.key() <= Key_Z)
|
||||||
|| (key_event.key() >= Key_0 && key_event.key() <= Key_9))) {
|
|| (key_event.key() >= Key_0 && key_event.key() <= Key_9))) {
|
||||||
m_current_search.append_codepoint(key_event.code_point());
|
m_current_search.append_code_point(key_event.code_point());
|
||||||
m_search_timer->restart(s_search_timeout);
|
m_search_timer->restart(s_search_timeout);
|
||||||
for (int i = 0; i < m_current_menu->item_count(); ++i) {
|
for (int i = 0; i < m_current_menu->item_count(); ++i) {
|
||||||
auto text = m_current_menu->item(i).text();
|
auto text = m_current_menu->item(i).text();
|
||||||
|
|
|
@ -144,7 +144,7 @@ int print_escaped(const char* name)
|
||||||
Utf8View utf8_name(name);
|
Utf8View utf8_name(name);
|
||||||
if (utf8_name.validate()) {
|
if (utf8_name.validate()) {
|
||||||
printf("%s", name);
|
printf("%s", name);
|
||||||
return utf8_name.length_in_codepoints();
|
return utf8_name.length_in_code_points();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; name[i] != '\0'; i++) {
|
for (int i = 0; name[i] != '\0'; i++) {
|
||||||
|
|
Loading…
Reference in a new issue