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 // TODO(jmesserly): would be nice to have this on String (dartbug.com/6501). |
5 /** | 6 /** |
6 * Provide a list of Unicode codepoints for a given string. | 7 * Provide a list of Unicode codepoints for a given string. |
7 */ | 8 */ |
8 List<int> stringToCodepoints(String str) { | 9 List<int> stringToCodepoints(String str) { |
9 List<int> codepoints; | 10 // Note: str.charCodes gives us 16-bit code units on all Dart implementations. |
10 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js | 11 // So we need to convert. The same is not true of "new String.fromCharCodes", |
11 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider | 12 // which accepts code points on the VM but not dart2js (dartbug.com/1357). |
12 // removing after this issue is resolved. | 13 return _utf16CodeUnitsToCodepoints(str.charCodes); |
13 if (_is16BitCodeUnit()) { | |
14 codepoints = _utf16CodeUnitsToCodepoints(str.charCodes); | |
15 } else { | |
16 codepoints = str.charCodes; | |
17 } | |
18 return codepoints; | |
19 } | 14 } |
20 | 15 |
21 /** | 16 /** |
22 * Generate a string from the provided Unicode codepoints. | 17 * Generate a string from the provided Unicode codepoints. |
23 */ | 18 */ |
24 String codepointsToString(List<int> codepoints) { | 19 String codepointsToString(List<int> codepoints) { |
25 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js | 20 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js |
26 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider | 21 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider |
27 // removing after this issue is resolved. | 22 // removing after this issue is resolved. |
28 if (_is16BitCodeUnit()) { | 23 if (_is16BitCodeUnit()) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 _offset -= by; | 261 _offset -= by; |
267 } | 262 } |
268 | 263 |
269 int get remaining => _end - _offset; | 264 int get remaining => _end - _offset; |
270 | 265 |
271 void skip([int count = 1]) { | 266 void skip([int count = 1]) { |
272 _offset += count; | 267 _offset += count; |
273 } | 268 } |
274 } | 269 } |
275 | 270 |
OLD | NEW |