Class CharMatcher.None

All Implemented Interfaces:
Predicate<Character>, Predicate<Character>
Enclosing class:
CharMatcher

private static final class CharMatcher.None extends CharMatcher.NamedFastMatcher
Implementation of CharMatcher.none().
  • Field Details

  • Constructor Details

    • None

      private None()
  • Method Details

    • matches

      public boolean matches(char c)
      Description copied from class: CharMatcher
      Determines a true or false value for the given character.
      Specified by:
      matches in class CharMatcher
    • indexIn

      public int indexIn(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns the index of the first matching BMP character in a character sequence, or -1 if no matching character is present.

      The default implementation iterates over the sequence in forward order calling CharMatcher.matches(char) for each character.

      Overrides:
      indexIn in class CharMatcher
      Parameters:
      sequence - the character sequence to examine from the beginning
      Returns:
      an index, or -1 if no character matches
    • indexIn

      public int indexIn(CharSequence sequence, int start)
      Description copied from class: CharMatcher
      Returns the index of the first matching BMP character in a character sequence, starting from a given position, or -1 if no character matches after that position.

      The default implementation iterates over the sequence in forward order, beginning at start, calling CharMatcher.matches(char) for each character.

      Overrides:
      indexIn in class CharMatcher
      Parameters:
      sequence - the character sequence to examine
      start - the first index to examine; must be nonnegative and no greater than sequence.length()
      Returns:
      the index of the first matching character, guaranteed to be no less than start, or -1 if no character matches
    • lastIndexIn

      public int lastIndexIn(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns the index of the last matching BMP character in a character sequence, or -1 if no matching character is present.

      The default implementation iterates over the sequence in reverse order calling CharMatcher.matches(char) for each character.

      Overrides:
      lastIndexIn in class CharMatcher
      Parameters:
      sequence - the character sequence to examine from the end
      Returns:
      an index, or -1 if no character matches
    • matchesAllOf

      public boolean matchesAllOf(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns true if a character sequence contains only matching BMP characters.

      The default implementation iterates over the sequence, invoking CharMatcher.matches(char) for each character, until this returns false or the end is reached.

      Overrides:
      matchesAllOf in class CharMatcher
      Parameters:
      sequence - the character sequence to examine, possibly empty
      Returns:
      true if this matcher matches every character in the sequence, including when the sequence is empty
    • matchesNoneOf

      public boolean matchesNoneOf(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns true if a character sequence contains no matching BMP characters. Equivalent to !matchesAnyOf(sequence).

      The default implementation iterates over the sequence, invoking CharMatcher.matches(char) for each character, until this returns true or the end is reached.

      Overrides:
      matchesNoneOf in class CharMatcher
      Parameters:
      sequence - the character sequence to examine, possibly empty
      Returns:
      true if this matcher matches no characters in the sequence, including when the sequence is empty
    • removeFrom

      public String removeFrom(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns a string containing all non-matching characters of a character sequence, in order. For example:
      
       CharMatcher.is('a').removeFrom("bazaar")
       
      ... returns "bzr".
      Overrides:
      removeFrom in class CharMatcher
    • replaceFrom

      public String replaceFrom(CharSequence sequence, char replacement)
      Description copied from class: CharMatcher
      Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement character. For example:
      
       CharMatcher.is('a').replaceFrom("radar", 'o')
       
      ... returns "rodor".

      The default implementation uses CharMatcher.indexIn(CharSequence) to find the first matching character, then iterates the remainder of the sequence calling CharMatcher.matches(char) for each character.

      Overrides:
      replaceFrom in class CharMatcher
      Parameters:
      sequence - the character sequence to replace matching characters in
      replacement - the character to append to the result string in place of each matching character in sequence
      Returns:
      the new string
    • replaceFrom

      public String replaceFrom(CharSequence sequence, CharSequence replacement)
      Description copied from class: CharMatcher
      Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement sequence. For example:
      
       CharMatcher.is('a').replaceFrom("yaha", "oo")
       
      ... returns "yoohoo".

      Note: If the replacement is a fixed string with only one character, you are better off calling CharMatcher.replaceFrom(CharSequence, char) directly.

      Overrides:
      replaceFrom in class CharMatcher
      Parameters:
      sequence - the character sequence to replace matching characters in
      replacement - the characters to append to the result string in place of each matching character in sequence
      Returns:
      the new string
    • collapseFrom

      public String collapseFrom(CharSequence sequence, char replacement)
      Description copied from class: CharMatcher
      Returns a string copy of the input character sequence, with each group of consecutive matching BMP characters replaced by a single replacement character. For example:
      
       CharMatcher.anyOf("eko").collapseFrom("bookkeeper", '-')
       
      ... returns "b-p-r".

      The default implementation uses CharMatcher.indexIn(CharSequence) to find the first matching character, then iterates the remainder of the sequence calling CharMatcher.matches(char) for each character.

      Overrides:
      collapseFrom in class CharMatcher
      Parameters:
      sequence - the character sequence to replace matching groups of characters in
      replacement - the character to append to the result string in place of each group of matching characters in sequence
      Returns:
      the new string
    • trimFrom

      public String trimFrom(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns a substring of the input character sequence that omits all matching BMP characters from the beginning and from the end of the string. For example:
      
       CharMatcher.anyOf("ab").trimFrom("abacatbab")
       
      ... returns "cat".

      Note that:

      
       CharMatcher.inRange('\0', ' ').trimFrom(str)
       
      ... is equivalent to String.trim().
      Overrides:
      trimFrom in class CharMatcher
    • trimLeadingFrom

      public String trimLeadingFrom(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns a substring of the input character sequence that omits all matching BMP characters from the beginning of the string. For example:
      
       CharMatcher.anyOf("ab").trimLeadingFrom("abacatbab")
       
      ... returns "catbab".
      Overrides:
      trimLeadingFrom in class CharMatcher
    • trimTrailingFrom

      public String trimTrailingFrom(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns a substring of the input character sequence that omits all matching BMP characters from the end of the string. For example:
      
       CharMatcher.anyOf("ab").trimTrailingFrom("abacatbab")
       
      ... returns "abacat".
      Overrides:
      trimTrailingFrom in class CharMatcher
    • countIn

      public int countIn(CharSequence sequence)
      Description copied from class: CharMatcher
      Returns the number of matching chars found in a character sequence.

      Counts 2 per supplementary character, such as for CharMatcher.whitespace()().CharMatcher.negate()().

      Overrides:
      countIn in class CharMatcher
    • and

      public CharMatcher and(CharMatcher other)
      Description copied from class: CharMatcher
      Returns a matcher that matches any character matched by both this matcher and other.
      Overrides:
      and in class CharMatcher
    • or

      public CharMatcher or(CharMatcher other)
      Description copied from class: CharMatcher
      Returns a matcher that matches any character matched by either this matcher or other.
      Overrides:
      or in class CharMatcher
    • negate

      public CharMatcher negate()
      Description copied from class: CharMatcher
      Returns a matcher that matches any character not matched by this matcher.
      Specified by:
      negate in interface Predicate<Character>
      Overrides:
      negate in class CharMatcher.FastMatcher