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

Side by Side Diff: pkg/utf/lib/utf32.dart

Issue 68563004: Move unicode tests to utf package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplify test. Created 7 years, 1 month 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 utf; 5 part of utf;
6 6
7 /** 7 /**
8 * Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert 8 * Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert
9 * as much of the input as needed. Determines the byte order from the BOM, 9 * as much of the input as needed. Determines the byte order from the BOM,
10 * or uses big-endian as a default. This method always strips a leading BOM. 10 * or uses big-endian as a default. This method always strips a leading BOM.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 while (moveNext()) { 227 while (moveNext()) {
228 codeunits[i++] = current; 228 codeunits[i++] = current;
229 } 229 }
230 return codeunits; 230 return codeunits;
231 } 231 }
232 232
233 int get current => _current; 233 int get current => _current;
234 234
235 bool moveNext() { 235 bool moveNext() {
236 _current = null; 236 _current = null;
237 if (utf32EncodedBytesIterator.remaining < 4) { 237 int remaining = utf32EncodedBytesIterator.remaining;
238 if (remaining == 0) {
239 _current = null;
240 return false;
241 }
242 if (remaining < 4) {
238 utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining); 243 utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining);
239 if (replacementCodepoint != null) { 244 if (replacementCodepoint != null) {
240 _current = replacementCodepoint; 245 _current = replacementCodepoint;
241 return true; 246 return true;
242 } else { 247 } else {
243 throw new ArgumentError( 248 throw new ArgumentError(
244 "Invalid UTF32 at ${utf32EncodedBytesIterator.position}"); 249 "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
245 } 250 }
246 } else {
247 int codepoint = decode();
248 if (_validCodepoint(codepoint)) {
249 _current = codepoint;
250 return true;
251 } else if (replacementCodepoint != null) {
252 _current = replacementCodepoint;
253 return true;
254 } else {
255 throw new ArgumentError(
256 "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
257 }
258 } 251 }
252 int codepoint = decode();
253 if (_validCodepoint(codepoint)) {
254 _current = codepoint;
255 return true;
256 } else if (replacementCodepoint != null) {
257 _current = replacementCodepoint;
258 return true;
259 } else {
260 throw new ArgumentError(
261 "Invalid UTF32 at ${utf32EncodedBytesIterator.position}");
262 }
259 } 263 }
260 264
261 int get position => utf32EncodedBytesIterator.position ~/ 4; 265 int get position => utf32EncodedBytesIterator.position ~/ 4;
262 266
263 void backup([int by = 1]) { 267 void backup([int by = 1]) {
264 utf32EncodedBytesIterator.backup(4 * by); 268 utf32EncodedBytesIterator.backup(4 * by);
265 } 269 }
266 270
267 int get remaining => (utf32EncodedBytesIterator.remaining + 3) ~/ 4; 271 int get remaining => (utf32EncodedBytesIterator.remaining + 3) ~/ 4;
268 272
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 value += (utf32EncodedBytesIterator.current << 24); 333 value += (utf32EncodedBytesIterator.current << 24);
330 return value; 334 return value;
331 } 335 }
332 } 336 }
333 337
334 bool _validCodepoint(int codepoint) { 338 bool _validCodepoint(int codepoint) {
335 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || 339 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) ||
336 (codepoint > UNICODE_UTF16_RESERVED_HI && 340 (codepoint > UNICODE_UTF16_RESERVED_HI &&
337 codepoint < UNICODE_VALID_RANGE_MAX); 341 codepoint < UNICODE_VALID_RANGE_MAX);
338 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698