Parses the string represenatation of a Python tuple into a vector of its items */
| 296 | Parses the string represenatation of a Python tuple into a vector of its items |
| 297 | */ |
| 298 | inline std::vector <std::string> parse_tuple(std::string in) { |
| 299 | std::vector <std::string> v; |
| 300 | const char seperator = ','; |
| 301 | |
| 302 | in = trim(in); |
| 303 | |
| 304 | if ((in.front() == '(') && (in.back() == ')')) |
| 305 | in = in.substr(1, in.length() - 2); |
| 306 | else |
| 307 | throw std::runtime_error("Invalid Python tuple."); |
| 308 | |
| 309 | std::istringstream iss(in); |
| 310 | |
| 311 | for (std::string token; std::getline(iss, token, seperator);) { |
| 312 | v.push_back(token); |
| 313 | } |
| 314 | |
| 315 | return v; |
| 316 | } |
| 317 | |
| 318 | template<typename T> |
| 319 | inline std::string write_tuple(const std::vector <T> &v) { |
no test coverage detected