-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenizer.cpp
51 lines (47 loc) · 1.19 KB
/
tokenizer.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
#include "tokenizer.h"
tokenizer::iterator& tokenizer::iterator::operator++()
{
text_begin = text_end;
if (text_end >= obj->text.size())
{
is_valid = false;
return *this;
}
for (int i = text_begin; i < obj->text.size(); ++i)
{
char c = obj->text[i];
if (contains(obj->remember, c))
{
text_end = i + (i == text_begin);
substr = obj->text.substr(text_begin, text_end - text_begin);
return *this;
}
else if (contains(obj->forget, c))
{
if (i == text_begin)
{
++text_begin;
}
else
{
text_end = i;
substr = obj->text.substr(text_begin, text_end - text_begin);
return *this;
}
}
}
text_end = obj->text.size();
substr = obj->text.substr(text_begin, text_end - text_begin);
return *this;
}
bool tokenizer::iterator::operator!= (const iterator& b) const
{
if ((!b.is_valid) && (!is_valid))
{
return false;
}
else
{
return !(obj == b.obj && text_begin == b.text_begin && text_end == b.text_end);
}
}