PlaceholderParser class final
A utility class for parsing and resolving placeholders within a string.
Supports placeholder expressions of the form:
Hello, #{user.name:Guest}! —> // Output: Hello, Alice! if user.name resolves to "Alice"
or "Hello, Guest!" if it does not.
Supports nested placeholders and fallback values:
#{app.title:#{default.title:MyApp}}
Example usage:
final parser = PlaceholderParser(r'#{', '}', ':', r'\', false);
final result = parser.replacePlaceholders('Welcome #{user.name:Guest}', MyResolver());
print(result); // Welcome Alice or Welcome Guest
You can control:
- Prefix/suffix (e.g.,
#{...}
or[[...]]
) - Escape characters (e.g.,
\#{...}
to skip parsing) - Fallback separator (e.g.,
:
or|
) - Whether to ignore unresolvable placeholders
Constructors
- PlaceholderParser(String _prefix, String _suffix, String? _separator, Character? _escape, bool _ignoreUnresolvablePlaceholders)
- A utility class for parsing and resolving placeholders within a string.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createSimplePlaceholderPart(
String text) → SimplePlaceholderPart -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parse(
String value) → PlaceholderParsedValue -
Parses the given
value
into a PlaceholderParsedValue structure without resolving it. -
replacePlaceholders(
String value, PlaceholderResolverFn placeholderResolver) → String -
Replaces all placeholders in the given
value
using the providedplaceholderResolver
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- logger → Log
-
final
-
wellKnownSimplePrefixes
→ Map<
String, String> -
final