forked from yangjiaolong/Go-ICP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringTokenizer.cpp
51 lines (40 loc) · 1.16 KB
/
StringTokenizer.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 <iostream>
#include "StringTokenizer.hpp"
StringTokenizer::StringTokenizer() {
};
StringTokenizer::StringTokenizer(std::string str, char delim) {
int delim_loc;
while ((delim_loc = str.find_first_of(delim,0)) != std::string::npos) {
if (str.substr(0, delim_loc).length() > 0) {
tokens.push_back(str.substr(0,delim_loc));
}
str = str.substr(delim_loc+1, str.length());
}
if (str.length() > 0) {
tokens.push_back(str);
}
};
StringTokenizer::StringTokenizer(std::string str, char * delims) {
int delim_loc;
while ((delim_loc = str.find_first_of(delims,0)) != std::string::npos) {
if (str.substr(0, delim_loc).length() > 0) {
tokens.push_back(str.substr(0,delim_loc));
}
str = str.substr(delim_loc+1, str.length());
}
if (str.length() > 0) tokens.push_back(str);
};
StringTokenizer::~StringTokenizer() {
};
std::string StringTokenizer::nextToken() {
if (!hasMoreTokens()) return "";
std::string return_str(tokens.front());
tokens.pop_front();
return return_str;
};
bool StringTokenizer::hasMoreTokens() {
return !tokens.empty();
};
int StringTokenizer::numberOfTokens() {
return tokens.size();
};