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

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

Issue 920453002: Add String.replaceFirstMapped. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: With change to _interpolate methods. 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 * index: 407 * index:
408 * 408 *
409 * string.contains('X', 1); // false 409 * string.contains('X', 1); // false
410 * string.contains(new RegExp(r'[A-Z]'), 1); // false 410 * string.contains(new RegExp(r'[A-Z]'), 1); // false
411 * 411 *
412 * [startIndex] must not be negative or greater than [length]. 412 * [startIndex] must not be negative or greater than [length].
413 */ 413 */
414 bool contains(Pattern other, [int startIndex = 0]); 414 bool contains(Pattern other, [int startIndex = 0]);
415 415
416 /** 416 /**
417 * Returns a new string in which the first occurence of [from] in this string 417 * Returns a new string in which the first occurence of [from] in this string
418 * is replaced with [to], starting from [startIndex]: 418 * is replaced with [to], starting from [startIndex]:
419 * 419 *
420 * '0.0001'.replaceFirst(new RegExp(r'0'), ''); // '.0001' 420 * '0.0001'.replaceFirst(new RegExp(r'0'), ''); // '.0001'
421 * '0.0001'.replaceFirst(new RegExp(r'0'), '7', 1); // '0.7001' 421 * '0.0001'.replaceFirst(new RegExp(r'0'), '7', 1); // '0.7001'
422 */ 422 */
423 String replaceFirst(Pattern from, String to, [int startIndex = 0]); 423 String replaceFirst(Pattern from, String to, [int startIndex = 0]);
424 424
425 /** 425 /**
426 * Replace the first occurence of [from] in this string.
427 *
428 * Returns a new string, which is this string
429 * except that the first match of [pattern], starting from [startIndex],
430 * is replaced by the result of calling [replace] with the match object.
431 *
432 * If the value returned by calling `replace` is not a [String], it
433 * is converted to a `String` using its `toString` method, which must
434 * then return a string.
435 */
436 String replaceFirstMapped(Pattern from, String replace(Match match),
437 [int startIndex = 0]);
438
439 /**
426 * Replaces all substrings that match [from] with [replace]. 440 * Replaces all substrings that match [from] with [replace].
427 * 441 *
428 * Returns a new string in which the non-overlapping substrings matching 442 * Returns a new string in which the non-overlapping substrings matching
429 * [from] (the ones iterated by `from.allMatches(thisString)`) are replaced 443 * [from] (the ones iterated by `from.allMatches(thisString)`) are replaced
430 * by the literal string [replace]. 444 * by the literal string [replace].
431 * 445 *
432 * 'resume'.replaceAll(new RegExp(r'e'), 'é'); // 'résumé' 446 * 'resume'.replaceAll(new RegExp(r'e'), 'é'); // 'résumé'
433 * 447 *
434 * Notice that the [replace] string is not interpreted. If the replacement 448 * Notice that the [replace] string is not interpreted. If the replacement
435 * depends on the match (for example on a [RegExp]'s capture groups), use 449 * depends on the match (for example on a [RegExp]'s capture groups), use
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 _position = position - 1; 771 _position = position - 1;
758 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); 772 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit);
759 return true; 773 return true;
760 } 774 }
761 } 775 }
762 _position = position; 776 _position = position;
763 _currentCodePoint = codeUnit; 777 _currentCodePoint = codeUnit;
764 return true; 778 return true;
765 } 779 }
766 } 780 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698