encodeUtf16Le function

List<int> encodeUtf16Le(
  1. String s
)

Encodes s as UTF-16 little-endian with a leading BOM — the encoding schtasks /Create /XML requires (a UTF-8 file is rejected with "cannot switch encoding").

Implementation

List<int> encodeUtf16Le(String s) {
  final out = <int>[0xFF, 0xFE];
  for (final unit in s.codeUnits) {
    out
      ..add(unit & 0xFF)
      ..add((unit >> 8) & 0xFF);
  }
  return out;
}