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

Method trimAndCollapseFrom

output/java_guava/1.4.19/CharMatcher.java:1019–1033  ·  view source on GitHub ↗

Collapses groups of matching characters exactly as #collapseFrom does, except that groups of matching characters at the start or end of the sequence are removed without replacement.

(CharSequence sequence, char replacement)

Source from the content-addressed store, hash-verified

1017
1018
1019 public String trimAndCollapseFrom(CharSequence sequence, char replacement) {
1020 // This implementation avoids unnecessary allocation.
1021 int len = sequence.length();
1022 int first = 0;
1023 int last = len - 1;
1024 while (first < len && matches(sequence.charAt(first))) {
1025 first++;
1026 }
1027 while (last > first && matches(sequence.charAt(last))) {
1028 last--;
1029 }
1030 return (first == 0 && last == len - 1)
1031 ? collapseFrom(sequence, replacement)
1032 : finishCollapseFrom(sequence, first, last + 1, replacement, new StringBuilder(last + 1 - first), false);
1033 }
1034
1035 private String finishCollapseFrom(
1036 CharSequence sequence,

Callers

nothing calls this directly

Calls 4

matchesMethod · 0.95
collapseFromMethod · 0.95
finishCollapseFromMethod · 0.95
lengthMethod · 0.45

Tested by

no test coverage detected