blob: 3f8cf3320051f26c6c3ec8002c3c35dec510dbf0 (
plain)
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
|
/**
* @brief tokenizer
*
*/
#ifndef string_tokenizer_h
#define string_tokenizer_h
#include <string>
#include <vector>
using namespace std;
static vector<string> string_tokenizer(const string &base_string, const string &delims)
{
vector<string> tokens;
// Skip delimiters at beginning.
string::size_type last_pos = base_string.find_first_not_of(delims, 0);
// find first "non-delimiter".
string::size_type pos = base_string.find_first_of(delims, last_pos);
while (string::npos != pos || string::npos != last_pos) {
// found a token, add it to the vector.
tokens.push_back(base_string.substr(last_pos, pos - last_pos));
// skip delimiters.
last_pos = base_string.find_first_not_of(delims, pos);
// find next "non-delimiter"
pos = base_string.find_first_of(delims, last_pos);
}
return tokens;
}
#endif
|