Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of _interceptors; | 5 part of _interceptors; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The interceptor class for [String]. The compiler recognizes this | 8 * The interceptor class for [String]. The compiler recognizes this |
| 9 * class as an interceptor, and changes references to [:this:] to | 9 * class as an interceptor, and changes references to [:this:] to |
| 10 * actually use the receiver of the method, which is generated as an extra | 10 * actually use the receiver of the method, which is generated as an extra |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 endIndex--; | 219 endIndex--; |
| 220 } else { | 220 } else { |
| 221 break; | 221 break; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 if (startIndex == 0 && endIndex == result.length) return result; | 225 if (startIndex == 0 && endIndex == result.length) return result; |
| 226 return JS('String', r'#.substring(#, #)', result, startIndex, endIndex); | 226 return JS('String', r'#.substring(#, #)', result, startIndex, endIndex); |
| 227 } | 227 } |
| 228 | 228 |
| 229 String repeat(int times, [String separator = ""]) { | 229 String operator*(int times) { |
| 230 if (times < 0) throw new RangeError.value(times); | 230 if (times <= 0) return ""; |
| 231 if (times == 0) return ""; | 231 if (times == 1) return this; |
| 232 if (separator.isEmpty) { | 232 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.
| |
| 233 return JS('String', "new Array(# + 1).join(#)", times, this); | |
| 234 } else { | |
| 235 var list = new JSArray.growable(times); | |
| 236 for (int i = 0; i < times; i++) list[i] = this; | |
| 237 return JS('String', "#.join(#)", list, separator); | |
| 238 } | |
| 239 } | 233 } |
| 240 | 234 |
| 241 String padLeft(int newLength, String padding) { | 235 String padLeft(int newLength, [String padding = ' ']) { |
| 242 if (padding.length != 1) throw new ArgumentError(padding); | |
| 243 int delta = newLength - this.length; | 236 int delta = newLength - this.length; |
| 244 if (delta <= 0) return this; | 237 if (delta <= 0) return this; |
| 245 var list = new JSArray.growable(delta + 1); | 238 var list = new JSArray.growable(delta + 1); |
| 246 list[delta] = this; | 239 list[delta] = this; |
|
sra1
2014/02/19 21:18:09
Current range analysis does not seem to eliminate
| |
| 247 return JS("String", "#.join(#)", list, padding); | 240 return JS("String", "#.join(#)", list, padding); |
|
sra1
2014/02/19 21:18:09
Single quotes to match the rest of the file.
| |
| 248 } | 241 } |
| 249 | 242 |
| 250 String padRight(int newLength, String padding) { | 243 String padRight(int newLength, [String padding = ' ']) { |
| 251 if (padding.length != 1) throw new ArgumentError(padding); | |
| 252 int delta = newLength - this.length; | 244 int delta = newLength - this.length; |
| 253 if (delta <= 0) return this; | 245 if (delta <= 0) return this; |
| 254 var list = new JSArray.growable(delta + 1); | 246 var list = new JSArray.growable(delta + 1); |
| 255 list[0] = this; | 247 list[0] = this; |
| 256 return JS("String", "#.join(#)", list, padding); | 248 return JS("String", "#.join(#)", list, padding); |
| 257 } | 249 } |
| 258 | 250 |
| 259 List<int> get codeUnits => new _CodeUnits(this); | 251 List<int> get codeUnits => new _CodeUnits(this); |
| 260 | 252 |
| 261 Runes get runes => new Runes(this); | 253 Runes get runes => new Runes(this); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 */ | 351 */ |
| 360 class _CodeUnits extends UnmodifiableListBase<int> { | 352 class _CodeUnits extends UnmodifiableListBase<int> { |
| 361 /** The string that this is the code units of. */ | 353 /** The string that this is the code units of. */ |
| 362 String _string; | 354 String _string; |
| 363 | 355 |
| 364 _CodeUnits(this._string); | 356 _CodeUnits(this._string); |
| 365 | 357 |
| 366 int get length => _string.length; | 358 int get length => _string.length; |
| 367 int operator[](int i) => _string.codeUnitAt(i); | 359 int operator[](int i) => _string.codeUnitAt(i); |
| 368 } | 360 } |
| OLD | NEW |