Parses the string represenatation of a Python tuple into a vector of its items */
| 283 | Parses the string represenatation of a Python tuple into a vector of its items |
| 284 | */ |
| 285 | inline std::vector<std::string> parse_tuple(std::string in) { |
| 286 | std::vector<std::string> v; |
| 287 | const char seperator = ','; |
| 288 | |
| 289 | in = trim(in); |
| 290 | |
| 291 | if ((in.front() == '(') && (in.back() == ')')) |
| 292 | in = in.substr(1, in.length() - 2); |
| 293 | else { |
| 294 | fprintf(stderr, "Invalid Python tuple."); |
| 295 | } |
| 296 | |
| 297 | std::istringstream iss(in); |
| 298 | |
| 299 | for (std::string token; std::getline(iss, token, seperator);) { |
| 300 | v.push_back(token); |
| 301 | } |
| 302 | |
| 303 | return v; |
| 304 | } |
| 305 | |
| 306 | template <typename T> |
| 307 | inline std::string write_tuple(const std::vector<T>& v) { |
no test coverage detected