toUtf8 function

Uint8List toUtf8(
  1. String input, {
  2. UTF8Codec codec = UTF8Codec.standard,
})

Converts UTF-8 character code points to 8-bit UTF-8 octet sequence.

Parameters:

  • input is a sequence of UTF-8 character code points.
  • codec is the UTF8Codec to use.

Throws:

Unlike the encoder from dart:convert, which replaces unpaired surrogates with the replacement character U+FFFD, this implementation rejects them.

Implementation

@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
Uint8List toUtf8(
  String input, {
  UTF8Codec codec = UTF8Codec.standard,
}) =>
    codec.encoder.convert(input.codeUnits);