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, String replacement, [int startIndex = 0]) { |
|
Lasse Reichstein Nielsen
2014/08/13 08:35:09
long line.
srawlins
2014/08/14 00:42:44
Done.
| |
| 418 if (pattern is! Pattern) { | 418 if (pattern is! Pattern) { |
| 419 throw new ArgumentError("${pattern} is not a Pattern"); | 419 throw new ArgumentError("${pattern} is not a Pattern"); |
| 420 } | 420 } |
| 421 if (replacement is! String) { | 421 if (replacement is! String) { |
| 422 throw new ArgumentError("${replacement} is not a String"); | 422 throw new ArgumentError("${replacement} is not a String"); |
| 423 } | 423 } |
| 424 if ((startIndex < 0) || (startIndex > this.length)) { | |
| 425 throw new RangeError.value(startIndex); | |
|
Lasse Reichstein Nielsen
2014/08/13 08:35:09
You can use
throw new RangeError.range(startInde
srawlins
2014/08/14 00:42:44
Done.
| |
| 426 } | |
| 424 StringBuffer buffer = new StringBuffer(); | 427 StringBuffer buffer = new StringBuffer(); |
|
Bill Hesse
2014/08/11 07:47:47
This could be made more efficient by moving the St
srawlins
2014/08/14 00:42:44
Done.
| |
| 425 int startIndex = 0; | 428 buffer.write(this.substring(0, startIndex)); |
| 426 Iterator iterator = pattern.allMatches(this).iterator; | 429 String remaining = this.substring(startIndex); |
|
Lasse Reichstein Nielsen
2014/08/11 08:13:32
Creating a substring, and then using allMatches, i
Lasse Reichstein Nielsen
2014/08/11 09:37:11
This implementation is actually wrong: A "^" must
Lasse Reichstein Nielsen
2014/08/13 08:35:09
And now we DO have start-index on allMatches, so t
srawlins
2014/08/14 00:42:44
Done. Thanks very much for this cleanup!
srawlins
2014/08/14 00:42:44
Good catch. This implementation now depends on pas
srawlins
2014/08/14 00:42:44
Thanks for the patch to Pattern.allMatches! This i
| |
| 430 Iterator iterator = pattern.allMatches(remaining).iterator; | |
| 427 if (iterator.moveNext()) { | 431 if (iterator.moveNext()) { |
| 428 Match match = iterator.current; | 432 Match match = iterator.current; |
| 429 buffer..write(this.substring(startIndex, match.start)) | 433 buffer..write(remaining.substring(0, match.start)) |
| 430 ..write(replacement); | 434 ..write(replacement); |
| 431 startIndex = match.end; | 435 startIndex = match.end; |
| 432 } | 436 } |
| 433 return (buffer..write(this.substring(startIndex))).toString(); | 437 return (buffer..write(remaining.substring(startIndex))).toString(); |
| 434 } | 438 } |
| 435 | 439 |
| 436 String replaceAll(Pattern pattern, String replacement) { | 440 String replaceAll(Pattern pattern, String replacement) { |
| 437 if (pattern is! Pattern) { | 441 if (pattern is! Pattern) { |
| 438 throw new ArgumentError("${pattern} is not a Pattern"); | 442 throw new ArgumentError("${pattern} is not a Pattern"); |
| 439 } | 443 } |
| 440 if (replacement is! String) { | 444 if (replacement is! String) { |
| 441 throw new ArgumentError( | 445 throw new ArgumentError( |
| 442 "${replacement} is not a String or Match->String function"); | 446 "${replacement} is not a String or Match->String function"); |
| 443 } | 447 } |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 class _CodeUnits extends Object with ListMixin<int>, | 1008 class _CodeUnits extends Object with ListMixin<int>, |
| 1005 UnmodifiableListMixin<int> { | 1009 UnmodifiableListMixin<int> { |
| 1006 /** The string that this is the code units of. */ | 1010 /** The string that this is the code units of. */ |
| 1007 String _string; | 1011 String _string; |
| 1008 | 1012 |
| 1009 _CodeUnits(this._string); | 1013 _CodeUnits(this._string); |
| 1010 | 1014 |
| 1011 int get length => _string.length; | 1015 int get length => _string.length; |
| 1012 int operator[](int i) => _string.codeUnitAt(i); | 1016 int operator[](int i) => _string.codeUnitAt(i); |
| 1013 } | 1017 } |
| OLD | NEW |