-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.cpp
More file actions
44 lines (35 loc) · 762 Bytes
/
Copy pathtoken.cpp
File metadata and controls
44 lines (35 loc) · 762 Bytes
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
#include "token.h"
#include <cstring>
Token::Token(TokenType type_, CharIter begin_, CharIter end_)
: type(type_), value(begin_, end_)
{}
bool Token::isUnknown() const
{
return type == TokenType::unknown;
}
void Token::clear()
{
type = TokenType::unknown; value = CharRange();
}
std::size_t Token::length() const
{
return std::distance(value.begin, value.end);
}
bool Token::compare(const char *str) const
{
int len = strlen(str);
if (len == 0)
return false;
std::size_t i = 0;
auto iter = value.begin;
for (; i < len && iter != value.end; ++i, ++iter)
{
if (str[i] != *iter)
return false;
}
return true;
}
std::string Token::toString() const
{
return value.toString();
}