MCPcopy Create free account
hub / github.com/antlr/codebuff / trimFrom

Method trimFrom

corpus/java/training/guava/base/CharMatcher.java:829–846  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

matchesMethod · 0.95
toStringMethod · 0.65
lengthMethod · 0.45

Tested by

no test coverage detected