dart.utf


Top-Level Variables
UNICODE_BOM: int
UNICODE_BYTE_ONE_MASK: int
UNICODE_BYTE_ZERO_MASK: int
UNICODE_PLANE_ONE_MAX: int
UNICODE_REPLACEMENT_CHARACTER_CODEPOINT: int
UNICODE_UTF16_HI_MASK: int
UNICODE_UTF16_LO_MASK: int
UNICODE_UTF16_OFFSET: int
UNICODE_UTF16_RESERVED_HI: int
UNICODE_UTF16_RESERVED_LO: int
UNICODE_UTF16_SURROGATE_UNIT_0_BASE: int
UNICODE_UTF16_SURROGATE_UNIT_1_BASE: int
UNICODE_UTF_BOM_HI: int
UNICODE_UTF_BOM_LO: int
UNICODE_VALID_RANGE_MAX: int
Functions
codepointsToString(List<int> codepoints): String
codepointsToUtf8(List<int> codepoints, int offset, int length): List<int>
decodeUtf16(List<int> bytes, int offset, int length, int replacementCodepoint): String
decodeUtf16AsIterable(List<int> bytes, int offset, int length, int replacementCodepoint): IterableUtf16Decoder
decodeUtf16be(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): String
decodeUtf16beAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): IterableUtf16Decoder
decodeUtf16le(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): String
decodeUtf16leAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): IterableUtf16Decoder
decodeUtf32(List<int> bytes, int offset, int length, int replacementCodepoint): String
decodeUtf32AsIterable(List<int> bytes, int offset, int length, int replacementCodepoint): IterableUtf32Decoder
decodeUtf32be(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): String
decodeUtf32beAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): IterableUtf32Decoder
decodeUtf32le(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): String
decodeUtf32leAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint): IterableUtf32Decoder
decodeUtf8(List<int> bytes, int offset, int length, int replacementCodepoint): String
decodeUtf8AsIterable(List<int> bytes, int offset, int length, int replacementCodepoint): IterableUtf8Decoder
encodeUtf16(String str): List<int>
encodeUtf16be(String str, bool writeBOM): List<int>
encodeUtf16le(String str, bool writeBOM): List<int>
encodeUtf32(String str): List<int>
encodeUtf32be(String str, bool writeBOM): List<int>
encodeUtf32le(String str, bool writeBOM): List<int>
encodeUtf8(String str): List<int>
hasUtf16Bom(List<int> utf32EncodedBytes, int offset, int length): bool
hasUtf16beBom(List<int> utf16EncodedBytes, int offset, int length): bool
hasUtf16leBom(List<int> utf16EncodedBytes, int offset, int length): bool
hasUtf32Bom(List<int> utf32EncodedBytes, int offset, int length): bool
hasUtf32beBom(List<int> utf32EncodedBytes, int offset, int length): bool
hasUtf32leBom(List<int> utf32EncodedBytes, int offset, int length): bool
stringToCodepoints(String str): List<int>
utf8ToCodepoints(List<int> utf8EncodedBytes, int offset, int length, int replacementCodepoint): List<int>
Typedefs
Utf32BytesDecoderProvider(): Utf32BytesDecoder
Classes
IterableUtf16Decoder
IterableUtf32Decoder
IterableUtf8Decoder
Utf16BytesToCodeUnitsDecoder
Utf16CodeUnitDecoder
Utf16beBytesToCodeUnitsDecoder
Utf16leBytesToCodeUnitsDecoder
Utf32BytesDecoder
Utf32beBytesDecoder
Utf32leBytesDecoder
Utf8Decoder
Utf8DecoderTransformer
Utf8EncoderTransformer

Support for encoding and decoding Unicode characters in UTF-8, UTF-16, and UTF-32.

Top-Level Variables

static const int UNICODE_BOM = 65279
static const int UNICODE_BYTE_ONE_MASK = 65280
static const int UNICODE_BYTE_ZERO_MASK = 255
static const int UNICODE_PLANE_ONE_MAX = 65535
static const int UNICODE_REPLACEMENT_CHARACTER_CODEPOINT = 65533

Invalid codepoints or encodings may be substituted with the value U+fffd.

static const int UNICODE_UTF16_HI_MASK = 1047552
static const int UNICODE_UTF16_LO_MASK = 1023
static const int UNICODE_UTF16_OFFSET = 65536
static const int UNICODE_UTF16_RESERVED_HI = 57343
static const int UNICODE_UTF16_RESERVED_LO = 55296
static const int UNICODE_UTF16_SURROGATE_UNIT_0_BASE = 55296
static const int UNICODE_UTF16_SURROGATE_UNIT_1_BASE = 56320
static const int UNICODE_UTF_BOM_HI = 254
static const int UNICODE_UTF_BOM_LO = 255
static const int UNICODE_VALID_RANGE_MAX = 1114111

Functions

static String codepointsToString(List<int> codepoints)

Generate a string from the provided Unicode codepoints.

Deprecated Use String.fromCharCodes instead.

static List<int> codepointsToUtf8(List<int> codepoints, int offset, int length)

Encode code points as UTF-8 code units.

static String decodeUtf16(List<int> bytes, int offset, int length, int replacementCodepoint)

Produce a String from a sequence of UTF-16 encoded bytes. This method always strips a leading BOM. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for the replacementCodepoint is U+FFFD.

static IterableUtf16Decoder decodeUtf16AsIterable(List<int> bytes, int offset, int length, int replacementCodepoint)

Decodes the UTF-16 bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. Determines the byte order from the BOM, or uses big-endian as a default. This method always strips a leading BOM. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for replacementCodepoint is U+FFFD.

static String decodeUtf16be(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Produce a String from a sequence of UTF-16BE encoded bytes. This method strips a leading BOM by default, but can be overridden by setting the optional parameter stripBom to false. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for the replacementCodepoint is U+FFFD.

static IterableUtf16Decoder decodeUtf16beAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Decodes the UTF-16BE bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. This method strips a leading BOM by default, but can be overridden by setting the optional parameter stripBom to false. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for the replacementCodepoint is U+FFFD.

static String decodeUtf16le(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Produce a String from a sequence of UTF-16LE encoded bytes. This method strips a leading BOM by default, but can be overridden by setting the optional parameter stripBom to false. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for the replacementCodepoint is U+FFFD.

static IterableUtf16Decoder decodeUtf16leAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Decodes the UTF-16LE bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. This method strips a leading BOM by default, but can be overridden by setting the optional parameter stripBom to false. Set the replacementCodepoint to null to throw an ArgumentError rather than replace the bad value. The default value for the replacementCodepoint is U+FFFD.

static String decodeUtf32(List<int> bytes, int offset, int length, int replacementCodepoint)

Produce a String from a sequence of UTF-32 encoded bytes. The parameters allow an offset into a list of bytes (as int), limiting the length of the values be decoded and the ability of override the default Unicode replacement character. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static IterableUtf32Decoder decodeUtf32AsIterable(List<int> bytes, int offset, int length, int replacementCodepoint)

Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. Determines the byte order from the BOM, or uses big-endian as a default. This method always strips a leading BOM. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static String decodeUtf32be(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Produce a String from a sequence of UTF-32BE encoded bytes. The parameters allow an offset into a list of bytes (as int), limiting the length of the values be decoded and the ability of override the default Unicode replacement character. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static IterableUtf32Decoder decodeUtf32beAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Decodes the UTF-32BE bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. This method strips a leading BOM by default, but can be overridden by setting the optional parameter stripBom to false. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static String decodeUtf32le(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Produce a String from a sequence of UTF-32LE encoded bytes. The parameters allow an offset into a list of bytes (as int), limiting the length of the values be decoded and the ability of override the default Unicode replacement character. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static IterableUtf32Decoder decodeUtf32leAsIterable(List<int> bytes, int offset, int length, bool stripBom, int replacementCodepoint)

Decodes the UTF-32LE bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. This method strips a leading BOM by default, but can be overridden by setting the optional parameter stripBom to false. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static String decodeUtf8(List<int> bytes, int offset, int length, int replacementCodepoint)

Produce a String from a List of UTF-8 encoded bytes. The parameters can set an offset into a list of bytes (as int), limit the length of the values to be decoded, and override the default Unicode replacement character. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static IterableUtf8Decoder decodeUtf8AsIterable(List<int> bytes, int offset, int length, int replacementCodepoint)

Decodes the UTF-8 bytes as an iterable. Thus, the consumer can only convert as much of the input as needed. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

static List<int> encodeUtf16(String str)

Produce a list of UTF-16 encoded bytes. This method prefixes the resulting bytes with a big-endian byte-order-marker.

static List<int> encodeUtf16be(String str, bool writeBOM)

Produce a list of UTF-16BE encoded bytes. By default, this method produces UTF-16BE bytes with no BOM.

static List<int> encodeUtf16le(String str, bool writeBOM)

Produce a list of UTF-16LE encoded bytes. By default, this method produces UTF-16LE bytes with no BOM.

static List<int> encodeUtf32(String str)

Produce a list of UTF-32 encoded bytes. This method prefixes the resulting bytes with a big-endian byte-order-marker.

static List<int> encodeUtf32be(String str, bool writeBOM)

Produce a list of UTF-32BE encoded bytes. By default, this method produces UTF-32BE bytes with no BOM.

static List<int> encodeUtf32le(String str, bool writeBOM)

Produce a list of UTF-32LE encoded bytes. By default, this method produces UTF-32BE bytes with no BOM.

static List<int> encodeUtf8(String str)

Produce a sequence of UTF-8 encoded bytes from the provided string.

static bool hasUtf16Bom(List<int> utf32EncodedBytes, int offset, int length)

Identifies whether a List of bytes starts (based on offset) with a byte-order marker (BOM).

static bool hasUtf16beBom(List<int> utf16EncodedBytes, int offset, int length)

Identifies whether a List of bytes starts (based on offset) with a big-endian byte-order marker (BOM).

static bool hasUtf16leBom(List<int> utf16EncodedBytes, int offset, int length)

Identifies whether a List of bytes starts (based on offset) with a little-endian byte-order marker (BOM).

static bool hasUtf32Bom(List<int> utf32EncodedBytes, int offset, int length)

Identifies whether a List of bytes starts (based on offset) with a byte-order marker (BOM).

static bool hasUtf32beBom(List<int> utf32EncodedBytes, int offset, int length)

Identifies whether a List of bytes starts (based on offset) with a big-endian byte-order marker (BOM).

static bool hasUtf32leBom(List<int> utf32EncodedBytes, int offset, int length)

Identifies whether a List of bytes starts (based on offset) with a little-endian byte-order marker (BOM).

static List<int> stringToCodepoints(String str)

Provide a list of Unicode codepoints for a given string.

static List<int> utf8ToCodepoints(List<int> utf8EncodedBytes, int offset, int length, int replacementCodepoint)

Typedefs

typedef Utf32BytesDecoder Utf32BytesDecoderProvider():

Class IterableUtf16Decoder extends IterableBase<int>

Fields
codeunitsProvider: _CodeUnitsProvider
iterator: Utf16CodeUnitDecoder
replacementCodepoint: int
Getters and Setters
iterator: Utf16CodeUnitDecoder

Return type of decodeUtf16AsIterable and variants. The Iterable type provides an iterator on demand and the iterator will only translate bytes as requested by the user of the iterator. (Note: results are not cached.)

Fields

final _CodeUnitsProvider codeunitsProvider
final Utf16CodeUnitDecoder iterator
final int replacementCodepoint

Getters and Setters

Utf16CodeUnitDecoder get iterator

Class IterableUtf32Decoder extends IterableBase<int>

Fields
codeunitsProvider: Utf32BytesDecoderProvider
iterator: Utf32BytesDecoder
Getters and Setters
iterator: Utf32BytesDecoder

Return type of decodeUtf32AsIterable and variants. The Iterable type provides an iterator on demand and the iterator will only translate bytes as requested by the user of the iterator. (Note: results are not cached.)

Fields

final Utf32BytesDecoderProvider codeunitsProvider
final Utf32BytesDecoder iterator

Getters and Setters

Utf32BytesDecoder get iterator

Class IterableUtf8Decoder extends IterableBase<int>

Fields
bytes: List
iterator: Utf8Decoder
length: int
offset: int
replacementCodepoint: int
Getters and Setters
iterator: Utf8Decoder
Constructors
IterableUtf8Decoder(List<int> bytes, int offset, int length, int replacementCodepoint)

Return type of decodeUtf8AsIterable and variants. The Iterable type provides an iterator on demand and the iterator will only translate bytes as requested by the user of the iterator. (Note: results are not cached.)

Fields

final List bytes
final Utf8Decoder iterator
final int length
final int offset
final int replacementCodepoint

Getters and Setters

Utf8Decoder get iterator

Constructors

IterableUtf8Decoder(List<int> bytes, int offset, int length, int replacementCodepoint)

Abstract class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator

Fields
current: int
position: int
remaining: int
replacementCodepoint: int
utf16EncodedBytesIterator: _ListRangeIterator
Getters and Setters
current: int
position: int
remaining: int
Constructors
Utf16BytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, int offset, int length, int replacementCodepoint)
Methods
backup(int by): void
decode(): int
decodeRest(): List<int>
moveNext(): bool
skip(int count): void

Convert UTF-16 encoded bytes to UTF-16 code units by grouping 1-2 bytes to produce the code unit (0-(2^16)-1). Relies on BOM to determine endian-ness, and defaults to BE.

Fields

final int current
final int position
final int remaining
final int replacementCodepoint
final _ListRangeIterator utf16EncodedBytesIterator

Getters and Setters

int get current
int get position
int get remaining

Constructors

factory Utf16BytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, int offset, int length, int replacementCodepoint)

Methods

void backup(int by)
int decode()
List<int> decodeRest()

Provides a fast way to decode the rest of the source bytes in a single call. This method trades memory for improved speed in that it potentially over-allocates the List containing results.

bool moveNext()

Moves to the next element. Returns true if current contains the next element. Returns false, if no element was left.

It is safe to invoke moveNext even when the iterator is already positioned after the last element. In this case moveNext has no effect.

void skip(int count)

Class Utf16CodeUnitDecoder implements Iterator<int>

Fields
current: int
iterator: Iterator
replacementCodepoint: int
utf16CodeUnitIterator: _ListRangeIterator
Getters and Setters
current: int
iterator: Iterator<int>
Constructors
Utf16CodeUnitDecoder(List<int> utf16CodeUnits, int offset, int length, int replacementCodepoint)
Utf16CodeUnitDecoder.fromListRangeIterator(_ListRangeIterator utf16CodeUnitIterator, int replacementCodepoint)
Methods
moveNext(): bool

An Iterator<int> of codepoints built on an Iterator of UTF-16 code units. The parameters can override the default Unicode replacement character. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value.

Fields

final int current
final Iterator iterator
final int replacementCodepoint
final _ListRangeIterator utf16CodeUnitIterator

Getters and Setters

int get current
Iterator<int> get iterator

Constructors

Utf16CodeUnitDecoder(List<int> utf16CodeUnits, int offset, int length, int replacementCodepoint)
Utf16CodeUnitDecoder.fromListRangeIterator(_ListRangeIterator utf16CodeUnitIterator, int replacementCodepoint)

Methods

bool moveNext()

Moves to the next element. Returns true if current contains the next element. Returns false, if no element was left.

It is safe to invoke moveNext even when the iterator is already positioned after the last element. In this case moveNext has no effect.


Class Utf16beBytesToCodeUnitsDecoder extends Utf16BytesToCodeUnitsDecoder

Constructors
Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)
Methods
decode(): int

Convert UTF-16BE encoded bytes to utf16 code units by grouping 1-2 bytes to produce the code unit (0-(2^16)-1).

Constructors

Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)

Methods

int decode()

Class Utf16leBytesToCodeUnitsDecoder extends Utf16BytesToCodeUnitsDecoder

Constructors
Utf16leBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)
Methods
decode(): int

Convert UTF-16LE encoded bytes to utf16 code units by grouping 1-2 bytes to produce the code unit (0-(2^16)-1).

Constructors

Utf16leBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)

Methods

int decode()

Abstract class Utf32BytesDecoder implements _ListRangeIterator

Fields
current: int
position: int
remaining: int
replacementCodepoint: int
utf32EncodedBytesIterator: _ListRangeIterator
Getters and Setters
current: int
position: int
remaining: int
Constructors
Utf32BytesDecoder(List<int> utf32EncodedBytes, int offset, int length, int replacementCodepoint)
Methods
backup(int by): void
decode(): int
decodeRest(): List<int>
moveNext(): bool
skip(int count): void

Abstrace parent class converts encoded bytes to codepoints.

Fields

final int current
final int position
final int remaining
final int replacementCodepoint
final _ListRangeIterator utf32EncodedBytesIterator

Getters and Setters

int get current
int get position
int get remaining

Constructors

factory Utf32BytesDecoder(List<int> utf32EncodedBytes, int offset, int length, int replacementCodepoint)

Methods

void backup(int by)
int decode()
List<int> decodeRest()
bool moveNext()

Moves to the next element. Returns true if current contains the next element. Returns false, if no element was left.

It is safe to invoke moveNext even when the iterator is already positioned after the last element. In this case moveNext has no effect.

void skip(int count)

Class Utf32beBytesDecoder extends Utf32BytesDecoder

Constructors
Utf32beBytesDecoder(List<int> utf32EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)
Methods
decode(): int

Convert UTF-32BE encoded bytes to codepoints by grouping 4 bytes to produce the unicode codepoint.

Constructors

Utf32beBytesDecoder(List<int> utf32EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)

Methods

int decode()

Class Utf32leBytesDecoder extends Utf32BytesDecoder

Constructors
Utf32leBytesDecoder(List<int> utf32EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)
Methods
decode(): int

Convert UTF-32BE encoded bytes to codepoints by grouping 4 bytes to produce the unicode codepoint.

Constructors

Utf32leBytesDecoder(List<int> utf32EncodedBytes, int offset, int length, bool stripBom, int replacementCodepoint)

Methods

int decode()

Class Utf8Decoder implements Iterator<int>

Fields
current: int
replacementCodepoint: int
utf8EncodedBytesIterator: _ListRangeIterator
Getters and Setters
current: int
Constructors
Utf8Decoder(List<int> utf8EncodedBytes, int offset, int length, int replacementCodepoint)
Methods
decodeRest(): List<int>
moveNext(): bool

Provides an iterator of Unicode codepoints from UTF-8 encoded bytes. The parameters can set an offset into a list of bytes (as int), limit the length of the values to be decoded, and override the default Unicode replacement character. Set the replacementCharacter to null to throw an ArgumentError rather than replace the bad value. The return value from this method can be used as an Iterable (e.g. in a for-loop).

Fields

final int current
final int replacementCodepoint
final _ListRangeIterator utf8EncodedBytesIterator

Getters and Setters

int get current

Constructors

Utf8Decoder(List<int> utf8EncodedBytes, int offset, int length, int replacementCodepoint)

Methods

List<int> decodeRest()

Decode the remaininder of the characters in this decoder into a List<int>.

bool moveNext()

Moves to the next element. Returns true if current contains the next element. Returns false, if no element was left.

It is safe to invoke moveNext even when the iterator is already positioned after the last element. In this case moveNext has no effect.


Class Utf8DecoderTransformer extends _StringDecoder

Constructors
Utf8DecoderTransformer(int replacementChar)

StringTransformer that decodes a stream of UTF-8 encoded bytes.

Constructors

Utf8DecoderTransformer(int replacementChar)

Class Utf8EncoderTransformer extends _StringEncoder

Constructors
Utf8EncoderTransformer()

StringTransformer that UTF-8 encodes a stream of strings.

Constructors

Utf8EncoderTransformer()