| 437 | } |
| 438 | |
| 439 | vector<string> |
| 440 | TfStringSplit(string const &src, string const &separator) |
| 441 | { |
| 442 | vector<string> split; |
| 443 | |
| 444 | if (src.empty()) |
| 445 | return split; |
| 446 | |
| 447 | // XXX python throws a ValueError in this case, we exit silently. |
| 448 | if (separator.empty()) |
| 449 | return split; |
| 450 | |
| 451 | size_t from=0; |
| 452 | size_t pos=0; |
| 453 | |
| 454 | while (true) { |
| 455 | pos = src.find(separator, from); |
| 456 | if (pos == string::npos) |
| 457 | break; |
| 458 | split.push_back(src.substr(from, pos-from)); |
| 459 | from = pos + separator.size(); |
| 460 | } |
| 461 | |
| 462 | // Also add the 'last' substring |
| 463 | split.push_back(src.substr(from)); |
| 464 | |
| 465 | return split; |
| 466 | } |
| 467 | |
| 468 | vector<string> |
| 469 | TfStringTokenize(string const &src, const char* delimiters) |