TDME2 1.9.121
StringTokenizer.cpp
Go to the documentation of this file.
1#include <string>
2#include <vector>
3
4#include <tdme/tdme.h>
6
7using std::string;
8
10
11StringTokenizer::StringTokenizer() {
12}
13
14void StringTokenizer::tokenize(const string& str, const string& delimiters)
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]) != -1) {
22 // yep, add token to elements if we have any
23 if (token.length() > 0) {
24 tokens.push_back(token);
25 token = "";
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 (token.length() > 0) {
34 tokens.push_back(token);
35 token = "";
36 }
37}
String tokenizer class.
void tokenize(const string &str, const string &delimiters)
Tokenize.