convert method

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

Converts the GBK codeUnits (a list of unsigned 8-bit integers) to the corresponding string.

Uses the code units from start to, but no including, end. If end is omitted, it defaults to codeUnits.length.

If the codeUnits start with the encoding of a unicodeBomCharacterRune, that character is discarded.

Implementation

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

  // Fast case for ASCII strings avoids StringBuffer / decodeMap.
  var oneBytes = _scanOneByteCharacters(codeUnits, start, end);
  StringBuffer? buffer;
  if (oneBytes > 0) {
    var firstPart = String.fromCharCodes(codeUnits, start, start + oneBytes);
    start += oneBytes;
    if (start == end) {
      return firstPart;
    }
    buffer = StringBuffer(firstPart);
  }

  buffer ??= StringBuffer();
  var decoder = _GbkStreamDecoder(buffer, _allowMalformed);
  decoder.convert(codeUnits, start, end);
  decoder.flush(codeUnits, end);
  return buffer.toString();
}