CharMatcher and - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for CharMatcher and method.

This code example shows how to use the following methods:and
            // We need to allow the \u0000 delimiter for JSON messages, so we 
            // can't use the JAVA_ISO_CONTROL character set and must build the 
            // range manually (minus \u0000) 
            .and(CharMatcher.inRange('\u0001', '\u001f').negate())
            .and(CharMatcher.inRange('\u007f', '\u009f').negate())
            .and(CharMatcher.ASCII)
            .matchesAllOf(buffer);
    } 
 
    @Override 
    public VehicleMessage parseNextMessage() { 
        String line = readToDelimiter();
        if(line != null) {
            try { 
                return JsonFormatter.deserialize(line);
            } catch(UnrecognizedMessageTypeException e) {
                Log.w(TAG, "Unable to deserialize JSON", e);
            } 
        } 
        return null; 
5
CodeRank
This code example shows how to use the following methods:and
        assertThat(CharMatcher.DIGIT.or(CharMatcher.WHITESPACE).retainFrom("Hello 1234 567")).isEqualTo(" 1234 567");
    } 
 
    @Test
    public void shouldRetainNothingAsConstrainsAreExcluding() throws Exception {
        assertThat(CharMatcher.DIGIT.and(CharMatcher.JAVA_LETTER).retainFrom("Hello 1234 567")).isEqualTo("");
    } 
 
    @Test
    public void shouldRetainLettersAndDigits() throws Exception {
        assertThat(CharMatcher.DIGIT.or(CharMatcher.JAVA_LETTER).retainFrom("Hello 1234 567")).isEqualTo("Hello1234567");
    } 
 
    @Test
    public void shouldCollapseAllDigitsByX() throws Exception {
        assertThat(CharMatcher.DIGIT.collapseFrom("Hello 1234 567", 'x')).isEqualTo("Hello x x");
    } 
 
     @Test
    public void shouldReplaceAllDigitsByX() throws Exception {
3
CodeRank
and Method Overview
Returns a matcher that matches any character matched by both this matcher and other.
See Code Examples for other Guava CharMatcher Methods: