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

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: String encoding utility methods and tests for Unicode, UTF-8, -16 and -32. 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..8f107595e8a59ab49eb5c20f95e0c986bbdb21a7
--- /dev/null
+++ b/utils/string_encoding/Unicode.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
jat 2012/01/31 15:19:22 Copyright date.
dcarlson 2012/01/31 22:11:38 Done.
+// 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");
+#import("UnicodeCore.dart");
+
+/**
+ * Provide Unicode codepoints for a given string.
+ */
+List<int> stringToCodepoints(String str) {
+ List<int> codepoints;
+ if (is16BitCodeUnit()) {
ahe 2012/01/31 14:46:53 I think you're working around bug in frog or dartc
dcarlson 2012/01/31 15:07:34 Done.
Dan Rice 2012/01/31 15:59:55 +1
+ codepoints = utf16CodeUnitsToCodepoints(str.charCodes());
+ } else {
+ codepoints = str.charCodes();
+ }
+ return codepoints;
+}
+
+/**
+ * Generate a string for the provided Unicode codepoints.
+ */
+String codepointsToString(List<int> codepoints) {
+ if (is16BitCodeUnit()) {
+ return (new String.fromCharCodes(
Dan Rice 2012/01/31 15:59:55 No need for parens around return value
dcarlson 2012/01/31 22:11:38 Done.
+ codepointsToUtf16CodeUnits(codepoints)));
+ } else {
+ return (new String.fromCharCodes(codepoints));
Dan Rice 2012/01/31 15:59:55 Ditto
dcarlson 2012/01/31 22:11:38 Done.
+ }
+}
« 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