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.
constfactory
- CharMatcher.ascii()
-
A matcher that accepts ASCII characters.
constfactory
- 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.
constfactory
- CharMatcher.inRange(Object start, Object stop)
-
A matcher that accepts a character range from
start
tostop
.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.
constfactory
- CharMatcher.letterOrDigit()
-
A matcher that accepts ASCII letters or digits.
constfactory
- CharMatcher.lowerCaseLetter()
-
A matcher that accepts ASCII lower-case letters, see
UnicodeCharMatcher.letterLowercase for the Unicode variant.
constfactory
- CharMatcher.none()
-
A matcher that accepts no character.
constfactory
- 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.
constfactory
- CharMatcher.upperCaseLetter()
-
A matcher that accepts ASCII upper-case letters, see
UnicodeCharMatcher.letterUppercase for the Unicode variant.
constfactory
- CharMatcher.whitespace()
-
A matcher that accepts ASCII whitespaces, see
UnicodeCharMatcher.whiteSpace for the Unicode variant.
constfactory
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 thesequence
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 specifiedreplacement
. -
countIn(
String sequence) → int -
Counts the number of matches in
sequence
. -
everyOf(
String sequence) → bool -
Returns
true
if thesequence
contains only matching characters. -
firstIndexIn(
String sequence, [int start = 0]) → int -
Returns the first matching index in
sequence
starting atstart
(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 atstart
(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 thesequence
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 specifiedreplacement
. -
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 &(
CharMatcher other) → CharMatcher -
Returns a matcher that matches any character matched by either this
matcher or
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.