toUtf8 function
Converts UTF-8 character code points to 8-bit UTF-8 octet sequence.
Parameters:
inputis a sequence of UTF-8 character code points.codecis the UTF8Codec to use.
Throws:
- FormatException if the
inputcontains unpaired surrogates.
Unlike the encoder from dart:convert, which replaces unpaired surrogates
with the replacement character U+FFFD, this implementation rejects them.
Implementation
Uint8List toUtf8(
String input, {
UTF8Codec codec = UTF8Codec.standard,
}) {
var out = codec.encoder.convert(input.codeUnits);
return out is Uint8List ? out : Uint8List.fromList(out);
}