convert method

String convert (
  1. List<int> bytes,
  2. [int start = 0,
  3. int? end]
)
inherited

Converts the bytes (a list of unsigned 7- or 8-bit integers) to the corresponding string.

If start and end are provided, only the sub-list of bytes from start to end (end not inclusive) is used as input to the conversion.

Implementation

String convert(List<int> bytes, [int start = 0, int? end]) {
  end = RangeError.checkValidRange(start, end, bytes.length);
  // TODO(38725): Remove workaround when assignment promotion is implemented
  if (end == null) {
    throw RangeError("Invalid range");
  }
  for (var i = start; i < end; i++) {
    var byte = bytes[i];
    if ((byte & ~_subsetMask) != 0) {
      if (!_allowInvalid) {
        throw FormatException("Invalid value in input: $byte");
      }
      return _convertInvalid(bytes, start, end);
    }
  }
  return String.fromCharCodes(bytes, start, end);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-convert/Latin1Decoder/convert.html