@Testpublicvoidremove_all_lower_case_from_string(){StringallButLowerCase=CharMatcher.JAVA_LOWER_CASE.negate().retainFrom("B-double E double R U-N beer run");assertEquals("B- E R U-N ",allButLowerCase);}
Trim leading spaces
@Testpublicvoidtrim_leading_spaces_from_string(){StringleftTrimmedString=CharMatcher.WHITESPACE.trimLeadingFrom(" Some String ");assertEquals("Some String ",leftTrimmedString);}
Trim trailing spaces
@Testpublicvoidtrim_trailing_spaces_from_string(){StringrightTrimmedString=CharMatcher.WHITESPACE.trimTrailingFrom(" Some String ");assertEquals(" Some String",rightTrimmedString);}
Trim all spaces
@Testpublicvoidtrim_all_spaces_from_string(){StringtrimmedString=CharMatcher.WHITESPACE.trimFrom(" Some String ");assertEquals("Some String",trimmedString);}
Remove all * from string
@Testpublicvoidremove_all_asterisk_from_string(){StringstringWithoutAstricks=CharMatcher.is('*').removeFrom("(* This is a comment. The compiler will ignore it. *)");assertEquals("( This is a comment. The compiler will ignore it. )",stringWithoutAstricks);}
@Testpublicvoidobtain_digits_from_telephone_number(){StringtelephoneNumber=CharMatcher.inRange('0','9').retainFrom("123-456-7890");assertEquals("1234567890",telephoneNumber);// worried about performanceCharMatcherdigits=CharMatcher.inRange('0','9').precomputed();StringteleNumber=digits.retainFrom("123-456-7890");assertEquals("1234567890",teleNumber);}
@Testpublicvoidcollapse_whitespace_dash(){Stringaddress="505 Williams Street";StringaddressWithDash=CharMatcher.WHITESPACE.collapseFrom(address,'-');assertEquals("505-Williams-Street",addressWithDash);}