-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer.cpp
executable file
·42 lines (39 loc) · 969 Bytes
/
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
#include "tokenizer.h"
#include "nomoretokensexception.h"
#include <QString>
#include <QStringList>
Tokenizer::Tokenizer() : index(0)
{
}
Tokenizer::Tokenizer(QString string, QString delimiters){
for(int i=1 ; i<delimiters.length() ; i++){
string.replace(delimiters.at(i),delimiters.at(0));
}
tokens = string.split(delimiters.at(0), QString::SkipEmptyParts);
index = 0;
}
QString Tokenizer::nextToken(){
if(index < tokens.size()){
return (QString)tokens.at(index++);
}else{
// throw NoMoreTokensExeception();
return QString();
}
}
QStringList Tokenizer::getAllTokens(){
return tokens;
}
void Tokenizer::forward(int steps){
index += steps;
}
QString Tokenizer::seeNextToken(){
if(index < tokens.length()){
return tokens.at(index);
}else{
return QString();
// throw NoMoreTokensException();
}
}
bool Tokenizer::hasMoreTokens(){
return index < tokens.length();
}