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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/utf/utf8.dart ('k') | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/utf/utf_core.dart
diff --git a/sdk/lib/utf/utf_core.dart b/sdk/lib/utf/utf_core.dart
index f22290bf23e3b7c8f19c25dbd746b2f5575bcdce..a1cedcece985c193b05a446ef78147a3bfc7d212 100644
--- a/sdk/lib/utf/utf_core.dart
+++ b/sdk/lib/utf/utf_core.dart
@@ -2,6 +2,48 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// TODO(jmesserly): would be nice to have this on String (dartbug.com/6501).
+/**
+ * Provide a list of Unicode codepoints for a given string.
+ */
+List<int> stringToCodepoints(String str) {
+ // Note: str.charCodes gives us 16-bit code units on all Dart implementations.
+ // So we need to convert. The same is not true of "new String.fromCharCodes",
+ // which accepts code points on the VM but not dart2js (dartbug.com/1357).
+ return _utf16CodeUnitsToCodepoints(str.charCodes);
+}
+
+/**
+ * Generate a string from the provided Unicode codepoints.
+ */
+String codepointsToString(List<int> codepoints) {
+ // TODO _is16BitCodeUnit() is used to work around a bug with dart2js
+ // (http://code.google.com/p/dart/issues/detail?id=1357). Consider
+ // removing after this issue is resolved.
+ if (_is16BitCodeUnit()) {
+ return new String.fromCharCodes(
+ _codepointsToUtf16CodeUnits(codepoints));
+ } else {
+ return new String.fromCharCodes(codepoints);
+ }
+}
+
+/*
+ * Test for presence of bug related to the use of UTF-16 code units for
+ * Dart compiled to JS.
+ */
+bool _test16BitCodeUnit = null;
+// TODO _is16BitCodeUnit() is used to work around a bug with dart2js
+// (http://code.google.com/p/dart/issues/detail?id=1357). Consider
+// removing after this issue is resolved.
+bool _is16BitCodeUnit() {
+ if (_test16BitCodeUnit == null) {
+ _test16BitCodeUnit = (new String.fromCharCodes([0x1D11E])) ==
+ (new String.fromCharCodes([0xD11E]));
+ }
+ return _test16BitCodeUnit;
+}
+
/**
* Invalid codepoints or encodings may be substituted with the value U+fffd.
*/
« 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