| 1427 | /// |
| 1428 | /// Array of strings |
| 1429 | public String[] split(String s) { |
| 1430 | // Create new vector |
| 1431 | ArrayList v = new ArrayList(); |
| 1432 | |
| 1433 | // Start at position 0 and search the whole string |
| 1434 | int pos = 0; |
| 1435 | int len = s.length(); |
| 1436 | |
| 1437 | // Try a match at each position |
| 1438 | while (pos < len && match(s, pos)) { |
| 1439 | // Get start of match |
| 1440 | int start = getParenStart(0); |
| 1441 | |
| 1442 | // Get end of match |
| 1443 | int newpos = getParenEnd(0); |
| 1444 | |
| 1445 | // Check if no progress was made |
| 1446 | if (newpos == pos) { |
| 1447 | v.add(s.substring(pos, start + 1)); |
| 1448 | newpos++; |
| 1449 | } else { |
| 1450 | v.add(s.substring(pos, start)); |
| 1451 | } |
| 1452 | |
| 1453 | // Move to new position |
| 1454 | pos = newpos; |
| 1455 | } |
| 1456 | |
| 1457 | // Push remainder if it's not empty |
| 1458 | String remainder = s.substring(pos); |
| 1459 | if (remainder.length() != 0) { |
| 1460 | v.add(remainder); |
| 1461 | } |
| 1462 | |
| 1463 | // Return vector as an array of strings |
| 1464 | String[] ret = new String[v.size()]; |
| 1465 | v.toArray(ret); |
| 1466 | return ret; |
| 1467 | } |
| 1468 | |
| 1469 | /// Substitutes a string for this regular expression in another string. |
| 1470 | /// This method works like the Perl function of the same name. |