encodeUtf16Le method

Uint8List encodeUtf16Le(
  1. String str, [
  2. bool writeBOM = false
])

encode utf-16 LE format

Implementation

Uint8List encodeUtf16Le(String str, [bool writeBOM = false]) {
  var utf16CodeUnits = codepointsToUtf16CodeUnits(str.codeUnits);
  var encoding = Uint8List(2 * utf16CodeUnits.length + (writeBOM ? 2 : 0));
  var i = 0;
  if (writeBOM) {
    encoding[i++] = unicodeUtfBomLo;
    encoding[i++] = unicodeUtfBomHi;
  }
  for (var unit in utf16CodeUnits) {
    encoding[i++] = unit & unicodeByteZeroMask;
    encoding[i++] = (unit & unicodeByteOneMask) >> 8;
  }
  return encoding;
}