| 1414 | } |
| 1415 | |
| 1416 | Vector<String> String::split(const String& p_splitter, bool p_allow_empty, int p_maxsplit) const |
| 1417 | { |
| 1418 | Vector<String> ret; |
| 1419 | |
| 1420 | if (is_empty()) |
| 1421 | { |
| 1422 | if (p_allow_empty) |
| 1423 | { |
| 1424 | ret.push_back(""); |
| 1425 | } |
| 1426 | return ret; |
| 1427 | } |
| 1428 | |
| 1429 | int from = 0; |
| 1430 | int len = length(); |
| 1431 | |
| 1432 | while (true) |
| 1433 | { |
| 1434 | int end; |
| 1435 | if (p_splitter.is_empty()) |
| 1436 | { |
| 1437 | end = from + 1; |
| 1438 | } |
| 1439 | else |
| 1440 | { |
| 1441 | end = find(p_splitter, from); |
| 1442 | if (end < 0) |
| 1443 | { |
| 1444 | end = len; |
| 1445 | } |
| 1446 | } |
| 1447 | if (p_allow_empty || (end > from)) |
| 1448 | { |
| 1449 | if (p_maxsplit <= 0) |
| 1450 | { |
| 1451 | ret.push_back(substr(from, end - from)); |
| 1452 | } |
| 1453 | else |
| 1454 | { |
| 1455 | // Put rest of the string and leave cycle. |
| 1456 | if (p_maxsplit == ret.size()) |
| 1457 | { |
| 1458 | ret.push_back(substr(from, len)); |
| 1459 | break; |
| 1460 | } |
| 1461 | |
| 1462 | // Otherwise, push items until positive limit is reached. |
| 1463 | ret.push_back(substr(from, end - from)); |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | if (end == len) |
| 1468 | { |
| 1469 | break; |
| 1470 | } |
| 1471 | |
| 1472 | from = end + p_splitter.length(); |
| 1473 | } |
no test coverage detected