Chromium Code Reviews| 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.
|
| + } |
| +} |