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

Side by Side Diff: runtime/lib/string_patch.dart

Issue 460613002: Add optional start index to Pattern.allMatches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add extra test. Created 6 years, 4 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 patch class String { 5 patch class String {
6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) {
7 return _StringBase.createFromCharCodes(charCodes); 7 return _StringBase.createFromCharCodes(charCodes);
8 } 8 }
9 9
10 /* patch */ factory String.fromCharCode(int charCode) { 10 /* patch */ factory String.fromCharCode(int charCode) {
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 533 }
534 } 534 }
535 stringList[i] = s; 535 stringList[i] = s;
536 } 536 }
537 if (isOneByteString) { 537 if (isOneByteString) {
538 return _OneByteString._concatAll(stringList, totalLength); 538 return _OneByteString._concatAll(stringList, totalLength);
539 } 539 }
540 return _concatRangeNative(stringList, 0, stringList.length); 540 return _concatRangeNative(stringList, 0, stringList.length);
541 } 541 }
542 542
543 Iterable<Match> allMatches(String str) { 543 Iterable<Match> allMatches(String string, [int start = 0]) {
544 List<Match> result = new List<Match>(); 544 List<Match> result = new List<Match>();
545 int length = str.length; 545 int length = string.length;
546 int patternLength = this.length; 546 int patternLength = this.length;
547 int startIndex = 0; 547 int startIndex = start;
548 while (true) { 548 while (true) {
549 int position = str.indexOf(this, startIndex); 549 int position = string.indexOf(this, startIndex);
550 if (position == -1) { 550 if (position == -1) {
551 break; 551 break;
552 } 552 }
553 result.add(new _StringMatch(position, str, this)); 553 result.add(new _StringMatch(position, string, this));
554 int endIndex = position + patternLength; 554 int endIndex = position + patternLength;
555 if (endIndex == length) { 555 if (endIndex == length) {
556 break; 556 break;
557 } else if (position == endIndex) { 557 } else if (position == endIndex) {
558 ++startIndex; // empty match, advance and restart 558 ++startIndex; // empty match, advance and restart
559 } else { 559 } else {
560 startIndex = endIndex; 560 startIndex = endIndex;
561 } 561 }
562 } 562 }
563 return result; 563 return result;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 class _CodeUnits extends Object with ListMixin<int>, 1004 class _CodeUnits extends Object with ListMixin<int>,
1005 UnmodifiableListMixin<int> { 1005 UnmodifiableListMixin<int> {
1006 /** The string that this is the code units of. */ 1006 /** The string that this is the code units of. */
1007 String _string; 1007 String _string;
1008 1008
1009 _CodeUnits(this._string); 1009 _CodeUnits(this._string);
1010 1010
1011 int get length => _string.length; 1011 int get length => _string.length;
1012 int operator[](int i) => _string.codeUnitAt(i); 1012 int operator[](int i) => _string.codeUnitAt(i);
1013 } 1013 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698