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