build method

  1. @override
String build(
  1. Context context,
  2. String name,
  3. List<String> arguments
)
inherited

Implementation

@override
String build(Context context, String name, List<String> arguments) {
  checkArguments(['c'], arguments, getChars());
  final argument = arguments.first;
  final list = getCharList();
  final tests = <String>[];
  var simple = true;
  for (var i = 0; i < list.length; i += 2) {
    if (list[i] != list[i + 1]) {
      simple = false;
      break;
    }
  }

  if (negate && simple) {
    var count = 0;
    for (var i = 0; i < list.length; i += 2) {
      final start = list[i];
      tests.add('$argument != $start');
      count++;
    }

    var result = tests.join(' && ');
    if (count > 3) {
      final last = list.last;
      result = '$argument > $last || $result';
    }

    return result;
  } else if (negate && list.length == 2) {
    final start = list[0];
    final end = list[1];
    final result = '$argument < $start && $argument > $end';
    return result;
  } else if (negate) {
    var count = 0;
    for (var i = 0; i < list.length; i += 2) {
      final start = list[i];
      final end = list[i + 1];
      if (start == end) {
        tests.add('$argument == $start');
        count++;
      } else {
        tests.add('$argument >= $start && $argument <= $end');
        count += 2;
      }
    }

    var result = tests.join(' || ');
    if (count > 3) {
      final last = list.last;
      result = '$argument > $last || !($result)';
    } else {
      result = '!($result)';
    }

    return result;
  } else {
    var count = 0;
    for (var i = 0; i < list.length; i += 2) {
      final start = list[i];
      final end = list[i + 1];
      if (start == end) {
        tests.add('$argument == $start');
        count++;
      } else {
        tests.add('$argument >= $start && $argument <= $end');
        count += 2;
      }
    }

    var result = tests.join(' || ');
    if (count > 3) {
      final last = list.last;
      result = '$argument <= $last && ($result)';
    }

    return result;
  }
}