Utf16CodeUnitDecoder Class
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 IllegalArgumentException rather than replace the bad value.
Implements
Constructors
Code new Utf16CodeUnitDecoder(List<int> utf16CodeUnits, [int offset = 0, int length, int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) #
Utf16CodeUnitDecoder(List<int> utf16CodeUnits, [int offset = 0, int length, int this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) : utf16CodeUnitIterator = (new _ListRange(utf16CodeUnits, offset, length)) .iterator();
Code new Utf16CodeUnitDecoder.fromListRangeIterator(_ListRangeIterator utf16CodeUnitIterator, int replacementCodepoint) #
Utf16CodeUnitDecoder.fromListRangeIterator( _ListRangeIterator this.utf16CodeUnitIterator, int this.replacementCodepoint);
Methods
Code int next() #
int next() { int value = utf16CodeUnitIterator.next(); if (value < 0) { if (replacementCodepoint != null) { return replacementCodepoint; } else { throw new IllegalArgumentException( "Invalid UTF16 at ${utf16CodeUnitIterator.position}"); } } else if (value < UNICODE_UTF16_RESERVED_LO || (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) { // transfer directly return value; } else if (value < UNICODE_UTF16_SURROGATE_UNIT_1_BASE && utf16CodeUnitIterator.hasNext()) { // merge surrogate pair int nextValue = utf16CodeUnitIterator.next(); if (nextValue >= UNICODE_UTF16_SURROGATE_UNIT_1_BASE && nextValue <= UNICODE_UTF16_RESERVED_HI) { value = (value - UNICODE_UTF16_SURROGATE_UNIT_0_BASE) << 10; value += UNICODE_UTF16_OFFSET + (nextValue - UNICODE_UTF16_SURROGATE_UNIT_1_BASE); return value; } else { if (nextValue >= UNICODE_UTF16_SURROGATE_UNIT_0_BASE && nextValue < UNICODE_UTF16_SURROGATE_UNIT_1_BASE) { utf16CodeUnitIterator.backup(); } if (replacementCodepoint != null) { return replacementCodepoint; } else { throw new IllegalArgumentException( "Invalid UTF16 at ${utf16CodeUnitIterator.position}"); } } } else if (replacementCodepoint != null) { return replacementCodepoint; } else { throw new IllegalArgumentException( "Invalid UTF16 at ${utf16CodeUnitIterator.position}"); } }
Fields
Code final _ListRangeIterator utf16CodeUnitIterator #
final _ListRangeIterator utf16CodeUnitIterator;