| 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 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 * | 456 * |
| 457 * pigLatin(String words) => words.replaceAllMapped( | 457 * pigLatin(String words) => words.replaceAllMapped( |
| 458 * new RegExp(r'\b(\w*?)([aeiou]\w*)', caseSensitive: false), | 458 * new RegExp(r'\b(\w*?)([aeiou]\w*)', caseSensitive: false), |
| 459 * (Match m) => "${m[2]}${m[1]}${m[1].isEmpty ? 'way' : 'ay'}"); | 459 * (Match m) => "${m[2]}${m[1]}${m[1].isEmpty ? 'way' : 'ay'}"); |
| 460 * | 460 * |
| 461 * pigLatin('I have a secret now!'); // 'Iway avehay away ecretsay ownay!' | 461 * pigLatin('I have a secret now!'); // 'Iway avehay away ecretsay ownay!' |
| 462 */ | 462 */ |
| 463 String replaceAllMapped(Pattern from, String replace(Match match)); | 463 String replaceAllMapped(Pattern from, String replace(Match match)); |
| 464 | 464 |
| 465 /** | 465 /** |
| 466 * Splits the string at matches of [pattern]. Returns | 466 * Splits the string at matches of [pattern] and returns a list of substrings. |
| 467 * a list of substrings. | |
| 468 * | 467 * |
| 469 * Splitting with an empty string pattern (`''`) splits at UTF-16 code unit | 468 * Finds all the matches of `pattern` in this string, |
| 470 * boundaries and not at rune boundaries: | 469 * and returns the list of the substrings between the matches. |
| 470 * |
| 471 * var string = "Hello world!"; |
| 472 * string.split(" "); // ['Hello', 'world!']; |
| 473 * |
| 474 * Empty matches at the beginning and end of the strings are ignored, |
| 475 * and so are empty matches right after another match. |
| 476 * |
| 477 * var string = "abba"; |
| 478 * string.split(new RegExp(r"b*")); // ['a', 'a'] |
| 479 * // not ['', 'a', 'a', ''] |
| 480 * |
| 481 * If this string is empty, the result is an empty list if `pattern` matches |
| 482 * the empty string, and it is `[""]` if the pattern doesn't match. |
| 483 * |
| 484 * var string = ''; |
| 485 * string.split(''); // [] |
| 486 * string.split("a"); // [''] |
| 487 * |
| 488 * Splitting with an empty pattern splits the string into single-code unit |
| 489 * strings. |
| 471 * | 490 * |
| 472 * var string = 'Pub'; | 491 * var string = 'Pub'; |
| 473 * string.split(''); // ['P', 'u', 'b'] | 492 * string.split(''); // ['P', 'u', 'b'] |
| 474 * | 493 * |
| 475 * string.codeUnits.map((unit) { | 494 * string.codeUnits.map((unit) { |
| 476 * return new String.fromCharCode(unit); | 495 * return new String.fromCharCode(unit); |
| 477 * }).toList(); // ['P', 'u', 'b'] | 496 * }).toList(); // ['P', 'u', 'b'] |
| 478 * | 497 * |
| 498 * Splitting happens at UTF-16 code unit boundaries, |
| 499 * and not at rune boundaries: |
| 500 * |
| 479 * // String made up of two code units, but one rune. | 501 * // String made up of two code units, but one rune. |
| 480 * string = '\u{1D11E}'; | 502 * string = '\u{1D11E}'; |
| 481 * string.split('').length; // 2 | 503 * string.split('').length; // 2 surrogate values |
| 482 * | 504 * |
| 483 * You should [map] the runes unless you are certain that the string is in | 505 * To get a list of strings containing the individual runes of a string, |
| 484 * the basic multilingual plane (meaning that each code unit represents a | 506 * you should not use split. You can instead map each rune to a string |
| 485 * rune): | 507 * as follows: |
| 486 * | 508 * |
| 487 * string.runes.map((rune) => new String.fromCharCode(rune)); | 509 * string.runes.map((rune) => new String.fromCharCode(rune)).toList(); |
| 488 */ | 510 */ |
| 489 List<String> split(Pattern pattern); | 511 List<String> split(Pattern pattern); |
| 490 | 512 |
| 491 /** | 513 /** |
| 492 * Splits the string, converts its parts, and combines them into a new | 514 * Splits the string, converts its parts, and combines them into a new |
| 493 * string. | 515 * string. |
| 494 * | 516 * |
| 495 * [pattern] is used to split the string into parts and separating matches. | 517 * [pattern] is used to split the string into parts and separating matches. |
| 496 * | 518 * |
| 497 * Each match is converted to a string by calling [onMatch]. If [onMatch] | 519 * Each match is converted to a string by calling [onMatch]. If [onMatch] |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 _position = position - 1; | 764 _position = position - 1; |
| 743 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); | 765 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); |
| 744 return true; | 766 return true; |
| 745 } | 767 } |
| 746 } | 768 } |
| 747 _position = position; | 769 _position = position; |
| 748 _currentCodePoint = codeUnit; | 770 _currentCodePoint = codeUnit; |
| 749 return true; | 771 return true; |
| 750 } | 772 } |
| 751 } | 773 } |
| OLD | NEW |