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

Unified Diff: sdk/lib/core/string.dart

Issue 677013002: Make dart2js String.split match the VM version. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also add documentation to String.split. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/regexp_helper.dart ('k') | tests/corelib/string_split_reg_exp_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/string.dart
diff --git a/sdk/lib/core/string.dart b/sdk/lib/core/string.dart
index 90e6b508b6b14eacbb5985033be2aa3814879207..8366764cab00681c103685058e6069f499e57d05 100644
--- a/sdk/lib/core/string.dart
+++ b/sdk/lib/core/string.dart
@@ -463,11 +463,30 @@ abstract class String implements Comparable<String>, Pattern {
String replaceAllMapped(Pattern from, String replace(Match match));
/**
- * Splits the string at matches of [pattern]. Returns
- * a list of substrings.
+ * Splits the string at matches of [pattern] and returns a list of substrings.
*
- * Splitting with an empty string pattern (`''`) splits at UTF-16 code unit
- * boundaries and not at rune boundaries:
+ * Finds all the matches of `pattern` in this string,
+ * and returns the list of the substrings between the matches.
+ *
+ * var string = "Hello world!";
+ * string.split(" "); // ['Hello', 'world!'];
+ *
+ * Empty matches at the beginning and end of the strings are ignored,
+ * and so are empty matches right after another match.
+ *
+ * var string = "abba";
+ * string.split(new RegExp(r"b*")); // ['a', 'a']
+ * // not ['', 'a', 'a', '']
+ *
+ * If this string is empty, the result is an empty list if `pattern` matches
+ * the empty string, and it is `[""]` if the pattern doesn't match.
+ *
+ * var string = '';
+ * string.split(''); // []
+ * string.split("a"); // ['']
+ *
+ * Splitting happends at UTF-16 code unit boundaries,
Søren Gjesse 2014/10/27 08:35:04 Add 'NOTE:'
Lasse Reichstein Nielsen 2014/10/28 10:15:04 I try to avoid writing "NOTE" or "NOTICE" unless s
+ * and not at rune boundaries:
*
* var string = 'Pub';
* string.split(''); // ['P', 'u', 'b']
@@ -480,11 +499,11 @@ abstract class String implements Comparable<String>, Pattern {
* string = '\u{1D11E}';
* string.split('').length; // 2
*
- * You should [map] the runes unless you are certain that the string is in
- * the basic multilingual plane (meaning that each code unit represents a
- * rune):
+ * To get a list of strings containing the individual runes of a string,
+ * you should not use split. You can instead map each rune to a string
+ * as follows:
*
- * string.runes.map((rune) => new String.fromCharCode(rune));
+ * string.runes.map((rune) => new String.fromCharCode(rune)).toList();
*/
List<String> split(Pattern pattern);
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/regexp_helper.dart ('k') | tests/corelib/string_split_reg_exp_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698