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 6482d8bf0dc0c08f8bab289be3b2604cfd66506f..8e99cde8f92f3e9d071087513c60ac6c83f5adfb 100644 |
--- a/sdk/lib/_internal/lib/js_string.dart |
+++ b/sdk/lib/_internal/lib/js_string.dart |
@@ -226,20 +226,13 @@ class JSString extends Interceptor implements String, JSIndexable { |
return JS('String', r'#.substring(#, #)', result, startIndex, endIndex); |
} |
- String repeat(int times, [String separator = ""]) { |
- if (times < 0) throw new RangeError.value(times); |
- if (times == 0) return ""; |
- if (separator.isEmpty) { |
- return JS('String', "new Array(# + 1).join(#)", times, this); |
- } else { |
- var list = new JSArray.growable(times); |
- for (int i = 0; i < times; i++) list[i] = this; |
- return JS('String', "#.join(#)", list, separator); |
- } |
+ String operator*(int times) { |
+ if (times <= 0) return ""; |
+ if (times == 1) return this; |
+ return JS('String', "new Array(# + 1).join(#)", times, this); |
sra1
2014/02/19 21:18:09
I'm a bit nervous of this idiom (in all three plac
Lasse Reichstein Nielsen
2014/02/20 07:16:40
I've incorporated your CL, so all this goes away.
|
} |
- String padLeft(int newLength, String padding) { |
- if (padding.length != 1) throw new ArgumentError(padding); |
+ String padLeft(int newLength, [String padding = ' ']) { |
int delta = newLength - this.length; |
if (delta <= 0) return this; |
var list = new JSArray.growable(delta + 1); |
@@ -247,8 +240,7 @@ class JSString extends Interceptor implements String, JSIndexable { |
return JS("String", "#.join(#)", list, padding); |
sra1
2014/02/19 21:18:09
Single quotes to match the rest of the file.
|
} |
- String padRight(int newLength, String padding) { |
- if (padding.length != 1) throw new ArgumentError(padding); |
+ String padRight(int newLength, [String padding = ' ']) { |
int delta = newLength - this.length; |
if (delta <= 0) return this; |
var list = new JSArray.growable(delta + 1); |