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

Unified Diff: utils/string_encoding/Unicode.dart

Issue 9233041: String encoding utility methods and tests for Unicode, UTF-8, -16 and -32. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove notes to self Created 8 years, 11 months 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 | « no previous file | utils/string_encoding/UnicodeCore.dart » ('j') | utils/string_encoding/UnicodeCore.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/string_encoding/Unicode.dart
diff --git a/utils/string_encoding/Unicode.dart b/utils/string_encoding/Unicode.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bc4b53bcbd158b0af0dcb3d4674208f6df2bd17b
--- /dev/null
+++ b/utils/string_encoding/Unicode.dart
@@ -0,0 +1,37 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+#library("Unicode");
Søren Gjesse 2012/02/01 11:25:25 I think our current naming scheme for libraries is
dcarlson 2012/02/01 22:18:46 Done.
+#import("UnicodeCore.dart");
Søren Gjesse 2012/02/01 11:25:25 Same for file names. All Dart files in e.g. coreli
dcarlson 2012/02/01 22:18:46 Done.
+
+/**
+ * Provide Unicode codepoints for a given string.
+ */
+List<int> stringToCodepoints(String str) {
+ List<int> codepoints;
+ // TODO is16BitCodeUnit() is used to work around a bug with frog/dartc
+ // (http://code.google.com/p/dart/issues/detail?id=1357). Consider
+ // removing after this issue is resolved.
+ if (is16BitCodeUnit()) {
+ codepoints = utf16CodeUnitsToCodepoints(str.charCodes());
+ } else {
+ codepoints = str.charCodes();
+ }
+ return codepoints;
+}
+
+/**
+ * Generate a string for the provided Unicode codepoints.
+ */
+String codepointsToString(List<int> codepoints) {
+ // TODO is16BitCodeUnit() is used to work around a bug with frog/dartc
+ // (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);
+ }
+}
« no previous file with comments | « no previous file | utils/string_encoding/UnicodeCore.dart » ('j') | utils/string_encoding/UnicodeCore.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698