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

Method removeFrom

corpus/java/training/guava/base/CharMatcher.java:695–722  ·  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

693 * ... returns {@code "bzr"}.
694 */
695 public String removeFrom(CharSequence sequence) {
696 String string = sequence.toString();
697 int pos = indexIn(string);
698 if (pos == -1) {
699 return string;
700 }
701
702 char[] chars = string.toCharArray();
703 int spread = 1;
704
705 // This unusual loop comes from extensive benchmarking
706 OUT:
707 while (true) {
708 pos++;
709 while (true) {
710 if (pos == chars.length) {
711 break OUT;
712 }
713 if (matches(chars[pos])) {
714 break;
715 }
716 chars[pos - spread] = chars[pos];
717 pos++;
718 }
719 spread++;
720 }
721 return new String(chars, 0, pos - spread);
722 }
723
724 /**
725 * Returns a string containing all matching characters of a character sequence, in order. For

Callers 4

replaceFromMethod · 0.95
canDecodeMethod · 0.45
decodeToMethod · 0.45
retainFromMethod · 0.45

Calls 4

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

Tested by

no test coverage detected