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

Method removeFrom

output/java_guava/1.4.13/CharMatcher.java:777–804  ·  view source on GitHub ↗

Returns a string containing all non-matching characters of a character sequence, in order. For example: CharMatcher.is('a').removeFrom("bazaar") ... returns "bzr".

(CharSequence sequence)

Source from the content-addressed store, hash-verified

775
776
777 public String removeFrom(CharSequence sequence) {
778 String string = sequence.toString();
779 int pos = indexIn(string);
780 if (pos == -1) {
781 return string;
782 }
783
784 char[] chars = string.toCharArray();
785 int spread = 1;
786
787 // This unusual loop comes from extensive benchmarking
788 OUT:
789 while (true) {
790 pos++;
791 while (true) {
792 if (pos == chars.length) {
793 break OUT;
794 }
795 if (matches(chars[pos])) {
796 break;
797 }
798 chars[pos - spread] = chars[pos];
799 pos++;
800 }
801 spread++;
802 }
803 return new String(chars, 0, pos - spread);
804 }
805
806 /**
807 * Returns a string containing all matching characters of a character sequence, in order. For

Callers 2

replaceFromMethod · 0.95
retainFromMethod · 0.45

Calls 4

indexInMethod · 0.95
matchesMethod · 0.95
toStringMethod · 0.65
toCharArrayMethod · 0.45

Tested by

no test coverage detected