menu
  1. Dart
  2. dart:convert
  3. Utf8Decoder class
Utf8Decoder

Utf8Decoder class final

This class converts UTF-8 code units (lists of unsigned 8-bit integers) to a string.

Example:

final utf8Decoder = utf8.decoder;
const encodedBytes = [
 195, 142, 195, 177, 197, 163, 195, 169, 114, 195, 177, 195, 165, 197,
 163, 195, 174, 195, 182, 195, 177, 195, 165, 196, 188, 195, 174, 197,
 190, 195, 165, 197, 163, 195, 174, 225, 187, 157, 195, 177];
final decodedBytes = utf8Decoder.convert(encodedBytes);
print(decodedBytes); // Îñţérñåţîöñåļîžåţîờñ

Throws a FormatException if the encoded input contains invalid UTF-8 byte sequences and allowMalformed is false (the default).

If allowMalformed is true, invalid byte sequences are converted into one or more Unicode replacement characters, U+FFFD ('�').

Example with allowMalformed set to true:

const utf8Decoder = Utf8Decoder(allowMalformed: true);
const encodedBytes = [0xFF];
final decodedBytes = utf8Decoder.convert(encodedBytes);
print(decodedBytes); // �
Inheritance

Constructors

Utf8Decoder.new ({bool allowMalformed = false})
Instantiates a new Utf8Decoder.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

bind (Stream <List <int >> stream) Stream <String >
Transforms the provided stream.
override
cast <RS, RT>() Converter <RS, RT>
Provides a Converter<RS, RT> view of this stream transformer.
inherited
convert (List <int > codeUnits, [int start = 0, int? end]) String
Converts the UTF-8 codeUnits (a list of unsigned 8-bit integers) to the corresponding string.
override
fuse <T>(Converter <String , T> next) Converter <List <int >, T>
Fuses this with other.
override
noSuchMethod (Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startChunkedConversion (Sink <String > sink) ByteConversionSink
Starts a chunked conversion.
override
toString () String
A string representation of this object.
inherited

Operators

operator == (Object other) bool
The equality operator.
inherited
dart:convert library

AltStyle によって変換されたページ (->オリジナル) /