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

Side by Side Diff: sdk/lib/core/string.dart

Issue 949753005: Add String.replaceRange and use it in replaceFirst{,Mapped}. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * A sequence of characters. 8 * A sequence of characters.
9 * 9 *
10 * A string can be either single or multiline. Single line strings are 10 * A string can be either single or multiline. Single line strings are
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 * 470 *
471 * pigLatin(String words) => words.replaceAllMapped( 471 * pigLatin(String words) => words.replaceAllMapped(
472 * new RegExp(r'\b(\w*?)([aeiou]\w*)', caseSensitive: false), 472 * new RegExp(r'\b(\w*?)([aeiou]\w*)', caseSensitive: false),
473 * (Match m) => "${m[2]}${m[1]}${m[1].isEmpty ? 'way' : 'ay'}"); 473 * (Match m) => "${m[2]}${m[1]}${m[1].isEmpty ? 'way' : 'ay'}");
474 * 474 *
475 * pigLatin('I have a secret now!'); // 'Iway avehay away ecretsay ownay!' 475 * pigLatin('I have a secret now!'); // 'Iway avehay away ecretsay ownay!'
476 */ 476 */
477 String replaceAllMapped(Pattern from, String replace(Match match)); 477 String replaceAllMapped(Pattern from, String replace(Match match));
478 478
479 /** 479 /**
480 * Replaces the substring from [start] to [end] with [replacement].
481 *
482 * Returns a new string equivalent to:
483 *
484 * this.substring(0, start) + replacement + this.substring(end)
485 *
486 * The [start] and [end] indices must specify a valid range of this string.
487 * That is `0 <= start <= end <= this.length`.
488 * If [end] is `null`, it defaults to [length].
489 */
490 String replaceRange(int start, int end, String replacement);
491
492 /**
480 * Splits the string at matches of [pattern] and returns a list of substrings. 493 * Splits the string at matches of [pattern] and returns a list of substrings.
481 * 494 *
482 * Finds all the matches of `pattern` in this string, 495 * Finds all the matches of `pattern` in this string,
483 * and returns the list of the substrings between the matches. 496 * and returns the list of the substrings between the matches.
484 * 497 *
485 * var string = "Hello world!"; 498 * var string = "Hello world!";
486 * string.split(" "); // ['Hello', 'world!']; 499 * string.split(" "); // ['Hello', 'world!'];
487 * 500 *
488 * Empty matches at the beginning and end of the strings are ignored, 501 * Empty matches at the beginning and end of the strings are ignored,
489 * and so are empty matches right after another match. 502 * and so are empty matches right after another match.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 _position = position - 1; 784 _position = position - 1;
772 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); 785 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit);
773 return true; 786 return true;
774 } 787 }
775 } 788 }
776 _position = position; 789 _position = position;
777 _currentCodePoint = codeUnit; 790 _currentCodePoint = codeUnit;
778 return true; 791 return true;
779 } 792 }
780 } 793 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/string_helper.dart ('k') | tests/corelib/string_replace_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698