encodeUtf32le function

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 = <int?>[]..length =
      4 * utf32CodeUnits.length + (writeBOM ? 4 : 0);
  var i = 0;
  if (writeBOM) {
    encoding[i++] = UNICODE_UTF_BOM_LO;
    encoding[i++] = UNICODE_UTF_BOM_HI;
    encoding[i++] = 0;
    encoding[i++] = 0;
  }
  for (var unit in utf32CodeUnits) {
    encoding[i++] = unit! & UNICODE_BYTE_ZERO_MASK;
    encoding[i++] = (unit >> 8) & UNICODE_BYTE_ZERO_MASK;
    encoding[i++] = (unit >> 16) & UNICODE_BYTE_ZERO_MASK;
    encoding[i++] = (unit >> 24) & UNICODE_BYTE_ZERO_MASK;
  }
  return encoding;
}