Dart API Referencedart:utfUtf32BytesDecoder

Utf32BytesDecoder abstract class

Abstrace parent class converts encoded bytes to codepoints.

abstract class Utf32BytesDecoder implements _ListRangeIterator {
 final _ListRangeIterator utf32EncodedBytesIterator;
 final int replacementCodepoint;
 int _current = null;

 Utf32BytesDecoder._fromListRangeIterator(
     this.utf32EncodedBytesIterator, this.replacementCodepoint);

 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [
     int offset = 0, int length,
     int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
   if (length == null) {
     length = utf32EncodedBytes.length - offset;
   }
   if (hasUtf32beBom(utf32EncodedBytes, offset, length)) {
     return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4,
         false, replacementCodepoint);
   } else if (hasUtf32leBom(utf32EncodedBytes, offset, length)) {
     return new Utf32leBytesDecoder(utf32EncodedBytes, offset + 4, length - 4,
         false, replacementCodepoint);
   } else {
     return new Utf32beBytesDecoder(utf32EncodedBytes, offset, length, false,
         replacementCodepoint);
   }
 }

 List<int> decodeRest() {
   List<int> codeunits = new List<int>(remaining);
   int i = 0;
   while (moveNext()) {
     codeunits[i++] = current;
   }
   return codeunits;
 }

 int get current => _current;

 bool moveNext() {
   _current = null;
   if (utf32EncodedBytesIterator.remaining < 4) {
     utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining);
     if (replacementCodepoint != null) {
         _current = replacementCodepoint;
         return true;
     } else {
       throw new ArgumentError(
           "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
     }
   } else {
     int codepoint = decode();
     if (_validCodepoint(codepoint)) {
       _current = codepoint;
       return true;
     } else if (replacementCodepoint != null) {
       _current = replacementCodepoint;
       return true;
     } else {
       throw new ArgumentError(
           "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
     }
   }
 }

 int get position => utf32EncodedBytesIterator.position ~/ 4;

 void backup([int by = 1]) {
   utf32EncodedBytesIterator.backup(4 * by);
 }

 int get remaining => (utf32EncodedBytesIterator.remaining + 3) ~/ 4;

 void skip([int count = 1]) {
   utf32EncodedBytesIterator.skip(4 * count);
 }

 int decode();
}

Subclasses

Utf32beBytesDecoder, Utf32leBytesDecoder

Constructors

factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [int offset = 0, int length, int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) #

factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [
   int offset = 0, int length,
   int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
 if (length == null) {
   length = utf32EncodedBytes.length - offset;
 }
 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) {
   return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4,
       false, replacementCodepoint);
 } else if (hasUtf32leBom(utf32EncodedBytes, offset, length)) {
   return new Utf32leBytesDecoder(utf32EncodedBytes, offset + 4, length - 4,
       false, replacementCodepoint);
 } else {
   return new Utf32beBytesDecoder(utf32EncodedBytes, offset, length, false,
       replacementCodepoint);
 }
}

Properties

final int current #

Returns the current element.

Return null if the iterator has not yet been moved to the first element, or if the iterator has been moved after the last element of the Iterable.

docs inherited from Iterator<int>
int get current => _current;

final int position #

int get position => utf32EncodedBytesIterator.position ~/ 4;

final int remaining #

int get remaining => (utf32EncodedBytesIterator.remaining + 3) ~/ 4;

final int replacementCodepoint #

final int replacementCodepoint

final _ListRangeIterator utf32EncodedBytesIterator #

final _ListRangeIterator utf32EncodedBytesIterator

Methods

void backup([int by = 1]) #

void backup([int by = 1]) {
 utf32EncodedBytesIterator.backup(4 * by);
}

abstract int decode() #

List<int> decodeRest() #

List<int> decodeRest() {
 List<int> codeunits = new List<int>(remaining);
 int i = 0;
 while (moveNext()) {
   codeunits[i++] = current;
 }
 return codeunits;
}

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.

docs inherited from Iterator<int>
bool moveNext() {
 _current = null;
 if (utf32EncodedBytesIterator.remaining < 4) {
   utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining);
   if (replacementCodepoint != null) {
       _current = replacementCodepoint;
       return true;
   } else {
     throw new ArgumentError(
         "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
   }
 } else {
   int codepoint = decode();
   if (_validCodepoint(codepoint)) {
     _current = codepoint;
     return true;
   } else if (replacementCodepoint != null) {
     _current = replacementCodepoint;
     return true;
   } else {
     throw new ArgumentError(
         "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
   }
 }
}

void skip([int count = 1]) #

void skip([int count = 1]) {
 utf32EncodedBytesIterator.skip(4 * count);
}