Line | |
---|
1 | #include <string> |
---|
2 | #include <vector> |
---|
3 | // |
---|
4 | // splits string s to vector v, using separator character sep |
---|
5 | // return value: v |
---|
6 | // It seems that it follows the python implementation of split() |
---|
7 | // |
---|
8 | std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep) |
---|
9 | { |
---|
10 | v.clear(); |
---|
11 | for (size_t p=0, q=0; q != s.npos; p = q + 1) |
---|
12 | v.push_back(s.substr(p,(q=s.find(sep,p))-p)); |
---|
13 | return v; |
---|
14 | } |
---|
15 | #if 0 |
---|
16 | #include <iostream> |
---|
17 | int main() |
---|
18 | { |
---|
19 | char sep = '/'; |
---|
20 | std::string s="/version/command/ /modifier/"; |
---|
21 | std::vector <std::string> v; |
---|
22 | |
---|
23 | v=split(v,s,sep); |
---|
24 | for (unsigned i=0; i<v.size(); i++) |
---|
25 | std::cout << i << ":" << v[i] << ":" << std::endl; |
---|
26 | return 0; |
---|
27 | } |
---|
28 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.