Kaynağa Gözat

LibWeb: Track the byte offset of an HTMLToken's position

We currently track the [line, column] position of every HTMLToken, as
this is what is needed for LibGUI's syntax highlighting. Some non-LibGUI
purposes (e.g. highlighting HTML with HTML) require a byte offset. Track
both during tokenization.
Timothy Flynn 1 yıl önce
ebeveyn
işleme
fea440055a

+ 1 - 0
Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h

@@ -37,6 +37,7 @@ public:
     struct Position {
         size_t line { 0 };
         size_t column { 0 };
+        size_t byte_offset { 0 };
     };
 
     struct Attribute {

+ 1 - 0
Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp

@@ -223,6 +223,7 @@ void HTMLTokenizer::skip(size_t count)
             } else {
                 m_source_positions.last().column++;
             }
+            m_source_positions.last().byte_offset += m_utf8_iterator.underlying_code_point_length_in_bytes();
         }
         ++m_utf8_iterator;
     }