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 patch class String { | 5 patch class String { |
| 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { | 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { |
| 7 return _StringBase.createFromCharCodes(charCodes); | 7 return _StringBase.createFromCharCodes(charCodes); |
| 8 } | 8 } |
| 9 | 9 |
| 10 /* patch */ factory String.fromCharCode(int charCode) { | 10 /* patch */ factory String.fromCharCode(int charCode) { |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 bool contains(Pattern pattern, [int startIndex = 0]) { | 407 bool contains(Pattern pattern, [int startIndex = 0]) { |
| 408 if (pattern is String) { | 408 if (pattern is String) { |
| 409 if (startIndex < 0 || startIndex > this.length) { | 409 if (startIndex < 0 || startIndex > this.length) { |
| 410 throw new RangeError.range(startIndex, 0, this.length); | 410 throw new RangeError.range(startIndex, 0, this.length); |
| 411 } | 411 } |
| 412 return indexOf(pattern, startIndex) >= 0; | 412 return indexOf(pattern, startIndex) >= 0; |
| 413 } | 413 } |
| 414 return pattern.allMatches(this.substring(startIndex)).isNotEmpty; | 414 return pattern.allMatches(this.substring(startIndex)).isNotEmpty; |
| 415 } | 415 } |
| 416 | 416 |
| 417 String replaceFirst(Pattern pattern, String replacement) { | 417 String replaceFirst(Pattern pattern, |
| 418 String replacement, | |
| 419 [int startIndex = 0]) { | |
| 418 if (pattern is! Pattern) { | 420 if (pattern is! Pattern) { |
| 419 throw new ArgumentError("${pattern} is not a Pattern"); | 421 throw new ArgumentError("${pattern} is not a Pattern"); |
| 420 } | 422 } |
| 421 if (replacement is! String) { | 423 if (replacement is! String) { |
| 422 throw new ArgumentError("${replacement} is not a String"); | 424 throw new ArgumentError("${replacement} is not a String"); |
| 423 } | 425 } |
| 424 StringBuffer buffer = new StringBuffer(); | 426 if (startIndex is! int) { |
| 425 int startIndex = 0; | 427 throw new ArgumentError("${startIndex} is not an int"); |
| 426 Iterator iterator = pattern.allMatches(this).iterator; | |
| 427 if (iterator.moveNext()) { | |
| 428 Match match = iterator.current; | |
| 429 buffer..write(this.substring(startIndex, match.start)) | |
| 430 ..write(replacement); | |
| 431 startIndex = match.end; | |
| 432 } | 428 } |
| 433 return (buffer..write(this.substring(startIndex))).toString(); | 429 if ((startIndex < 0) || (startIndex > this.length)) { |
| 430 throw new RangeError.range(startIndex, 0, this.length); | |
| 431 } | |
| 432 Iterator iterator = | |
| 433 startIndex == 0 ? pattern.allMatches(this).iterator | |
|
Lasse Reichstein Nielsen
2014/08/19 07:26:45
Indent by four.
srawlins
2014/08/19 21:42:32
Done.
| |
| 434 : pattern.allMatches(this, startIndex).iterator; | |
| 435 if (!iterator.moveNext()) return this; | |
| 436 Match match = iterator.current; | |
| 437 return "${this.substring(0, match.start)}" | |
| 438 "$replacement" | |
| 439 "${this.substring(match.end)}"; | |
| 434 } | 440 } |
| 435 | 441 |
| 436 String replaceAll(Pattern pattern, String replacement) { | 442 String replaceAll(Pattern pattern, String replacement) { |
| 437 if (pattern is! Pattern) { | 443 if (pattern is! Pattern) { |
| 438 throw new ArgumentError("${pattern} is not a Pattern"); | 444 throw new ArgumentError("${pattern} is not a Pattern"); |
| 439 } | 445 } |
| 440 if (replacement is! String) { | 446 if (replacement is! String) { |
| 441 throw new ArgumentError( | 447 throw new ArgumentError( |
| 442 "${replacement} is not a String or Match->String function"); | 448 "${replacement} is not a String or Match->String function"); |
| 443 } | 449 } |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 class _CodeUnits extends Object with ListMixin<int>, | 1010 class _CodeUnits extends Object with ListMixin<int>, |
| 1005 UnmodifiableListMixin<int> { | 1011 UnmodifiableListMixin<int> { |
| 1006 /** The string that this is the code units of. */ | 1012 /** The string that this is the code units of. */ |
| 1007 String _string; | 1013 String _string; |
| 1008 | 1014 |
| 1009 _CodeUnits(this._string); | 1015 _CodeUnits(this._string); |
| 1010 | 1016 |
| 1011 int get length => _string.length; | 1017 int get length => _string.length; |
| 1012 int operator[](int i) => _string.codeUnitAt(i); | 1018 int operator[](int i) => _string.codeUnitAt(i); |
| 1013 } | 1019 } |
| OLD | NEW |