TDME2  1.9.200
StringTokenizer.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
4 #include <tdme/tdme.h>
6 
7 using std::string;
8 
10 
11 StringTokenizer::StringTokenizer() {
12 }
13 
14 void StringTokenizer::tokenize(const string& str, const string& delimiters, bool emptyTokens)
15 {
16  idx = 0;
17  tokens.clear();
18  string token;
19  for (int i = 0; i < str.length(); i++) {
20  // got a delimiter?
21  if (delimiters.find(str[i]) != string::npos) {
22  // yep, add token to elements if we have any
23  if (emptyTokens == true || token.empty() == false) {
24  tokens.push_back(token);
25  token.clear();
26  }
27  } else {
28  // no delimiter, add char to token
29  token+= str[i];
30  }
31  }
32  // do we have a token still? add it to elements
33  if (emptyTokens == true || token.empty() == false) {
34  tokens.push_back(token);
35  }
36 }
String tokenizer class.
void tokenize(const string &str, const string &delimiters, bool emptyTokens=false)
Tokenize.