format method

String format(
  1. List<Object> args
)

Format a string.

Implementation

String format(List<Object> args) {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  return this!.replaceAllMapped(RegExp(r'\{(\d+)\}'), (match) {
    final index = int.parse(match.group(1)!);
    if (index < 0 || index >= args.length) {
      throw ArgumentError('index: $index, length: ${args.length}');
    }
    return args[index].toString();
  });
}