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

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

Issue 15709018: Proof-of-concept matchPrefix on Pattern. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed other 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
Index: sdk/lib/_internal/compiler/implementation/lib/js_string.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_string.dart b/sdk/lib/_internal/compiler/implementation/lib/js_string.dart
index 92d7c673a2a62bc8da0b152e3afa0a81c59d5bdb..6b083719d95f65f10cc0e1cc99244e57f19fa121 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_string.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_string.dart
@@ -25,6 +25,20 @@ class JSString extends Interceptor implements String, JSIndexable {
return allMatchesInStringUnchecked(this, str);
}
+ Match matchAsPrefix(String string, [int start = 0]) {
+ if (start < 0 || start > string.length) {
+ throw new RangeError.range(start, 0, string.length);
+ }
+ if (start + this.length > string.length) return null;
+ // TODO(lrn): See if this can be optimized.
+ for (int i = 0; i < this.length; i++) {
+ if (string.codeUnitAt(start + i) != this.codeUnitAt(i)) {
+ return null;
+ }
+ }
+ return new StringMatch(start, string, this);
+ }
+
String operator +(String other) {
if (other is !String) throw new ArgumentError(other);
return JS('String', r'# + #', this, other);

Powered by Google App Engine
This is Rietveld 408576698