decodeUtf16 function
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>());
}