-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.cpp
93 lines (74 loc) · 2.72 KB
/
Token.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Template by Ali A. Kooshesh on 1/27/21.
// Additional Code by Garret Mook on 02/06/21.
#include <iostream>
#include <iomanip>
#include "Token.hpp"
Token::Token(int line, int pos): _isOpenTag{false},
_isCloseTag{false},
_isCloseAngleBracket{false},
_isCloseStandAloneTag{false},
_tagName{""},
_eof{false},
_lineNumber{line},
_charPos{pos},
_eol{false},
_isSlash{false} {}
bool &Token::isOpenTag() { return _isOpenTag; }
bool &Token::isCloseTag() { return _isCloseTag; }
bool &Token::isCloseAngleBracket() { return _isCloseAngleBracket; }
bool &Token::endOfFile() { return _eof; }
bool &Token::isCloseStandAloneTag() { return _isCloseStandAloneTag; }
bool &Token::isSlash() { return _isSlash; }
std::string Token::tagName() { return _tagName; }
bool &Token::eol(){
return _eol;
}
void Token::makeOpenTag(std::string name) {
_tagName = name;
isOpenTag() = true;
}
std::string Token::makeOpenTag() {
return _tagName;
}
void Token::makeCloseTag(std::string name) {
_tagName = name;
isCloseTag() = true;
}
/*
void Token::print() {
std::cout << "[" << std::setw(2) << _lineNumber << ", " << std::setw(3) << _charPos << "] ";
if(isOpenTag()) {
std::cout << "<" << tagName() << std::endl;
} else if(isCloseStandAloneTag()) {
std::cout << "/>" << std::endl;
} else if(isCloseAngleBracket()) {
std::cout << ">" << std::endl;
} else if(isCloseTag()) {
std::cout << "</" << tagName() << std::endl;
} else if(isSlash() ) {
}
else {// more else if's before this else
std::cout << "Unknown" << std::endl;
}
}
*/
void Token::print() {
if(isOpenTag()) {
std::cout << "[" << std::setw(2) << _lineNumber << ", " << std::setw(3) << _charPos << "] ";
std::cout << "<" << tagName() << std::endl;
} else if(isCloseStandAloneTag()) {
std::cout << "[" << std::setw(2) << _lineNumber << ", " << std::setw(3) << _charPos << "] ";
std::cout << "/>" << std::endl;
} else if(isCloseAngleBracket()) {
std::cout << "[" << std::setw(2) << _lineNumber << ", " << std::setw(3) << _charPos << "] ";
std::cout << ">" << std::endl;
} else if(isCloseTag()) {
std::cout << "[" << std::setw(2) << _lineNumber << ", " << std::setw(3) << _charPos << "] ";
std::cout << "</" << tagName() << std::endl;
} else if(isSlash() ) {
}
else {// more else if's before this else
std::cout << "Unknown" << std::endl;
}
}