More work on fast css transforms

This commit is contained in:
Kovid Goyal 2021-03-17 22:51:11 +05:30
parent d0b9a0d153
commit 5b30af2216
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -16,6 +16,7 @@
#include <exception> #include <exception>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <functional>
// character classes {{{ // character classes {{{
static inline bool static inline bool
@ -145,6 +146,7 @@ class Token {
void set_type(const TokenType q) { type = q; } void set_type(const TokenType q) { type = q; }
void set_output_position(const size_t val) { out_pos = val; } void set_output_position(const size_t val) { out_pos = val; }
bool is_type(const TokenType q) const { return type == q; } bool is_type(const TokenType q) const { return type == q; }
bool is_delimiter(const char32_t ch) const { return type == TokenType::delimiter && text.size() == 1 && text[0] == ch; }
void add_char(const char32_t ch) { text.push_back(ch); } void add_char(const char32_t ch) { text.push_back(ch); }
void mark_unit() { unit_at = text.size(); } void mark_unit() { unit_at = text.size(); }
void clear_text() { text.clear(); } void clear_text() { text.clear(); }
@ -161,6 +163,10 @@ class Token {
return true; return true;
} }
bool is_keyword_case_insensitive(const char *lowercase_text) const {
return type == TokenType::ident && text_equals_case_insensitive(lowercase_text);
}
void trim_trailing_whitespace() { void trim_trailing_whitespace() {
while(text.size() && is_whitespace(text.back())) text.pop_back(); while(text.size() && is_whitespace(text.back())) text.pop_back();
} }
@ -262,6 +268,33 @@ class TokenQueue {
} }
bool process_declaration() { bool process_declaration() {
bool changed = false;
bool colon_found = false, key_found = false;
std::function<bool(std::vector<Token>::iterator)> process_values;
for (auto it = queue.begin(); it < queue.end(); it++) {
if (!it->is_significant()) continue;
if (key_found) {
if (colon_found) {
if (process_values) process_values(it);
break;
} else {
if (!it->is_delimiter(':')) break; // no colon found
colon_found = true;
}
} else {
if (it->is_type(TokenType::ident)) {
key_found = true;
if (it->text_equals_case_insensitive("font") || it->text_equals_case_insensitive("font-size")) {
process_values = std::bind(&TokenQueue::process_font_sizes, this, std::placeholders::_1);
}
} else break; // no property key found
}
}
return changed;
}
bool process_font_sizes(std::vector<Token>::iterator) {
bool changed = false; bool changed = false;
return changed; return changed;
} }