Line | |
---|
1 | #include <string> |
---|
2 | #include <vector> |
---|
3 | #include <string.h> |
---|
4 | #include "utils.h" |
---|
5 | // |
---|
6 | // splits string s to vector v, using separator character sep |
---|
7 | // return value: v |
---|
8 | // It seems that it follows the python implementation of split() |
---|
9 | // |
---|
10 | std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep) |
---|
11 | { |
---|
12 | v.clear(); |
---|
13 | for (size_t p=0, q=0; q != s.npos; p = q + 1) |
---|
14 | v.push_back(s.substr(p,(q=s.find(sep,p))-p)); |
---|
15 | return v; |
---|
16 | } |
---|
17 | |
---|
18 | // converts string to char * |
---|
19 | // resulting string is created using malloc. Use free to free. |
---|
20 | char* str_to_charp(const std::string s) |
---|
21 | { |
---|
22 | return strdup(s.c_str()); |
---|
23 | } |
---|
24 | |
---|
Note: See
TracBrowser
for help on using the repository browser.