processNamedArguments static method
Replaces ${name} in text with values from args; unknown names
are left as is. Substituted text is not processed again.
Implementation
static String processNamedArguments(String text, Map<String, String> args) {
var result = text;
var i = result.indexOf(r'${');
while (i != -1) {
var j = result.indexOf('}', i);
if (j == -1) break; // unterminated ${...}
final value = args[result.substring(i + 2, j)];
if (value != null) {
result = result.substring(0, i) + value + result.substring(j + 1);
j = i + value.length - 1;
}
i = result.indexOf(r'${', j + 1);
}
return result;
}