Returns a string containing all non-matching characters of a character sequence, in order. For example: {@snippet : CharMatcher.is('a').removeFrom("bazaar") } ... returns {@code "bzr"}.
(CharSequence sequence)
| 616 | * ... returns {@code "bzr"}. |
| 617 | */ |
| 618 | public String removeFrom(CharSequence sequence) { |
| 619 | String string = sequence.toString(); |
| 620 | int pos = indexIn(string); |
| 621 | if (pos == -1) { |
| 622 | return string; |
| 623 | } |
| 624 | |
| 625 | char[] chars = string.toCharArray(); |
| 626 | int spread = 1; |
| 627 | |
| 628 | // This unusual loop comes from extensive benchmarking |
| 629 | OUT: |
| 630 | while (true) { |
| 631 | pos++; |
| 632 | while (true) { |
| 633 | if (pos == chars.length) { |
| 634 | break OUT; |
| 635 | } |
| 636 | if (matches(chars[pos])) { |
| 637 | break; |
| 638 | } |
| 639 | chars[pos - spread] = chars[pos]; |
| 640 | pos++; |
| 641 | } |
| 642 | spread++; |
| 643 | } |
| 644 | return new String(chars, 0, pos - spread); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Returns a string containing all matching BMP characters of a character sequence, in order. For |