Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: sdk/lib/utf/utf8.dart

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 encodedLength++; 79 encodedLength++;
80 } else if (value <= _UTF8_TWO_BYTE_MAX) { 80 } else if (value <= _UTF8_TWO_BYTE_MAX) {
81 encodedLength += 2; 81 encodedLength += 2;
82 } else if (value <= _UTF8_THREE_BYTE_MAX) { 82 } else if (value <= _UTF8_THREE_BYTE_MAX) {
83 encodedLength += 3; 83 encodedLength += 3;
84 } else if (value <= UNICODE_VALID_RANGE_MAX) { 84 } else if (value <= UNICODE_VALID_RANGE_MAX) {
85 encodedLength += 4; 85 encodedLength += 4;
86 } 86 }
87 } 87 }
88 88
89 List<int> encoded = new List<int>.fixedLength(encodedLength); 89 List<int> encoded = new List<int>(encodedLength);
90 int insertAt = 0; 90 int insertAt = 0;
91 for (int value in source) { 91 for (int value in source) {
92 if (value < 0 || value > UNICODE_VALID_RANGE_MAX) { 92 if (value < 0 || value > UNICODE_VALID_RANGE_MAX) {
93 encoded.setRange(insertAt, 3, [0xef, 0xbf, 0xbd]); 93 encoded.setRange(insertAt, 3, [0xef, 0xbf, 0xbd]);
94 insertAt += 3; 94 insertAt += 3;
95 } else if (value <= _UTF8_ONE_BYTE_MAX) { 95 } else if (value <= _UTF8_ONE_BYTE_MAX) {
96 encoded[insertAt] = value; 96 encoded[insertAt] = value;
97 insertAt++; 97 insertAt++;
98 } else if (value <= _UTF8_TWO_BYTE_MAX) { 98 } else if (value <= _UTF8_TWO_BYTE_MAX) {
99 encoded[insertAt] = _UTF8_FIRST_BYTE_OF_TWO_BASE | ( 99 encoded[insertAt] = _UTF8_FIRST_BYTE_OF_TWO_BASE | (
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 166
167 Utf8Decoder._fromListRangeIterator(_ListRange source, [ 167 Utf8Decoder._fromListRangeIterator(_ListRange source, [
168 this.replacementCodepoint = 168 this.replacementCodepoint =
169 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) : 169 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
170 utf8EncodedBytesIterator = source.iterator; 170 utf8EncodedBytesIterator = source.iterator;
171 171
172 /** Decode the remaininder of the characters in this decoder 172 /** Decode the remaininder of the characters in this decoder
173 * into a [List<int>]. 173 * into a [List<int>].
174 */ 174 */
175 List<int> decodeRest() { 175 List<int> decodeRest() {
176 List<int> codepoints = new List<int>.fixedLength(utf8EncodedBytesIterator.re maining); 176 List<int> codepoints = new List<int>(utf8EncodedBytesIterator.remaining);
177 int i = 0; 177 int i = 0;
178 while (moveNext()) { 178 while (moveNext()) {
179 codepoints[i++] = current; 179 codepoints[i++] = current;
180 } 180 }
181 if (i == codepoints.length) { 181 if (i == codepoints.length) {
182 return codepoints; 182 return codepoints;
183 } else { 183 } else {
184 List<int> truncCodepoints = new List<int>.fixedLength(i); 184 List<int> truncCodepoints = new List<int>(i);
185 truncCodepoints.setRange(0, i, codepoints); 185 truncCodepoints.setRange(0, i, codepoints);
186 return truncCodepoints; 186 return truncCodepoints;
187 } 187 }
188 } 188 }
189 189
190 int get current => _current; 190 int get current => _current;
191 191
192 bool moveNext() { 192 bool moveNext() {
193 _current = null; 193 _current = null;
194 194
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698