| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.utf; | 5 part of dart.utf; |
| 6 | 6 |
| 7 const int _UTF8_ONE_BYTE_MAX = 0x7f; | 7 const int _UTF8_ONE_BYTE_MAX = 0x7f; |
| 8 const int _UTF8_TWO_BYTE_MAX = 0x7ff; | 8 const int _UTF8_TWO_BYTE_MAX = 0x7ff; |
| 9 const int _UTF8_THREE_BYTE_MAX = 0xffff; | 9 const int _UTF8_THREE_BYTE_MAX = 0xffff; |
| 10 | 10 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 replacementCodepoint).decodeRest(); | 124 replacementCodepoint).decodeRest(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Return type of [decodeUtf8AsIterable] and variants. The Iterable type | 128 * Return type of [decodeUtf8AsIterable] and variants. The Iterable type |
| 129 * provides an iterator on demand and the iterator will only translate bytes | 129 * provides an iterator on demand and the iterator will only translate bytes |
| 130 * as requested by the user of the iterator. (Note: results are not cached.) | 130 * as requested by the user of the iterator. (Note: results are not cached.) |
| 131 */ | 131 */ |
| 132 // TODO(floitsch): Consider removing the extend and switch to implements since | 132 // TODO(floitsch): Consider removing the extend and switch to implements since |
| 133 // that's cheaper to allocate. | 133 // that's cheaper to allocate. |
| 134 class IterableUtf8Decoder extends Iterable<int> { | 134 class IterableUtf8Decoder extends IterableBase<int> { |
| 135 final List<int> bytes; | 135 final List<int> bytes; |
| 136 final int offset; | 136 final int offset; |
| 137 final int length; | 137 final int length; |
| 138 final int replacementCodepoint; | 138 final int replacementCodepoint; |
| 139 | 139 |
| 140 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, | 140 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, |
| 141 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 141 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); |
| 142 | 142 |
| 143 Utf8Decoder get iterator => | 143 Utf8Decoder get iterator => |
| 144 new Utf8Decoder(bytes, offset, length, replacementCodepoint); | 144 new Utf8Decoder(bytes, offset, length, replacementCodepoint); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 return true; | 266 return true; |
| 267 } else if (replacementCodepoint != null) { | 267 } else if (replacementCodepoint != null) { |
| 268 _current = replacementCodepoint; | 268 _current = replacementCodepoint; |
| 269 return true; | 269 return true; |
| 270 } else { | 270 } else { |
| 271 throw new ArgumentError( | 271 throw new ArgumentError( |
| 272 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); | 272 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 } | 275 } |
| OLD | NEW |