summaryrefslogtreecommitdiff
path: root/src/html_token.cpp
blob: 1eabaa868c8c28beffd79793f19535ad0ac2966d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "html_token.hpp"
#include <matte/logger.h>

const char* TOKEN_TO_NAME_MAP[HtmlTokenType_Length] = {
    "Text",
    "Start Tag",
    "End Tag",
    "EOF",
    "Character"
};

void HtmlToken::print() {
    const char* name = TOKEN_TO_NAME_MAP[type];
    switch (type) {
    case HtmlTokenType_Character:
        logger_info("%s, %c", name, character_token);
        break;
    case HtmlTokenType_StartTag:
    case HtmlTokenType_EndTag:
        logger_info("%s, %S, attributes: %lu", name, tag_name.c_str(), attributes.size());

        for (auto i = 0; i < attributes.size(); i++) {
            HtmlAttribute& attribute = attributes[i];
            printf("\tattribute: %S=%S\n", attribute.name.c_str(), attribute.value.c_str());
        }
        break;
    default:
        logger_info("%s", name);
    }
}

void HtmlToken::reset() {
    type = HtmlTokenType_None;
    tag_name.clear();
    code_entity.clear();
    attributes.clear();
}