-
Notifications
You must be signed in to change notification settings - Fork 0
/
strtoken.cpp
42 lines (42 loc) · 1.21 KB
/
strtoken.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 "strtoken.h"
bool StringTokenizer::isItTokenizer(char input){
for(int i=0;(unsigned)i<tokenizers.size();i++){
if(tokenizers[i]==input)return true;
}
return false;
}
std::string StringTokenizer::charToString(char input){
char returnValue[2];
returnValue[0]=input;
returnValue[1]='\0';
return std::string(returnValue);
}
StringTokenizer::StringTokenizer(std::string mainString,std::string tokenizerChars){
tokenizers=tokenizerChars;
std::string temp;
for(int i=0;(unsigned)i<mainString.size();i++){
if(isItTokenizer(mainString[i])){
if(temp!="")
tokens.push_back(temp);
temp="";
}else{
temp=temp+charToString(mainString[i]);
}
}
if(temp!="")
tokens.push_back(temp);
}
std::vector<std::string> StringTokenizer::getAllTokens(){
return tokens;
}
std::string StringTokenizer::operator[](int input) const{
if(input<0)return std::string();
if((unsigned)input<tokens.size()){
return tokens[input];
}else{
return std::string();
}
}
std::vector<std::string>::size_type StringTokenizer::size(){
return tokens.size();
}