decodeUtf16 function

String decodeUtf16(
  1. List<int> bytes, [
  2. int offset = 0,
  3. int? length,
  4. int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
])

Produce a String from a sequence of UTF-16 encoded bytes. This method always strips a leading BOM. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for the replacementCodepoint is U+FFFD.

Implementation

String decodeUtf16(List<int> bytes,
    [int offset = 0,
    int? length,
    int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
  var decoder =
      Utf16BytesToCodeUnitsDecoder(bytes, offset, length, replacementCodepoint);
  var codeunits = decoder.decodeRest();
  return String.fromCharCodes(
      utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint)
          .whereType<int>());
}