SourceFile.decoded constructor Null safety

SourceFile.decoded(
  1. Iterable<int> decodedChars,
  2. {dynamic url}
)

Creates a new source file from a list of decoded code units.

url may be either a String, a Uri, or null.

Currently, if decodedChars contains characters larger than 0xFFFF, they'll be treated as single characters rather than being split into surrogate pairs. This behavior is deprecated. For forwards-compatibility, callers should only pass in characters less than or equal to 0xFFFF.

Implementation

SourceFile.decoded(Iterable<int> decodedChars, {url})
    : url = url is String ? Uri.parse(url) : url as Uri?,
      _decodedChars = Uint32List.fromList(decodedChars.toList()) {
  for (var i = 0; i < _decodedChars.length; i++) {
    var c = _decodedChars[i];
    if (c == _cr) {
      // Return not followed by newline is treated as a newline
      final j = i + 1;
      if (j >= _decodedChars.length || _decodedChars[j] != _lf) c = _lf;
    }
    if (c == _lf) _lineStarts.add(i + 1);
  }
}