convert method

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

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);
  final startBlock = this.startBlock;
  final startBlockLength = startBlock?.length ?? 0;
  List<int>? modified;
  for (var i = start; i < usedEnd; i++) {
    final byte = input[i];
    if ((byte & ~0xFF) != 0) {
      if (!allowInvalid) {
        throw FormatException('Invalid value in input: $byte '
            'at position $i '
            'in "${String.fromCharCodes(input, start, usedEnd)}"');
      } else {
        modified ??= List.from(input);
        modified[i] = 0xFFFD; // unicode �
      }
    } else if (byte > startIndex) {
      final index = byte - (startIndex + 1);
      modified ??= List.from(input);
      modified[i] = symbols.codeUnitAt(index);
    } else if (byte <= startBlockLength) {
      modified ??= List.from(input);
      modified[i] = startBlock!.codeUnitAt(byte - 1);
    }
  }
  return String.fromCharCodes(modified ?? input, start, end);
}