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_value_nq.cpp
More file actions
54 lines (49 loc) · 1.86 KB
/
Copy pathattribute_value_nq.cpp
File metadata and controls
54 lines (49 loc) · 1.86 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
44
45
46
47
48
49
50
51
52
53
54
/**
* 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_value_nq.hpp"
#include <iostream>
#include <vector>
bool
HTML::Tokenizer::AttributeValueNQ::Parse() {
if (context.eof) {
context.LogError(HTML::Tokenizer::ParserError::EOF_IN_TAG);
tokenizer.treeConstructor.EmitEOFToken();
return true;
}
switch (context.character) {
case Unicode::CHARACTER_TABULATION:
case Unicode::LINE_FEED:
case Unicode::FORM_FEED:
case Unicode::SPACE:
context.state = HTML::Tokenizer::ParserState::BEFORE_ATTRIBUTE_NAME;
break;
case Unicode::AMPERSAND:
context.returnState = HTML::Tokenizer::ParserState::ATTRIBUTE_VALUE_NQ;
context.state = HTML::Tokenizer::ParserState::CHARACTER_REFERENCE;
break;
case Unicode::GREATER_THAN_SIGN:
context.LogError(HTML::Tokenizer::ParserError::MISSING_ATTRIBUTE_VALUE);
context.state = HTML::Tokenizer::ParserState::DATA;
tokenizer.treeConstructor.EmitToken(context.GetCurrentTagToken());
if (context.isEndTag)
context.startTagToken = HTML::Tokenizer::StartTagToken();
else
context.endTagToken = HTML::Tokenizer::EndTagToken();
break;
case Unicode::NULL_CHARACTER:
context.LogError(HTML::Tokenizer::ParserError::UNEXPECTED_NULL_CHARACTER);
context.GetCurrentTagToken().attributeValue += Unicode::REPLACEMENT_CHARACTER;
break;
default:
if (context.character == Unicode::QUOTATION_MARK || context.character == Unicode::APOSTROPHE
|| context.character == Unicode::LESS_THAN_SIGN || context.character == Unicode::EQUALS_SIGN
|| context.character == Unicode::GRAVE_ACCENT)
context.LogError(HTML::Tokenizer::ParserError::UNEXPECTED_CHARACTER_IN_UNQOUTED_ATTRIBUTE_VALUE);
context.GetCurrentTagToken().attributeValue += context.character;
break;
}
return true;
}