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

Unified Diff: sdk/lib/_internal/lib/js_string.dart

Issue 17281002: Make String.startsWith take an optional start index. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 7 years, 6 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
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/js_string.dart
diff --git a/sdk/lib/_internal/lib/js_string.dart b/sdk/lib/_internal/lib/js_string.dart
index 2da5ed4c17aef3e6feede8366e911a1dc5920efe..be707c0de69e622247e409ef43db1f813350f81d 100644
--- a/sdk/lib/_internal/lib/js_string.dart
+++ b/sdk/lib/_internal/lib/js_string.dart
@@ -85,15 +85,19 @@ class JSString extends Interceptor implements String, JSIndexable {
}
}
- bool startsWith(Pattern pattern) {
+ bool startsWith(Pattern pattern, [int index = 0]) {
+ if (index < 0 || index > this.length) {
+ throw new RangeError.range(index, 0, this.length);
+ }
if (pattern is String) {
String other = pattern;
int otherLength = other.length;
- if (otherLength > length) return false;
+ int endIndex = index + otherLength;
+ if (endIndex > length) return false;
return JS('bool', r'# == #', other,
- JS('String', r'#.substring(0, #)', this, otherLength));
+ JS('String', r'#.substring(#, #)', this, index, endIndex));
}
- return pattern.matchAsPrefix(this, 0) != null;
+ return pattern.matchAsPrefix(this, index) != null;
}
String substring(int startIndex, [int endIndex]) {
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698