| 1476 | } |
| 1477 | |
| 1478 | Vector<String> String::rsplit(const String& p_splitter, bool p_allow_empty, int p_maxsplit) const |
| 1479 | { |
| 1480 | Vector<String> ret; |
| 1481 | const int len = length(); |
| 1482 | int remaining_len = len; |
| 1483 | |
| 1484 | while (true) |
| 1485 | { |
| 1486 | if (remaining_len < p_splitter.length() || (p_maxsplit > 0 && p_maxsplit == ret.size())) |
| 1487 | { |
| 1488 | // no room for another splitter or hit max splits, push what's left and we're done |
| 1489 | if (p_allow_empty || remaining_len > 0) |
| 1490 | { |
| 1491 | ret.push_back(substr(0, remaining_len)); |
| 1492 | } |
| 1493 | break; |
| 1494 | } |
| 1495 | |
| 1496 | int left_edge; |
| 1497 | if (p_splitter.is_empty()) |
| 1498 | { |
| 1499 | left_edge = remaining_len - 1; |
| 1500 | if (left_edge == 0) |
| 1501 | { |
| 1502 | left_edge--; // Skip to the < 0 condition. |
| 1503 | } |
| 1504 | } |
| 1505 | else |
| 1506 | { |
| 1507 | left_edge = rfind(p_splitter, remaining_len - p_splitter.length()); |
| 1508 | } |
| 1509 | |
| 1510 | if (left_edge < 0) |
| 1511 | { |
| 1512 | // no more splitters, we're done |
| 1513 | ret.push_back(substr(0, remaining_len)); |
| 1514 | break; |
| 1515 | } |
| 1516 | |
| 1517 | int substr_start = left_edge + p_splitter.length(); |
| 1518 | if (p_allow_empty || substr_start < remaining_len) |
| 1519 | { |
| 1520 | ret.push_back(substr(substr_start, remaining_len - substr_start)); |
| 1521 | } |
| 1522 | |
| 1523 | remaining_len = left_edge; |
| 1524 | } |
| 1525 | |
| 1526 | ret.reverse(); |
| 1527 | return ret; |
| 1528 | } |
| 1529 | |
| 1530 | Vector<double> String::split_floats(const String& p_splitter, bool p_allow_empty) const |
| 1531 | { |
no test coverage detected