interpolateAsync static method

Future<String> interpolateAsync(
  1. String input,
  2. ConsumerSupplierFunction<String, Future<String?>> callback
)

Interpolate {} tokens in the input string, but asynchronously

Implementation

static Future<String> interpolateAsync(String input, ConsumerSupplierFunction<String, Future<String?> > callback) async
{
  StringBuffer replaced = new StringBuffer();
  int currentIndex = 0;
  for (Match match in _INTERPOLATE_REGEXP.allMatches(input))
  {
    String prefix = match.input.substring(currentIndex, match.start);
    currentIndex = match.end;
    replaced.write(prefix);
    String key = match.group(1)!;
    replaced.write( await callback(key) ?? ella.EMPTY_STRING );
  }
  replaced.write(input.substring(currentIndex));
  return replaced.toString();
}