encodeUtf32Le method

List<int> encodeUtf32Le(
  1. String str, [
  2. bool writeBOM = false
])

Produce a list of UTF-32LE encoded bytes. By default, this method produces UTF-32BE bytes with no BOM.

Implementation

List<int> encodeUtf32Le(String str, [bool writeBOM = false]) {
  var utf32CodeUnits = stringToCodepoints(str);
  var encoding = List<int>.filled(
    4 * utf32CodeUnits.length + (writeBOM ? 4 : 0),
    0,
  );
  var i = 0;
  if (writeBOM) {
    encoding[i++] = unicodeUtfBomLo;
    encoding[i++] = unicodeUtfBomHi;
    encoding[i++] = 0;
    encoding[i++] = 0;
  }
  for (var unit in utf32CodeUnits) {
    encoding[i++] = unit & unicodeByteZeroMask;
    encoding[i++] = (unit >> 8) & unicodeByteZeroMask;
    encoding[i++] = (unit >> 16) & unicodeByteZeroMask;
    encoding[i++] = (unit >> 24) & unicodeByteZeroMask;
  }
  return encoding;
}