replacePlaceholders function Null safety

String replacePlaceholders(
  1. String input,
  2. Map<String, String> variables,
  3. RegExp rexprVariable
)

Replaces placeholders in a string with values stored in a map. input: the input string [variables: a map containing (placeholder, value) pairs rexprVariable a regular expression for one variable. The variable name must be in group(1) returns: the input string with the replaced placeholders

Implementation

String replacePlaceholders(
    String input, Map<String, String> variables, RegExp rexprVariable) {
  var rc = input;
  for (var matcher in rexprVariable.allMatches(input)) {
    final name = matcher.group(1);
    if (!variables.containsKey(name)) {
      _logger.error(
          'replaceVariables(): unknown placeholder $name in ${limitString(input, 40)}');
    } else {
      rc = rc.replaceAll(matcher.group(0)!, variables[name]!);
    }
  }
  return rc;
}