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

Side by Side Diff: sdk/lib/utf/utf_core.dart

Issue 11418115: Fix Unicode issues in dart2js and dart2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove accidental test expectation dupe 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 // TODO(jmesserly): would be nice to have this on String (dartbug.com/6501). 5 // TODO(jmesserly): would be nice to have this on String (dartbug.com/6501).
6 /** 6 /**
7 * Provide a list of Unicode codepoints for a given string. 7 * Provide a list of Unicode codepoints for a given string.
8 */ 8 */
9 List<int> stringToCodepoints(String str) { 9 List<int> stringToCodepoints(String str) {
10 // Note: str.charCodes gives us 16-bit code units on all Dart implementations. 10 // Note: str.charCodes gives us 16-bit code units on all Dart implementations.
11 // So we need to convert. The same is not true of "new String.fromCharCodes", 11 // So we need to convert.
12 // which accepts code points on the VM but not dart2js (dartbug.com/1357).
13 return _utf16CodeUnitsToCodepoints(str.charCodes); 12 return _utf16CodeUnitsToCodepoints(str.charCodes);
14 } 13 }
15 14
16 /** 15 /**
17 * Generate a string from the provided Unicode codepoints. 16 * Generate a string from the provided Unicode codepoints.
18 */ 17 */
19 String codepointsToString(List<int> codepoints) { 18 String codepointsToString(List<int> codepoints) {
20 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js 19 return new String.fromCharCodes(codepoints);
21 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider
22 // removing after this issue is resolved.
23 if (_is16BitCodeUnit()) {
24 return new String.fromCharCodes(
25 _codepointsToUtf16CodeUnits(codepoints));
26 } else {
27 return new String.fromCharCodes(codepoints);
28 }
29 }
30
31 /*
32 * Test for presence of bug related to the use of UTF-16 code units for
33 * Dart compiled to JS.
34 */
35 bool _test16BitCodeUnit = null;
36 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js
37 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider
38 // removing after this issue is resolved.
39 bool _is16BitCodeUnit() {
40 if (_test16BitCodeUnit == null) {
41 _test16BitCodeUnit = (new String.fromCharCodes([0x1D11E])) ==
42 (new String.fromCharCodes([0xD11E]));
43 }
44 return _test16BitCodeUnit;
45 } 20 }
46 21
47 /** 22 /**
48 * Invalid codepoints or encodings may be substituted with the value U+fffd. 23 * Invalid codepoints or encodings may be substituted with the value U+fffd.
49 */ 24 */
50 const int UNICODE_REPLACEMENT_CHARACTER_CODEPOINT = 0xfffd; 25 const int UNICODE_REPLACEMENT_CHARACTER_CODEPOINT = 0xfffd;
51 const int UNICODE_BOM = 0xfeff; 26 const int UNICODE_BOM = 0xfeff;
52 const int UNICODE_UTF_BOM_LO = 0xff; 27 const int UNICODE_UTF_BOM_LO = 0xff;
53 const int UNICODE_UTF_BOM_HI = 0xfe; 28 const int UNICODE_UTF_BOM_HI = 0xfe;
54 29
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 _offset -= by; 236 _offset -= by;
262 } 237 }
263 238
264 int get remaining => _end - _offset; 239 int get remaining => _end - _offset;
265 240
266 void skip([int count = 1]) { 241 void skip([int count = 1]) {
267 _offset += count; 242 _offset += count;
268 } 243 }
269 } 244 }
270 245
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698