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

Unified Diff: runtime/lib/string.dart

Issue 8424012: Add optional arguments to our indexOf/lastIndexOf methods. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/string.dart
===================================================================
--- runtime/lib/string.dart (revision 942)
+++ runtime/lib/string.dart (working copy)
@@ -103,15 +103,15 @@
return this.substringMatches(0, other);
}
- int indexOf(String other, int startIndex) {
+ int indexOf(String other, [int start = 0]) {
if (other.isEmpty()) {
- return startIndex < this.length ? startIndex : this.length;
+ return start < this.length ? start : this.length;
}
- if ((startIndex < 0) || (startIndex >= this.length)) {
+ if ((start < 0) || (start >= this.length)) {
return -1;
}
int len = this.length - other.length + 1;
- for (int index = startIndex; index < len; index++) {
+ for (int index = start; index < len; index++) {
if (this.substringMatches(index, other)) {
return index;
}
@@ -119,14 +119,15 @@
return -1;
}
- int lastIndexOf(String other, int fromIndex) {
+ int lastIndexOf(String other, [int start = null]) {
+ if (start == null) start = length - 1;
if (other.isEmpty()) {
- return Math.min(this.length, fromIndex);
+ return Math.min(this.length, start);
}
- if (fromIndex >= this.length) {
- fromIndex = this.length - 1;
+ if (start >= this.length) {
+ start = this.length - 1;
}
- for (int index = fromIndex; index >= 0; index--) {
+ for (int index = start; index >= 0; index--) {
if (this.substringMatches(index, other)) {
return index;
}

Powered by Google App Engine
This is Rietveld 408576698