replacePlaceholders method
Replaces all placeholders in the given value
using the provided placeholderResolver
.
This will parse the value
, resolve all placeholders recursively using
placeholderResolver
, and return the fully interpolated string.
If a placeholder cannot be resolved:
- It uses the fallback (if provided)
- Or throws an error unless configured to ignore unresolvable placeholders
Example:
final parser = PlaceholderParser(r'#{', '}', ':', null, false);
final result = parser.replacePlaceholders('Hi #{name:User}', MyResolver());
print(result); // Hi Alice or Hi User
Implementation
String replacePlaceholders(String value, PlaceholderResolverFn placeholderResolver) {
PlaceholderParsedValue parsedValue = parse(value);
PlaceholderPartResolutionContext resolutionContext = PlaceholderPartResolutionContext(
placeholderResolver,
_prefix,
_suffix,
_ignoreUnresolvablePlaceholders,
(candidate) => _parseWithPlaceholder(candidate, false),
logger,
);
return parsedValue.resolve(resolutionContext);
}