| 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 const int _UTF8_ONE_BYTE_MAX = 0x7f; | 5 const int _UTF8_ONE_BYTE_MAX = 0x7f; |
| 6 const int _UTF8_TWO_BYTE_MAX = 0x7ff; | 6 const int _UTF8_TWO_BYTE_MAX = 0x7ff; |
| 7 const int _UTF8_THREE_BYTE_MAX = 0xffff; | 7 const int _UTF8_THREE_BYTE_MAX = 0xffff; |
| 8 | 8 |
| 9 const int _UTF8_LO_SIX_BIT_MASK = 0x3f; | 9 const int _UTF8_LO_SIX_BIT_MASK = 0x3f; |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 120 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
| 121 return new Utf8Decoder(utf8EncodedBytes, offset, length, | 121 return new Utf8Decoder(utf8EncodedBytes, offset, length, |
| 122 replacementCodepoint).decodeRest(); | 122 replacementCodepoint).decodeRest(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * Return type of [decodeUtf8AsIterable] and variants. The Iterable type | 126 * Return type of [decodeUtf8AsIterable] and variants. The Iterable type |
| 127 * provides an iterator on demand and the iterator will only translate bytes | 127 * provides an iterator on demand and the iterator will only translate bytes |
| 128 * as requested by the user of the iterator. (Note: results are not cached.) | 128 * as requested by the user of the iterator. (Note: results are not cached.) |
| 129 */ | 129 */ |
| 130 class IterableUtf8Decoder implements Iterable<int> { | 130 class IterableUtf8Decoder extends Iterable<int> { |
| 131 final List<int> bytes; | 131 final List<int> bytes; |
| 132 final int offset; | 132 final int offset; |
| 133 final int length; | 133 final int length; |
| 134 final int replacementCodepoint; | 134 final int replacementCodepoint; |
| 135 | 135 |
| 136 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, | 136 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, |
| 137 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 137 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); |
| 138 | 138 |
| 139 Utf8Decoder iterator() => new Utf8Decoder(bytes, offset, length, | 139 Utf8Decoder iterator() => new Utf8Decoder(bytes, offset, length, |
| 140 replacementCodepoint); | 140 replacementCodepoint); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if (validSequence && nonOverlong && inRange) { | 251 if (validSequence && nonOverlong && inRange) { |
| 252 return value; | 252 return value; |
| 253 } else if (replacementCodepoint != null) { | 253 } else if (replacementCodepoint != null) { |
| 254 return replacementCodepoint; | 254 return replacementCodepoint; |
| 255 } else { | 255 } else { |
| 256 throw new ArgumentError( | 256 throw new ArgumentError( |
| 257 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); | 257 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 } | 260 } |
| OLD | NEW |