Returns a substring of the input character sequence that omits all characters this matcher matches from the beginning and from the end of the string. For example: CharMatcher.anyOf("ab").trimFrom("abacatbab") ... returns "cat". Note that: {@code CharM
(CharSequence sequence)
| 827 | * ... is equivalent to {@link String#trim()}. |
| 828 | */ |
| 829 | public String trimFrom(CharSequence sequence) { |
| 830 | int len = sequence.length(); |
| 831 | int first; |
| 832 | int last; |
| 833 | |
| 834 | for (first = 0; first < len; first++) { |
| 835 | if (!matches(sequence.charAt(first))) { |
| 836 | break; |
| 837 | } |
| 838 | } |
| 839 | for (last = len - 1; last > first; last--) { |
| 840 | if (!matches(sequence.charAt(last))) { |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | return sequence.subSequence(first, last + 1).toString(); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Returns a substring of the input character sequence that omits all characters this matcher |