Utf32BytesDecoder class
Abstrace parent class converts encoded bytes to codepoints.
class Utf32BytesDecoder implements _ListRangeIterator { final _ListRangeIterator utf32EncodedBytesIterator; final int replacementCodepoint; 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 (hasNext()) { codeunits[i++] = next(); } return codeunits; } bool hasNext() => utf32EncodedBytesIterator.hasNext(); int next() { if (utf32EncodedBytesIterator.remaining < 4) { utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining); if (replacementCodepoint != null) { return replacementCodepoint; } else { throw new ArgumentError( "Invalid UTF32 at ${utf32EncodedBytesIterator.position}"); } } else { int codepoint = decode(); if (_validCodepoint(codepoint)) { return codepoint; } else if (replacementCodepoint != null) { return replacementCodepoint; } 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); } abstract 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 _ListRangeIterator utf32EncodedBytesIterator #
final _ListRangeIterator utf32EncodedBytesIterator;
Methods
List<int> decodeRest() #
List<int> decodeRest() { List<int> codeunits = new List<int>(remaining); int i = 0; while (hasNext()) { codeunits[i++] = next(); } return codeunits; }
int next() #
Gets the next element in the iteration. Throws a
NoMoreElementsException
if no element is left.
int next() { if (utf32EncodedBytesIterator.remaining < 4) { utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining); if (replacementCodepoint != null) { return replacementCodepoint; } else { throw new ArgumentError( "Invalid UTF32 at ${utf32EncodedBytesIterator.position}"); } } else { int codepoint = decode(); if (_validCodepoint(codepoint)) { return codepoint; } else if (replacementCodepoint != null) { return replacementCodepoint; } else { throw new ArgumentError( "Invalid UTF32 at ${utf32EncodedBytesIterator.position}"); } } }