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)
| 775 | |
| 776 | |
| 777 | public String removeFrom(CharSequence sequence) { |
| 778 | String string = sequence.toString(); |
| 779 | int pos = indexIn(string); |
| 780 | if (pos == -1) { |
| 781 | return string; |
| 782 | } |
| 783 | |
| 784 | char[] chars = string.toCharArray(); |
| 785 | int spread = 1; |
| 786 | |
| 787 | // This unusual loop comes from extensive benchmarking |
| 788 | OUT: |
| 789 | while (true) { |
| 790 | pos++; |
| 791 | while (true) { |
| 792 | if (pos == chars.length) { |
| 793 | break OUT; |
| 794 | } |
| 795 | if (matches(chars[pos])) { |
| 796 | break; |
| 797 | } |
| 798 | chars[pos - spread] = chars[pos]; |
| 799 | pos++; |
| 800 | } |
| 801 | spread++; |
| 802 | } |
| 803 | return new String(chars, 0, pos - spread); |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Returns a string containing all matching characters of a character sequence, in order. For |
no test coverage detected