convert method

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

Converts input and returns the result of the conversion.

Implementation

@override
String convert(List<int> input, [int start = 0, int? end]) {
  final usedEnd = RangeError.checkValidRange(start, end, input.length);

  var r = 0;
  var size = 0;
  final nDst = StringBuffer();

  void write(int code) => nDst.write(String.fromCharCode(code));

  for (var nSrc = start; nSrc < usedEnd; nSrc += size) {
    final c0 = input[nSrc];
    if (c0 < 0x80) {
      r = c0;
      size = 1;
    } else if (0x81 <= c0 && c0 < 0xFF) {
      if (nSrc + 1 >= input.length) {
        r = _runeError;
        size = 1;
        write(r);
        continue;
      }
      final c1 = input[nSrc + 1];
      r = 0xfffd;
      size = 2;

      final i = c0 * 16 * 16 + c1;
      final s = _decodeTable[i];
      if (s != null) {
        write(s);
        continue;
      }
    } else if (allowInvalid) {
      r = _runeError;
      size = 1;
    } else {
      throw FormatException('Encountered invalid rune $c0 at position $nSrc');
    }
    write(r);
    continue;
  }
  return nDst.toString();
}