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)
| 915 | |
| 916 | |
| 917 | public String trimFrom(CharSequence sequence) { |
| 918 | int len = sequence.length(); |
| 919 | int first; |
| 920 | int last; |
| 921 | for (first = 0; first < len; first++) { |
| 922 | if (!matches(sequence.charAt(first))) { |
| 923 | break; |
| 924 | } |
| 925 | } |
| 926 | for (last = len - 1; last > first; last--) { |
| 927 | if (!matches(sequence.charAt(last))) { |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | return sequence.subSequence(first, last + 1).toString(); |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Returns a substring of the input character sequence that omits all characters this matcher |