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

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

Issue 11411092: Revert "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
« no previous file with comments | « sdk/lib/utf/utf8.dart ('k') | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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).
6 /**
7 * Provide a list of Unicode codepoints for a given string.
8 */
9 List<int> stringToCodepoints(String str) {
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",
12 // which accepts code points on the VM but not dart2js (dartbug.com/1357).
13 return _utf16CodeUnitsToCodepoints(str.charCodes);
14 }
15
16 /**
17 * Generate a string from the provided Unicode codepoints.
18 */
19 String codepointsToString(List<int> codepoints) {
20 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js
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 }
46
5 /** 47 /**
6 * Invalid codepoints or encodings may be substituted with the value U+fffd. 48 * Invalid codepoints or encodings may be substituted with the value U+fffd.
7 */ 49 */
8 const int UNICODE_REPLACEMENT_CHARACTER_CODEPOINT = 0xfffd; 50 const int UNICODE_REPLACEMENT_CHARACTER_CODEPOINT = 0xfffd;
9 const int UNICODE_BOM = 0xfeff; 51 const int UNICODE_BOM = 0xfeff;
10 const int UNICODE_UTF_BOM_LO = 0xff; 52 const int UNICODE_UTF_BOM_LO = 0xff;
11 const int UNICODE_UTF_BOM_HI = 0xfe; 53 const int UNICODE_UTF_BOM_HI = 0xfe;
12 54
13 const int UNICODE_BYTE_ZERO_MASK = 0xff; 55 const int UNICODE_BYTE_ZERO_MASK = 0xff;
14 const int UNICODE_BYTE_ONE_MASK = 0xff00; 56 const int UNICODE_BYTE_ONE_MASK = 0xff00;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 _offset -= by; 261 _offset -= by;
220 } 262 }
221 263
222 int get remaining => _end - _offset; 264 int get remaining => _end - _offset;
223 265
224 void skip([int count = 1]) { 266 void skip([int count = 1]) {
225 _offset += count; 267 _offset += count;
226 } 268 }
227 } 269 }
228 270
OLDNEW
« no previous file with comments | « sdk/lib/utf/utf8.dart ('k') | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698