This repository was archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute_name.cpp
More file actions
43 lines (37 loc) · 1.65 KB
/
Copy pathattribute_name.cpp
File metadata and controls
43 lines (37 loc) · 1.65 KB
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
38
39
40
41
42
43
/**
* Copyright (C) 2020 Tristan. All Rights Reserved.
* This file is licensed under the BSD 2-Clause license.
* See the COPYING file for licensing information.
*/
#include "attribute_name.hpp"
#include <iostream>
#include <vector>
bool
HTML::Tokenizer::AttributeName::Parse() {
auto &tagToken = context.GetCurrentTagToken();
const static std::array<char, 6> characterList = {Unicode::CHARACTER_TABULATION, Unicode::LINE_FEED,
Unicode::FORM_FEED, Unicode::SPACE, '\\', Unicode::GREATER_THAN_SIGN};
if (context.eof
|| std::find(std::begin(characterList), std::end(characterList), context.character)
!= std::end(characterList)) {
context.reconsume = true;
context.state = HTML::Tokenizer::ParserState::AFTER_ATTRIBUTE_NAME;
} else if (context.character == Unicode::EQUALS_SIGN) {
context.state = HTML::Tokenizer::ParserState::BEFORE_ATTRIBUTE_VALUE;
} else if (context.character >= Unicode::LATIN_CAPITAL_LETTER_A
&& context.character <= Unicode::LATIN_CAPITAL_LETTER_Z) { // Is uppercase
tagToken.attributeName += static_cast<char>(context.character + 0x20);
} else if (context.character == Unicode::NULL_CHARACTER) {
context.LogError(HTML::Tokenizer::ParserError::UNEXPECTED_NULL_CHARACTER);
tagToken.attributeName += Unicode::REPLACEMENT_CHARACTER;
} else {
if (context.character == Unicode::QUOTATION_MARK || context.character == Unicode::APOSTROPHE
|| context.character == Unicode::LESS_THAN_SIGN) {
context.LogError(HTML::Tokenizer::ParserError::UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME);
// Intentional Fallthrough
}
tagToken.attributeName += context.character;
}
// TODO Check duplicate-attribute parser error
return true;
}