Utf16beBytesToCodeUnitsDecoder class
Convert UTF-16BE encoded bytes to utf16 code units by grouping 1-2 bytes to produce the code unit (0-(2^16)-1).
class Utf16beBytesToCodeUnitsDecoder extends Utf16BytesToCodeUnitsDecoder {
Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [
int offset = 0, int length, bool stripBom = true,
int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
super._fromListRangeIterator(
(new _ListRange(utf16EncodedBytes, offset, length)).iterator,
replacementCodepoint) {
if (stripBom && hasUtf16beBom(utf16EncodedBytes, offset, length)) {
skip();
}
}
int decode() {
utf16EncodedBytesIterator.moveNext();
int hi = utf16EncodedBytesIterator.current;
utf16EncodedBytesIterator.moveNext();
int lo = utf16EncodedBytesIterator.current;
return (hi << 8) + lo;
}
}
Extends
Utf16BytesToCodeUnitsDecoder > Utf16beBytesToCodeUnitsDecoder
Constructors
new Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [int offset = 0, int length, bool stripBom = true, int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) #
Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [
int offset = 0, int length, bool stripBom = true,
int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
super._fromListRangeIterator(
(new _ListRange(utf16EncodedBytes, offset, length)).iterator,
replacementCodepoint) {
if (stripBom && hasUtf16beBom(utf16EncodedBytes, offset, length)) {
skip();
}
}
Properties
final int current #
final int position #
int get position => utf16EncodedBytesIterator.position ~/ 2;
final int remaining #
int get remaining => (utf16EncodedBytesIterator.remaining + 1) ~/ 2;
final int replacementCodepoint #
final int replacementCodepoint
final _ListRangeIterator utf16EncodedBytesIterator #
final _ListRangeIterator utf16EncodedBytesIterator
Methods
void backup([int by = 1]) #
void backup([int by = 1]) {
utf16EncodedBytesIterator.backup(2 * by);
}
int decode() #
int decode() {
utf16EncodedBytesIterator.moveNext();
int hi = utf16EncodedBytesIterator.current;
utf16EncodedBytesIterator.moveNext();
int lo = utf16EncodedBytesIterator.current;
return (hi << 8) + lo;
}
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.
List<int> decodeRest() {
List<int> codeunits = new List<int>(remaining);
int i = 0;
while (moveNext()) {
codeunits[i++] = current;
}
if (i == codeunits.length) {
return codeunits;
} else {
List<int> truncCodeunits = new List<int>(i);
truncCodeunits.setRange(0, i, codeunits);
return truncCodeunits;
}
}
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.
bool moveNext() {
_current = null;
if (utf16EncodedBytesIterator.remaining < 2) {
utf16EncodedBytesIterator.moveNext();
if (replacementCodepoint != null) {
_current = replacementCodepoint;
return true;
} else {
throw new ArgumentError(
"Invalid UTF16 at ${utf16EncodedBytesIterator.position}");
}
} else {
_current = decode();
return true;
}
}
void skip([int count = 1]) #
void skip([int count = 1]) {
utf16EncodedBytesIterator.skip(2 * count);
}