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

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

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 /** 5 /**
6 * The String class represents character strings. Strings are 6 * The String class represents character strings. Strings are
7 * immutable. A string is represented by a list of 32-bit Unicode 7 * immutable. A string is represented by a list of 16-bit UTF-16
8 * scalar character codes accessible through the [charCodeAt] or the 8 * code units accessible through the [codeUnitAt] or the [codeUnits]
9 * [charCodes] method. 9 * methods. The corresponding Unicode code points are available with
10 * [charCodeAt] or the [charCodes] method.
10 */ 11 */
11 interface String 12 interface String
12 extends Comparable, Pattern, Sequence<String> 13 extends Comparable, Pattern, Sequence<String>
13 default _StringImpl { 14 default _StringImpl {
14 /** 15 /**
15 * Allocates a new String for the specified [charCodes]. 16 * Allocates a new String for the specified 21 bit Unicode [codePoints].
16 */ 17 */
17 String.fromCharCodes(List<int> charCodes); 18 String.fromCharCodes(List<int> codePoints);
18 19
19 /** 20 /**
20 * Gets the character (as [String]) at the given [index]. 21 * Allocates a new String for the specified 16 bit UTF-16 [codeUnits].
22 */
23 String.fromCodeUnits(List<int> codeUnits);
24
25 /**
26 * Gets the Unicode character (as [String]) at the given [index]. This
27 * routine can return a single combining character (accent) that would
28 * normally be displayed together with the character it is modifying.
29 * If the index corresponds to the first of two UTF-16 surrogate pair
floitsch 2012/11/08 15:28:21 Update comment.
erikcorry 2012/11/15 13:28:25 Done.
30 * code units then it will return a string containing the Unicode
31 * character corresponding to the pair.
21 */ 32 */
22 String operator [](int index); 33 String operator [](int index);
23 34
24 /** 35 /**
25 * Gets the scalar character code at the given [index]. 36 * Gets the 21 bit Unicode code point at the given [index]. Surrogate
37 * pairs are handled as in [operator []].
floitsch 2012/11/08 15:28:21 Update comment.
erikcorry 2012/11/15 13:28:25 Done.
26 */ 38 */
27 int charCodeAt(int index); 39 int charCodeAt(int index);
28 40
29 /** 41 /**
30 * The length of the string. 42 * Gets the 16 bit UTF-16 code unit at the given index.
floitsch 2012/11/08 15:28:21 Update comment (now same as [operator []]).
erikcorry 2012/11/15 13:28:25 Done.
erikcorry 2012/11/15 13:28:25 Done.
43 */
44 int codeUnitAt(int index);
45
46
47 /**
48 * The length of the string, measured in UTF-16 code units.
31 */ 49 */
32 int get length; 50 int get length;
33 51
34 /** 52 /**
35 * Returns whether the two strings are equal. This method compares 53 * Returns whether the two strings are equal. This method compares
36 * each individual scalar character codes of the strings. 54 * each individual UTF-16 code unit. No Unicode normalization is
55 * performed (accent composition/decomposition).
37 */ 56 */
38 bool operator ==(String other); 57 bool operator ==(String other);
39 58
40 /** 59 /**
41 * Returns whether this string ends with [other]. 60 * Returns whether this string ends with [other].
42 */ 61 */
43 bool endsWith(String other); 62 bool endsWith(String other);
44 63
45 /** 64 /**
46 * Returns whether this string starts with [other]. 65 * Returns whether this string starts with [other].
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 */ 122 */
104 String replaceAll(Pattern from, String to); 123 String replaceAll(Pattern from, String to);
105 124
106 /** 125 /**
107 * Splits the string around matches of [pattern]. Returns 126 * Splits the string around matches of [pattern]. Returns
108 * a list of substrings. 127 * a list of substrings.
109 */ 128 */
110 List<String> split(Pattern pattern); 129 List<String> split(Pattern pattern);
111 130
112 /** 131 /**
113 * Returns a list of the characters of this string. 132 * Returns a list of the characters of this string. No string normalization
133 * is performed so unprecomposed combining characters (accents) may be found
134 * in the list.
114 */ 135 */
115 List<String> splitChars(); 136 List<String> splitChars();
116 137
117 /** 138 /**
118 * Returns a list of the scalar character codes of this string. 139 * Returns a list of the 21 bit Unicode code points of this string.
119 */ 140 */
120 List<int> get charCodes; 141 List<int> get charCodes;
121 142
122 /** 143 /**
144 * Returns a list of the 16 bit UTF-16 code units of this string.
145 */
146 List<int> get codeUnits;
147
148 /**
123 * If this string is not already all lower case, returns a new string 149 * If this string is not already all lower case, returns a new string
124 * where all characters are made lower case. Returns [:this:] otherwise. 150 * where all characters are made lower case. Returns [:this:] otherwise.
125 */ 151 */
126 String toLowerCase(); 152 String toLowerCase();
127 153
128 /** 154 /**
129 * If this string is not already all uper case, returns a new string 155 * If this string is not already all uper case, returns a new string
130 * where all characters are made upper case. Returns [:this:] otherwise. 156 * where all characters are made upper case. Returns [:this:] otherwise.
131 */ 157 */
132 String toUpperCase(); 158 String toUpperCase();
133 } 159 }
134 160
135 class _StringImpl { 161 class _StringImpl {
136 /** 162 /**
137 * Factory implementation of String.fromCharCodes: 163 * Factory implementation of String.fromCharCodes.
138 * Allocates a new String for the specified [charCodes].
139 */ 164 */
140 external factory String.fromCharCodes(List<int> charCodes); 165 external factory String.fromCharCodes(List<int> codePoints);
166
167 /**
168 * Factory implementation of String.fromCodeUnits.
169 */
170 external factory String.fromCodeUnits(List<int> codeUnits);
141 171
142 /** 172 /**
143 * Joins all the given strings to create a new string. 173 * Joins all the given strings to create a new string.
144 */ 174 */
145 external static String join(List<String> strings, String separator); 175 external static String join(List<String> strings, String separator);
146 176
147 /** 177 /**
148 * Concatenates all the given strings to create a new string. 178 * Concatenates all the given strings to create a new string.
149 */ 179 */
150 external static String concatAll(List<String> strings); 180 external static String concatAll(List<String> strings);
151 181
152 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698