MCPcopy
hub / github.com/google/guava / removeFrom

Method removeFrom

guava/src/com/google/common/base/CharMatcher.java:618–645  ·  view source on GitHub ↗

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

(CharSequence sequence)

Source from the content-addressed store, hash-verified

616 * ... returns {@code "bzr"}.
617 */
618 public String removeFrom(CharSequence sequence) {
619 String string = sequence.toString();
620 int pos = indexIn(string);
621 if (pos == -1) {
622 return string;
623 }
624
625 char[] chars = string.toCharArray();
626 int spread = 1;
627
628 // This unusual loop comes from extensive benchmarking
629 OUT:
630 while (true) {
631 pos++;
632 while (true) {
633 if (pos == chars.length) {
634 break OUT;
635 }
636 if (matches(chars[pos])) {
637 break;
638 }
639 chars[pos - spread] = chars[pos];
640 pos++;
641 }
642 spread++;
643 }
644 return new String(chars, 0, pos - spread);
645 }
646
647 /**
648 * Returns a string containing all matching BMP characters of a character sequence, in order. For

Callers 9

replaceFromMethod · 0.95
retainFromMethod · 0.45
reallyTestEmptyMethod · 0.45
reallyTestNoMatchesMethod · 0.45
reallyTestAllMatchesMethod · 0.45

Calls 4

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

Tested by 7

reallyTestEmptyMethod · 0.36
reallyTestNoMatchesMethod · 0.36
reallyTestAllMatchesMethod · 0.36