splitInterpolation method

  1. @protected
SplitInterpolation? splitInterpolation(
  1. String input,
  2. String location
)

Helper method for implementing parseInterpolation.

Splits a longer multi-expression interpolation into SplitInterpolation.

Implementation

@protected
SplitInterpolation? splitInterpolation(String input, String location) {
  var parts = jsSplit(input, _findInterpolation);
  if (parts.length <= 1) {
    return null;
  }
  var strings = <String>[];
  var expressions = <String>[];
  for (var i = 0; i < parts.length; i++) {
    var part = parts[i];
    if (i.isEven) {
      // fixed string
      strings.add(part);
    } else if (part.trim().isNotEmpty) {
      expressions.add(part);
    } else {
      throw ParseException(
        'Blank expressions are not allowed in interpolated strings',
        input,
        'at column ${_findInterpolationErrorColumn(parts, i)} in',
        location,
      );
    }
  }
  return SplitInterpolation._(strings, expressions);
}