| 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 final int _UTF8_ONE_BYTE_MAX = 0x7f; | 5 const int _UTF8_ONE_BYTE_MAX = 0x7f; |
| 6 final int _UTF8_TWO_BYTE_MAX = 0x7ff; | 6 const int _UTF8_TWO_BYTE_MAX = 0x7ff; |
| 7 final int _UTF8_THREE_BYTE_MAX = 0xffff; | 7 const int _UTF8_THREE_BYTE_MAX = 0xffff; |
| 8 | 8 |
| 9 final int _UTF8_LO_SIX_BIT_MASK = 0x3f; | 9 const int _UTF8_LO_SIX_BIT_MASK = 0x3f; |
| 10 | 10 |
| 11 final int _UTF8_FIRST_BYTE_OF_TWO_BASE = 0xc0; | 11 const int _UTF8_FIRST_BYTE_OF_TWO_BASE = 0xc0; |
| 12 final int _UTF8_FIRST_BYTE_OF_THREE_BASE = 0xe0; | 12 const int _UTF8_FIRST_BYTE_OF_THREE_BASE = 0xe0; |
| 13 final int _UTF8_FIRST_BYTE_OF_FOUR_BASE = 0xf0; | 13 const int _UTF8_FIRST_BYTE_OF_FOUR_BASE = 0xf0; |
| 14 final int _UTF8_FIRST_BYTE_OF_FIVE_BASE = 0xf8; | 14 const int _UTF8_FIRST_BYTE_OF_FIVE_BASE = 0xf8; |
| 15 final int _UTF8_FIRST_BYTE_OF_SIX_BASE = 0xfc; | 15 const int _UTF8_FIRST_BYTE_OF_SIX_BASE = 0xfc; |
| 16 | 16 |
| 17 final int _UTF8_FIRST_BYTE_OF_TWO_MASK = 0x1f; | 17 const int _UTF8_FIRST_BYTE_OF_TWO_MASK = 0x1f; |
| 18 final int _UTF8_FIRST_BYTE_OF_THREE_MASK = 0xf; | 18 const int _UTF8_FIRST_BYTE_OF_THREE_MASK = 0xf; |
| 19 final int _UTF8_FIRST_BYTE_OF_FOUR_MASK = 0x7; | 19 const int _UTF8_FIRST_BYTE_OF_FOUR_MASK = 0x7; |
| 20 | 20 |
| 21 final int _UTF8_FIRST_BYTE_BOUND_EXCL = 0xfe; | 21 const int _UTF8_FIRST_BYTE_BOUND_EXCL = 0xfe; |
| 22 final int _UTF8_SUBSEQUENT_BYTE_BASE = 0x80; | 22 const int _UTF8_SUBSEQUENT_BYTE_BASE = 0x80; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Decodes the UTF-8 bytes as an iterable. Thus, the consumer can only convert | 25 * Decodes the UTF-8 bytes as an iterable. Thus, the consumer can only convert |
| 26 * as much of the input as needed. Set the replacementCharacter to null to | 26 * as much of the input as needed. Set the replacementCharacter to null to |
| 27 * throw an IllegalArgumentException rather than replace the bad value. | 27 * throw an IllegalArgumentException rather than replace the bad value. |
| 28 */ | 28 */ |
| 29 IterableUtf8Decoder decodeUtf8AsIterable(List<int> bytes, [int offset = 0, | 29 IterableUtf8Decoder decodeUtf8AsIterable(List<int> bytes, [int offset = 0, |
| 30 int length, | 30 int length, |
| 31 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 31 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
| 32 return new IterableUtf8Decoder(bytes, offset, length, replacementCodepoint); | 32 return new IterableUtf8Decoder(bytes, offset, length, replacementCodepoint); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (validSequence && nonOverlong && inRange) { | 252 if (validSequence && nonOverlong && inRange) { |
| 253 return value; | 253 return value; |
| 254 } else if (replacementCodepoint != null) { | 254 } else if (replacementCodepoint != null) { |
| 255 return replacementCodepoint; | 255 return replacementCodepoint; |
| 256 } else { | 256 } else { |
| 257 throw new IllegalArgumentException( | 257 throw new IllegalArgumentException( |
| 258 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); | 258 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 } | 261 } |
| OLD | NEW |