capTimerValues static method

String capTimerValues(
  1. String content,
  2. TimerRewriteConfig config, {
  3. int? maxNumberOfTimes,
})

Implementation

static String capTimerValues(
  String content,
  TimerRewriteConfig config, {
  int? maxNumberOfTimes,
}) {
  final startAfter =
      RegExp(r'^(\s*startAfter:\s*)(\d+)(\s*)$', multiLine: true);
  final repeatInterval = RegExp(
    r'^(\s*repeatInterval:\s*)(\d+)(\s*)$',
    multiLine: true,
  );
  final maxNumberOfTimesPattern = RegExp(
    r'^(\s*maxNumberOfTimes:\s*)(\d+)(\s*)$',
    multiLine: true,
  );
  var rewritten = content
      .replaceAllMapped(
        startAfter,
        (match) => _capTimerLine(match, config.maxStartAfterSeconds),
      )
      .replaceAllMapped(
        repeatInterval,
        (match) => _capTimerLine(match, config.maxRepeatIntervalSeconds),
      );
  final maxTimes = maxNumberOfTimes ?? config.maxNumberOfTimes;
  if (maxTimes != null) {
    rewritten = rewritten.replaceAllMapped(
      maxNumberOfTimesPattern,
      (match) => _capTimerLine(match, maxTimes),
    );
  }
  return rewritten;
}