| Index: sdk/lib/utf/utf16.dart
|
| diff --git a/sdk/lib/utf/utf16.dart b/sdk/lib/utf/utf16.dart
|
| index 431d695ad83a233f5e8130f82264945a07788d5e..7d318aaf2c1fe2f1638b24d4e315c9b368ad3238 100644
|
| --- a/sdk/lib/utf/utf16.dart
|
| +++ b/sdk/lib/utf/utf16.dart
|
| @@ -221,7 +221,7 @@ class IterableUtf16Decoder extends Iterable<int> {
|
|
|
| IterableUtf16Decoder._(this.codeunitsProvider, this.replacementCodepoint);
|
|
|
| - Utf16CodeUnitDecoder iterator() =>
|
| + Utf16CodeUnitDecoder get iterator =>
|
| new Utf16CodeUnitDecoder.fromListRangeIterator(codeunitsProvider(),
|
| replacementCodepoint);
|
| }
|
| @@ -234,6 +234,7 @@ class IterableUtf16Decoder extends Iterable<int> {
|
| class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator {
|
| final _ListRangeIterator utf16EncodedBytesIterator;
|
| final int replacementCodepoint;
|
| + int _current = -1;
|
|
|
| Utf16BytesToCodeUnitsDecoder._fromListRangeIterator(
|
| this.utf16EncodedBytesIterator, this.replacementCodepoint);
|
| @@ -264,8 +265,8 @@ class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator {
|
| List<int> decodeRest() {
|
| List<int> codeunits = new List<int>(remaining);
|
| int i = 0;
|
| - while (hasNext) {
|
| - codeunits[i++] = next();
|
| + while (moveNext()) {
|
| + codeunits[i++] = current;
|
| }
|
| if (i == codeunits.length) {
|
| return codeunits;
|
| @@ -276,19 +277,27 @@ class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator {
|
| }
|
| }
|
|
|
| - bool get hasNext => utf16EncodedBytesIterator.hasNext;
|
| + int get current {
|
| + if (_current == -1) {
|
| + // TODO(floitsch): bad error message.
|
| + throw new StateError("No more elements");
|
| + }
|
| + }
|
|
|
| - int next() {
|
| + bool moveNext() {
|
| + _current = -1;
|
| if (utf16EncodedBytesIterator.remaining < 2) {
|
| - utf16EncodedBytesIterator.next();
|
| + utf16EncodedBytesIterator.moveNext();
|
| if (replacementCodepoint != null) {
|
| - return replacementCodepoint;
|
| + _current = replacementCodepoint;
|
| + return true;
|
| } else {
|
| throw new ArgumentError(
|
| "Invalid UTF16 at ${utf16EncodedBytesIterator.position}");
|
| }
|
| } else {
|
| - return decode();
|
| + _current = decode();
|
| + return true;
|
| }
|
| }
|
|
|
| @@ -315,16 +324,19 @@ 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) {
|
| + super._fromListRangeIterator(
|
| + (new _ListRange(utf16EncodedBytes, offset, length)).iterator,
|
| + replacementCodepoint) {
|
| if (stripBom && hasUtf16beBom(utf16EncodedBytes, offset, length)) {
|
| skip();
|
| }
|
| }
|
|
|
| int decode() {
|
| - int hi = utf16EncodedBytesIterator.next();
|
| - int lo = utf16EncodedBytesIterator.next();
|
| + utf16EncodedBytesIterator.moveNext();
|
| + int hi = utf16EncodedBytesIterator.current;
|
| + utf16EncodedBytesIterator.moveNext();
|
| + int lo = utf16EncodedBytesIterator.current;
|
| return (hi << 8) + lo;
|
| }
|
| }
|
| @@ -337,16 +349,19 @@ class Utf16leBytesToCodeUnitsDecoder extends Utf16BytesToCodeUnitsDecoder {
|
| Utf16leBytesToCodeUnitsDecoder(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) {
|
| + super._fromListRangeIterator(
|
| + (new _ListRange(utf16EncodedBytes, offset, length)).iterator,
|
| + replacementCodepoint) {
|
| if (stripBom && hasUtf16leBom(utf16EncodedBytes, offset, length)) {
|
| skip();
|
| }
|
| }
|
|
|
| int decode() {
|
| - int lo = utf16EncodedBytesIterator.next();
|
| - int hi = utf16EncodedBytesIterator.next();
|
| + utf16EncodedBytesIterator.moveNext();
|
| + int lo = utf16EncodedBytesIterator.current;
|
| + utf16EncodedBytesIterator.moveNext();
|
| + int hi = utf16EncodedBytesIterator.current;
|
| return (hi << 8) + lo;
|
| }
|
| }
|
|
|