Returns a string containing all non-matching characters of a character sequence, in order. For example: CharMatcher.is('a').removeFrom("bazaar") ... returns "bzr".
(CharSequence sequence)
| 693 | * ... returns {@code "bzr"}. |
| 694 | */ |
| 695 | public String removeFrom(CharSequence sequence) { |
| 696 | String string = sequence.toString(); |
| 697 | int pos = indexIn(string); |
| 698 | if (pos == -1) { |
| 699 | return string; |
| 700 | } |
| 701 | |
| 702 | char[] chars = string.toCharArray(); |
| 703 | int spread = 1; |
| 704 | |
| 705 | // This unusual loop comes from extensive benchmarking |
| 706 | OUT: |
| 707 | while (true) { |
| 708 | pos++; |
| 709 | while (true) { |
| 710 | if (pos == chars.length) { |
| 711 | break OUT; |
| 712 | } |
| 713 | if (matches(chars[pos])) { |
| 714 | break; |
| 715 | } |
| 716 | chars[pos - spread] = chars[pos]; |
| 717 | pos++; |
| 718 | } |
| 719 | spread++; |
| 720 | } |
| 721 | return new String(chars, 0, pos - spread); |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Returns a string containing all matching characters of a character sequence, in order. For |
no test coverage detected