replaceRegionInText function

String replaceRegionInText(
  1. List regions,
  2. String text
)

Implementation

String replaceRegionInText(List regions, String text) {
  var replaced = text;
  num offset = 0;
  regions.forEach((region) {
    var length = region['end'] - region['start'] + 1;
    var replaceWith = '${getNumber(region)}';
    replaced = splice(replaced, region['start'] + offset, length, replaceWith);
    offset -= length - replaceWith.length;
  });
  return replaced;
}