Rev | Line | |
---|
[7] | 1 | |
---|
| 2 | /* |
---|
| 3 | Copyright 2013 Willem Vermin, SURFsara |
---|
| 4 | |
---|
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 6 | you may not use this file except in compliance with the License. |
---|
| 7 | You may obtain a copy of the License at |
---|
| 8 | |
---|
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | |
---|
| 11 | Unless required by applicable law or agreed to in writing, software |
---|
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | See the License for the specific language governing permissions and |
---|
| 15 | limitations under the License. |
---|
| 16 | */ |
---|
| 17 | #include <string> |
---|
| 18 | #include <vector> |
---|
| 19 | // |
---|
| 20 | // splits string s to vector v, using separator character sep |
---|
| 21 | // return value: v |
---|
| 22 | // It seems that it follows the python implementation of split() |
---|
| 23 | // |
---|
| 24 | std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep) |
---|
| 25 | { |
---|
| 26 | v.clear(); |
---|
| 27 | for (size_t p=0, q=0; q != s.npos; p = q + 1) |
---|
| 28 | v.push_back(s.substr(p,(q=s.find(sep,p))-p)); |
---|
| 29 | return v; |
---|
| 30 | } |
---|
| 31 | #if 0 |
---|
| 32 | #include <iostream> |
---|
| 33 | int main() |
---|
| 34 | { |
---|
| 35 | char sep = '/'; |
---|
| 36 | std::string s="/version/command/ /modifier/"; |
---|
| 37 | std::vector <std::string> v; |
---|
| 38 | |
---|
| 39 | v=split(v,s,sep); |
---|
| 40 | for (unsigned i=0; i<v.size(); i++) |
---|
| 41 | std::cout << i << ":" << v[i] << ":" << std::endl; |
---|
| 42 | return 0; |
---|
| 43 | } |
---|
| 44 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.