diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-07-14 23:33:12 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-17 16:24:57 +0430 |
commit | 1aeafcc58bc38bd6c90e218b4e75a57893d4f0d8 (patch) | |
tree | 1deee753986d3db7c5a9b5f17518eb22861a7224 /Userland/Libraries/LibWeb | |
parent | e8e9426b4fcf6042b7658a805eabe9b2012d6769 (diff) | |
download | serenity-1aeafcc58bc38bd6c90e218b4e75a57893d4f0d8.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp | 36 |
2 files changed, 26 insertions, 23 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h index 74cf4bb359..1649a20e7f 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h @@ -50,10 +50,7 @@ public: { HTMLToken token; token.m_type = Type::Character; - StringBuilder builder; - // 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(); + token.set_code_point(code_point); 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 { VERIFY(is_comment()); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index 2644c9dd3c..32e3c630c4 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -75,18 +75,17 @@ namespace Web::HTML { goto new_state; \ } while (0) -#define FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \ - do { \ - for (auto code_point : m_temporary_buffer) { \ - if (consumed_as_part_of_an_attribute()) { \ - m_current_builder.append_code_point(code_point); \ - } else { \ - create_new_token(HTMLToken::Type::Character); \ - m_current_builder.append_code_point(code_point); \ - m_current_token.m_comment_or_character.data = consume_current_builder(); \ - m_queued_tokens.enqueue(move(m_current_token)); \ - } \ - } \ +#define FLUSH_CODEPOINTS_CONSUMED_AS_A_CHARACTER_REFERENCE \ + do { \ + for (auto code_point : m_temporary_buffer) { \ + if (consumed_as_part_of_an_attribute()) { \ + m_current_builder.append_code_point(code_point); \ + } else { \ + create_new_token(HTMLToken::Type::Character); \ + m_current_token.set_code_point(code_point); \ + m_queued_tokens.enqueue(move(m_current_token)); \ + } \ + } \ } while (0) #define DONT_CONSUME_NEXT_INPUT_CHARACTER \ @@ -142,13 +141,12 @@ namespace Web::HTML { return m_queued_tokens.dequeue(); \ } while (0) -#define EMIT_CHARACTER(code_point) \ - do { \ - create_new_token(HTMLToken::Type::Character); \ - m_current_builder.append_code_point(code_point); \ - m_current_token.m_comment_or_character.data = consume_current_builder(); \ - m_queued_tokens.enqueue(move(m_current_token)); \ - return m_queued_tokens.dequeue(); \ +#define EMIT_CHARACTER(code_point) \ + do { \ + create_new_token(HTMLToken::Type::Character); \ + m_current_token.set_code_point(code_point); \ + m_queued_tokens.enqueue(move(m_current_token)); \ + return m_queued_tokens.dequeue(); \ } while (0) #define EMIT_CURRENT_CHARACTER \ |