CharMatcher class abstract

Abstract character matcher function.

The CharMatcher is a boolean predicate on Unicode code-points. The inclusion of a character can be determined by calling the char matcher with the code-unit as the function argument, for example:

CharMatcher.whitespace().match(' '.runes.first); // true
CharMatcher.digit().match('a'.runes.first); // 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
Implementers
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 ASCII digits, see UnicodeCharMatcher.numberDecimalDigit for the Unicode variant.
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 ASCII letters, see UnicodeCharMatcher.letter for the Unicode variant.
const
factory
CharMatcher.letterOrDigit()
A matcher that accepts ASCII letters or digits.
const
factory
CharMatcher.lowerCaseLetter()
A matcher that accepts ASCII lower-case letters, see UnicodeCharMatcher.letterLowercase for the Unicode variant.
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.punctuation()
A matcher that accepts ASCII punctuation characters, see UnicodeCharMatcher.punctuation for the Unicode variant.
const
factory
CharMatcher.upperCaseLetter()
A matcher that accepts ASCII upper-case letters, see UnicodeCharMatcher.letterUppercase for the Unicode variant.
const
factory
CharMatcher.whitespace()
A matcher that accepts ASCII whitespace, see UnicodeCharMatcher.whiteSpace for the Unicode variant.
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 sequence, [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.
call(int value) → bool
Determines if the given Unicode code-point value belongs to this character class. See match for details.
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 first 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 Unicode code-point value belongs to this character class.
matchAsPrefix(String sequence, [int start = 0]) → Match?
Matches this pattern against the start of string.
override
noneOf(String sequence) → bool
Returns true if the sequence contains no matching character.
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 Object.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 trailing matching characters in sequence.
trimTrailingFrom(String sequence) → String
Removes trailing matching characters in sequence.

Operators

operator &(CharMatcher other) → CharMatcher
Returns a matcher that matches any character matched by both this matcher and other.
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.