Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.convert; | 5 part of dart.convert; |
| 6 | 6 |
| 7 /** The Unicode Replacement character `U+FFFD` (�). */ | 7 /** The Unicode Replacement character `U+FFFD` (�). */ |
| 8 const int UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD; | 8 const int UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD; |
| 9 | 9 |
| 10 /** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */ | 10 /** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */ |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 class _Utf8Encoder { | 126 class _Utf8Encoder { |
| 127 int _carry = 0; | 127 int _carry = 0; |
| 128 int _bufferIndex = 0; | 128 int _bufferIndex = 0; |
| 129 final List<int> _buffer; | 129 final List<int> _buffer; |
| 130 | 130 |
| 131 static const _DEFAULT_BYTE_BUFFER_SIZE = 1024; | 131 static const _DEFAULT_BYTE_BUFFER_SIZE = 1024; |
| 132 | 132 |
| 133 _Utf8Encoder() : this.withBufferSize(_DEFAULT_BYTE_BUFFER_SIZE); | 133 _Utf8Encoder() : this.withBufferSize(_DEFAULT_BYTE_BUFFER_SIZE); |
| 134 | 134 |
| 135 _Utf8Encoder.withBufferSize(int bufferSize) | 135 _Utf8Encoder.withBufferSize(int bufferSize) |
| 136 // TODO(11971, floitsch): use Uint8List instead of normal lists. | 136 // TODO(11971, floitsch): use Uint8List instead of normal lists. |
|
floitsch
2014/01/31 13:03:49
Remove TODO.
| |
| 137 : _buffer = new List<int>(bufferSize); | 137 : _buffer = _createBuffer(bufferSize); |
| 138 | |
| 139 /** | |
| 140 * Allow an implementation to pick the most efficient way of storing bytes. | |
|
floitsch
2014/01/31 13:03:49
Maybe add a TODO(11971): just always use a Uint8Li
| |
| 141 */ | |
| 142 external static List<int> _createBuffer(int size); | |
| 138 | 143 |
| 139 /** | 144 /** |
| 140 * Tries to combine the given [leadingSurrogate] with the [nextCodeUnit] and | 145 * Tries to combine the given [leadingSurrogate] with the [nextCodeUnit] and |
| 141 * writes it to [_buffer]. | 146 * writes it to [_buffer]. |
| 142 * | 147 * |
| 143 * Returns true if the [nextCodeUnit] was combined with the | 148 * Returns true if the [nextCodeUnit] was combined with the |
| 144 * [leadingSurrogate]. If it wasn't then nextCodeUnit was not a trailing | 149 * [leadingSurrogate]. If it wasn't then nextCodeUnit was not a trailing |
| 145 * surrogate and has not been written yet. | 150 * surrogate and has not been written yet. |
| 146 * | 151 * |
| 147 * It is safe to pass 0 for [nextCodeUnit] in which case only the leading | 152 * It is safe to pass 0 for [nextCodeUnit] in which case only the leading |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 } | 518 } |
| 514 break loop; | 519 break loop; |
| 515 } | 520 } |
| 516 if (expectedUnits > 0) { | 521 if (expectedUnits > 0) { |
| 517 _value = value; | 522 _value = value; |
| 518 _expectedUnits = expectedUnits; | 523 _expectedUnits = expectedUnits; |
| 519 _extraUnits = extraUnits; | 524 _extraUnits = extraUnits; |
| 520 } | 525 } |
| 521 } | 526 } |
| 522 } | 527 } |
| OLD | NEW |