mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
LibWeb: Remove StringBuilder from HTMLToken::m_tag
This commit is contained in:
parent
901d71148b
commit
3aa202c432
4 changed files with 33 additions and 21 deletions
|
@ -1572,8 +1572,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
||||||
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::image) {
|
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::image) {
|
||||||
// Parse error. Change the token's tag name to HTML::TagNames::img and reprocess it. (Don't ask.)
|
// Parse error. Change the token's tag name to HTML::TagNames::img and reprocess it. (Don't ask.)
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
token.m_tag.tag_name.clear();
|
token.m_tag.tag_name = "img";
|
||||||
token.m_tag.tag_name.append(HTML::TagNames::img);
|
|
||||||
process_using_the_rules_for(m_insertion_mode, token);
|
process_using_the_rules_for(m_insertion_mode, token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ String HTMLToken::to_string() const
|
||||||
|
|
||||||
if (type() == HTMLToken::Type::StartTag || type() == HTMLToken::Type::EndTag) {
|
if (type() == HTMLToken::Type::StartTag || type() == HTMLToken::Type::EndTag) {
|
||||||
builder.append(" { name: '");
|
builder.append(" { name: '");
|
||||||
builder.append(m_tag.tag_name.to_string());
|
builder.append(m_tag.tag_name);
|
||||||
builder.append("', { ");
|
builder.append("', { ");
|
||||||
for (auto& attribute : m_tag.attributes) {
|
for (auto& attribute : m_tag.attributes) {
|
||||||
builder.append(attribute.local_name);
|
builder.append(attribute.local_name);
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
{
|
{
|
||||||
HTMLToken token;
|
HTMLToken token;
|
||||||
token.m_type = Type::StartTag;
|
token.m_type = Type::StartTag;
|
||||||
token.m_tag.tag_name.append(tag_name);
|
token.m_tag.tag_name = tag_name;
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
String tag_name() const
|
String tag_name() const
|
||||||
{
|
{
|
||||||
VERIFY(is_start_tag() || is_end_tag());
|
VERIFY(is_start_tag() || is_end_tag());
|
||||||
return m_tag.tag_name.to_string();
|
return m_tag.tag_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_self_closing() const
|
bool is_self_closing() const
|
||||||
|
@ -120,10 +120,8 @@ public:
|
||||||
void adjust_tag_name(const FlyString& old_name, const FlyString& new_name)
|
void adjust_tag_name(const FlyString& old_name, const FlyString& new_name)
|
||||||
{
|
{
|
||||||
VERIFY(is_start_tag() || is_end_tag());
|
VERIFY(is_start_tag() || is_end_tag());
|
||||||
if (old_name == m_tag.tag_name.string_view()) {
|
if (old_name == m_tag.tag_name)
|
||||||
m_tag.tag_name.clear();
|
m_tag.tag_name = new_name;
|
||||||
m_tag.tag_name.append(new_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjust_attribute_name(const FlyString& old_name, const FlyString& new_name)
|
void adjust_attribute_name(const FlyString& old_name, const FlyString& new_name)
|
||||||
|
@ -202,7 +200,7 @@ private:
|
||||||
// Type::StartTag
|
// Type::StartTag
|
||||||
// Type::EndTag
|
// Type::EndTag
|
||||||
struct {
|
struct {
|
||||||
StringBuilder tag_name;
|
String tag_name;
|
||||||
bool self_closing { false };
|
bool self_closing { false };
|
||||||
bool self_closing_acknowledged { false };
|
bool self_closing_acknowledged { false };
|
||||||
Vector<AttributeBuilder> attributes;
|
Vector<AttributeBuilder> attributes;
|
||||||
|
|
|
@ -303,29 +303,32 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
ON_WHITESPACE
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
m_current_token.m_end_position = nth_last_position(1);
|
m_current_token.m_end_position = nth_last_position(1);
|
||||||
SWITCH_TO(BeforeAttributeName);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
m_current_token.m_end_position = nth_last_position(0);
|
m_current_token.m_end_position = nth_last_position(0);
|
||||||
SWITCH_TO(SelfClosingStartTag);
|
SWITCH_TO(SelfClosingStartTag);
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
m_current_token.m_end_position = nth_last_position(1);
|
m_current_token.m_end_position = nth_last_position(1);
|
||||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value()));
|
m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value()));
|
||||||
m_current_token.m_end_position = nth_last_position(0);
|
m_current_token.m_end_position = nth_last_position(0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
m_current_token.m_tag.tag_name.append_code_point(0xFFFD);
|
m_current_builder.append_code_point(0xFFFD);
|
||||||
m_current_token.m_end_position = nth_last_position(0);
|
m_current_token.m_end_position = nth_last_position(0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -337,7 +340,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append_code_point(current_input_character.value());
|
m_current_builder.append_code_point(current_input_character.value());
|
||||||
m_current_token.m_end_position = nth_last_position(0);
|
m_current_token.m_end_position = nth_last_position(0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1846,6 +1849,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
ON_WHITESPACE
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
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('/'));
|
||||||
|
@ -1857,6 +1861,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
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('/'));
|
||||||
|
@ -1868,6 +1873,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
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('/'));
|
||||||
|
@ -1879,13 +1885,13 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value()));
|
m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value()));
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_ASCII_LOWER_ALPHA
|
ON_ASCII_LOWER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append_code_point(current_input_character.value());
|
m_current_builder.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;
|
||||||
}
|
}
|
||||||
|
@ -1956,6 +1962,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
ON_WHITESPACE
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
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('/'));
|
||||||
|
@ -1967,6 +1974,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
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('/'));
|
||||||
|
@ -1978,6 +1986,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
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('/'));
|
||||||
|
@ -1989,13 +1998,13 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value()));
|
m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value()));
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_ASCII_LOWER_ALPHA
|
ON_ASCII_LOWER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(current_input_character.value());
|
m_current_builder.append(current_input_character.value());
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2166,6 +2175,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
ON_WHITESPACE
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
if (current_end_tag_token_is_appropriate())
|
if (current_end_tag_token_is_appropriate())
|
||||||
SWITCH_TO(BeforeAttributeName);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
|
|
||||||
|
@ -2178,6 +2188,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
if (current_end_tag_token_is_appropriate())
|
if (current_end_tag_token_is_appropriate())
|
||||||
SWITCH_TO(SelfClosingStartTag);
|
SWITCH_TO(SelfClosingStartTag);
|
||||||
|
|
||||||
|
@ -2190,6 +2201,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
if (current_end_tag_token_is_appropriate())
|
if (current_end_tag_token_is_appropriate())
|
||||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||||
|
|
||||||
|
@ -2202,13 +2214,13 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value()));
|
m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value()));
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_ASCII_LOWER_ALPHA
|
ON_ASCII_LOWER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(current_input_character.value());
|
m_current_builder.append(current_input_character.value());
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2491,6 +2503,7 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
ON_WHITESPACE
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
if (current_end_tag_token_is_appropriate())
|
if (current_end_tag_token_is_appropriate())
|
||||||
SWITCH_TO(BeforeAttributeName);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
|
@ -2501,6 +2514,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
if (current_end_tag_token_is_appropriate())
|
if (current_end_tag_token_is_appropriate())
|
||||||
SWITCH_TO(SelfClosingStartTag);
|
SWITCH_TO(SelfClosingStartTag);
|
||||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||||
|
@ -2511,6 +2525,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||||
if (current_end_tag_token_is_appropriate())
|
if (current_end_tag_token_is_appropriate())
|
||||||
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('<'));
|
||||||
|
@ -2521,13 +2536,13 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
ON_ASCII_UPPER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value()));
|
m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value()));
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_ASCII_LOWER_ALPHA
|
ON_ASCII_LOWER_ALPHA
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.tag_name.append(current_input_character.value());
|
m_current_builder.append(current_input_character.value());
|
||||||
m_temporary_buffer.append(current_input_character.value());
|
m_temporary_buffer.append(current_input_character.value());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue