LibWeb: Use getter and setter for Character type HTMLTokens
While storing the code point in a UTF-8 encoded String in horrendously inefficient, this problem will be addressed at a later stage.
This commit is contained in:
parent
e8e9426b4f
commit
1aeafcc58b
Notes:
sideshowbarker
2024-07-18 08:53:02 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/1aeafcc58bc Pull-request: https://github.com/SerenityOS/serenity/pull/8784 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard
2 changed files with 26 additions and 23 deletions
|
@ -50,10 +50,7 @@ public:
|
||||||
{
|
{
|
||||||
HTMLToken token;
|
HTMLToken token;
|
||||||
token.m_type = Type::Character;
|
token.m_type = Type::Character;
|
||||||
StringBuilder builder;
|
token.set_code_point(code_point);
|
||||||
// FIXME: This narrows code_point to char, should this be append_code_point() instead?
|
|
||||||
builder.append(code_point);
|
|
||||||
token.m_comment_or_character.data = builder.to_string();
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +94,14 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_code_point(u32 code_point)
|
||||||
|
{
|
||||||
|
VERIFY(is_character());
|
||||||
|
StringBuilder builder;
|
||||||
|
builder.append_code_point(code_point);
|
||||||
|
m_comment_or_character.data = builder.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
String const& comment() const
|
String const& comment() const
|
||||||
{
|
{
|
||||||
VERIFY(is_comment());
|
VERIFY(is_comment());
|
||||||
|
|
|
@ -82,8 +82,7 @@ namespace Web::HTML {
|
||||||
m_current_builder.append_code_point(code_point); \
|
m_current_builder.append_code_point(code_point); \
|
||||||
} else { \
|
} else { \
|
||||||
create_new_token(HTMLToken::Type::Character); \
|
create_new_token(HTMLToken::Type::Character); \
|
||||||
m_current_builder.append_code_point(code_point); \
|
m_current_token.set_code_point(code_point); \
|
||||||
m_current_token.m_comment_or_character.data = consume_current_builder(); \
|
|
||||||
m_queued_tokens.enqueue(move(m_current_token)); \
|
m_queued_tokens.enqueue(move(m_current_token)); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
@ -145,8 +144,7 @@ namespace Web::HTML {
|
||||||
#define EMIT_CHARACTER(code_point) \
|
#define EMIT_CHARACTER(code_point) \
|
||||||
do { \
|
do { \
|
||||||
create_new_token(HTMLToken::Type::Character); \
|
create_new_token(HTMLToken::Type::Character); \
|
||||||
m_current_builder.append_code_point(code_point); \
|
m_current_token.set_code_point(code_point); \
|
||||||
m_current_token.m_comment_or_character.data = consume_current_builder(); \
|
|
||||||
m_queued_tokens.enqueue(move(m_current_token)); \
|
m_queued_tokens.enqueue(move(m_current_token)); \
|
||||||
return m_queued_tokens.dequeue(); \
|
return m_queued_tokens.dequeue(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue