Interpolator class
Class to parse and cache string template for later interpolation
Initialization with a string template:
const format = "substitution: {sub}; escaping braces: {pre}{suf} placeholder:{unmatched}";
final interpolator = Interpolator(format, {null: "null"});
print(interpolator({"sub": "substituted"}));
//substitution: substituted; escaping braces: {} placeholder:null
Constructors
-
Interpolator(String format, [Map<
String?, dynamic> defaultVal = const {}]) -
Create an Interpolator with
format
and an optional mapdefaultVal
to set the default values of keys. Set the value of keynull
in thedefaultVal
to designate a placeholder to substitute the keys in the string template which do not exist in the provided map, otherwise a FormatException will be thrown when fail to find a key in the map.factory -
Interpolator.noEscape(String format, [Map<
String?, dynamic> defaultVal = const {}]) -
All the same to the Interpolator constructor except this one crates an
interpolator which does not escape the braces.
factory
Properties
Methods
-
call<
V> (Map< String?, V> subs) → String -
Perform interpolation on early parsed string template with
subs
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
retrieve(
String input) → Map< String, String> -
Retrieve values from an interpolated string
input
Use with care since values may contain the same patterns that divide values -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited