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

Side by Side Diff: sdk/lib/core/string.dart

Issue 12261009: Added implementation of String.codeUnits. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typos 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.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * The String class represents sequences of characters. Strings are 8 * The String class represents sequences of characters. Strings are
9 * immutable. A string is represented by a sequence of Unicode UTF-16 9 * immutable. A string is represented by a sequence of Unicode UTF-16
10 * code units accessible through the [codeUnitAt] or the 10 * code units accessible through the [codeUnitAt] or the
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 * a two-character String. 442 * a two-character String.
443 * 443 *
444 * Returns null if [current] is null. 444 * Returns null if [current] is null.
445 */ 445 */
446 String get currentAsString { 446 String get currentAsString {
447 if (_position == _nextPosition) return null; 447 if (_position == _nextPosition) return null;
448 if (_position + 1 == _nextPosition) return string[_position]; 448 if (_position + 1 == _nextPosition) return string[_position];
449 return string.substring(_position, _nextPosition); 449 return string.substring(_position, _nextPosition);
450 } 450 }
451 451
452
453 bool moveNext() { 452 bool moveNext() {
454 _position = _nextPosition; 453 _position = _nextPosition;
455 if (_position == string.length) { 454 if (_position == string.length) {
456 _currentCodePoint = null; 455 _currentCodePoint = null;
457 return false; 456 return false;
458 } 457 }
459 int codeUnit = string.charCodeAt(_position); 458 int codeUnit = string.charCodeAt(_position);
460 int nextPosition = _position + 1; 459 int nextPosition = _position + 1;
461 if (_isLeadSurrogate(codeUnit) && nextPosition < string.length) { 460 if (_isLeadSurrogate(codeUnit) && nextPosition < string.length) {
462 int nextCodeUnit = string.charCodeAt(nextPosition); 461 int nextCodeUnit = string.charCodeAt(nextPosition);
(...skipping 22 matching lines...) Expand all
485 _position = position - 1; 484 _position = position - 1;
486 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); 485 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit);
487 return true; 486 return true;
488 } 487 }
489 } 488 }
490 _position = position; 489 _position = position;
491 _currentCodePoint = codeUnit; 490 _currentCodePoint = codeUnit;
492 return true; 491 return true;
493 } 492 }
494 } 493 }
494
495 /**
496 * An [Iterable] of the UTF-16 code units of a [String] in index order.
497 */
498 class CodeUnits extends ListIterable<int> {
499 /** The string that this is the code units of. */
500 String string;
501
502 CodeUnits(this.string);
503
504 int get length => string.length;
505 int elementAt(int i) => string.codeUnitAt(i);
506 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/js_string.dart ('k') | tests/corelib/string_codeunits_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698