CharMatcher class abstract

Abstract character matcher function.

The CharMatcher is a boolean predicate on UTF-16 code units. The inclusion of a character can be determined by calling match with the code-unit as the function argument, for example:

CharMatcher.whitespace().match(' '.codeUnitAt(0)); // true
CharMatcher.digit().match('a'.codeUnitAt(0)); // false

A large collection of helper methods let you perform string operations on the occurrences of the specified class of characters: trimming, collapsing, replacing, removing, retaining, etc. For example:

String withoutWhitespace = CharMatcher.whitespace().removeFrom(string);
String onlyDigits = CharMatcher.digit().retainFrom(string);
Implemented types
Mixed in types
Annotations
  • @immutable

Constructors

CharMatcher()
Internal constructor.
const
CharMatcher.any()
A matcher that accepts any character.
const
factory
CharMatcher.ascii()
A matcher that accepts ASCII characters.
const
factory
CharMatcher.charSet(String chars)
A matcher that accepts a set of characters.
factory
CharMatcher.digit()
A matcher that accepts digits.
const
factory
CharMatcher.inRange(Object start, Object stop)
A matcher that accepts a character range from start to stop.
factory
CharMatcher.isChar(Object character)
A matcher that accepts a single character.
factory
CharMatcher.letter()
A matcher that accepts letters.
const
factory
CharMatcher.letterOrDigit()
A matcher that accepts letters or digits.
const
factory
CharMatcher.lowerCaseLetter()
A matcher that accepts lower-case letters.
const
factory
CharMatcher.none()
A matcher that accepts no character.
const
factory
CharMatcher.pattern(String pattern)
A matcher that accepts a regular expression character class.
factory
CharMatcher.upperCaseLetter()
A matcher that accepts upper-case letters.
const
factory
CharMatcher.whitespace()
A matcher that accepts whitespaces.
const
factory

Properties

defaultToStringPrinter ObjectPrinter
Override to configure the empty ObjectPrinter.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
toStringPrinter ObjectPrinter
Override and call super to add values to the ObjectPrinter.
no setterinherited

Methods

allMatches(String string, [int start = 0]) Iterable<Match>
Matches this pattern against the string repeatedly.
override
anyOf(String sequence) bool
Returns true if the sequence contains at least one matching character.
collapseFrom(String sequence, String replacement) String
Replaces each group of consecutive matched characters in sequence with the specified replacement.
countIn(String sequence) int
Counts the number of matches in sequence.
everyOf(String sequence) bool
Returns true if the sequence contains only matching characters.
firstIndexIn(String sequence, [int start = 0]) int
Returns the last matching index in sequence starting at start (inclusive). Returns -1 if it could not be found.
lastIndexIn(String sequence, [int? start]) int
Returns the first matching index in sequence, searching backward starting at start (inclusive). Returns -1 if it could not be found.
match(int value) bool
Determines if the given character code belongs to the character class.
matchAsPrefix(String string, [int start = 0]) Match?
Matches this pattern against the start of string.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeFrom(String sequence) String
Removes all matched characters in sequence.
replaceFrom(String sequence, String replacement) String
Replaces each matched character in sequence with the specified replacement.
retainFrom(String sequence) String
Retains all matched characters in sequence.
toString() String
Standard toString implementation. Do not override, instead implement toStringPrinter to customize.
inherited
trimFrom(String sequence) String
Removes leading and trailing matching characters in sequence.
trimLeadingFrom(String sequence) String
Removes leading matching characters in sequence.
trimTailingFrom(String sequence) String
Removes tailing matching characters in sequence.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator |(CharMatcher other) CharMatcher
Returns a matcher that matches any character matched by either this matcher or other.
operator ~() CharMatcher
Returns a matcher that matches any character not matched by this matcher.