processArguments static method

String processArguments(
  1. String text,
  2. List<String> args, [
  3. int currentArg = 0
])

Replaces ${...} placeholders in text with args: ${n} takes args[n] when n is a valid index, any other placeholder takes the next unused argument. Substituted text is not processed again.

Implementation

static String processArguments(
  String text,
  List<String> args, [
  int currentArg = 0,
]) {
  if (!text.contains(r'${') || args.length <= currentArg) return text;
  var index = _extractNextIndex(text, args);
  var nextArg = currentArg;
  if (index == -1) {
    index = currentArg;
    nextArg++;
  }
  final start = text.indexOf(r'${');
  final end = text.indexOf('}', start);
  return text.substring(0, start) +
      args[index] +
      processArguments(text.substring(end + 1), args, nextArg);
}