encodeUtf16le function
Produce a list of UTF-16LE encoded bytes. By default, this method produces UTF-16LE bytes with no BOM.
Implementation
List<int?> encodeUtf16le(String str, [bool writeBOM = false]) {
var utf16CodeUnits = _stringToUtf16CodeUnits(str);
var encoding = <int?>[]..length =
2 * utf16CodeUnits.length + (writeBOM ? 2 : 0);
var i = 0;
if (writeBOM) {
encoding[i++] = UNICODE_UTF_BOM_LO;
encoding[i++] = UNICODE_UTF_BOM_HI;
}
for (var unit in utf16CodeUnits) {
encoding[i++] = unit! & UNICODE_BYTE_ZERO_MASK;
encoding[i++] = (unit & UNICODE_BYTE_ONE_MASK) >> 8;
}
return encoding;
}