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

Method trimAndCollapseFrom

output/java_guava/1.4.13/CharMatcher.java:1021–1037  ·  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

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