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

Side by Side Diff: utils/string_encoding/unicode.dart

Issue 9410001: restructure string decoding to support iterable use and include benchmarks for UTF-8 decoding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
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 #library("unicode"); 5 #library("unicode");
6 #import("unicode_core.dart"); 6 #import("unicode_core.dart");
7 7
8 /** 8 /**
9 * Provide Unicode codepoints for a given string. 9 * Provide a list of Unicode codepoints for a given string.
10 */ 10 */
11 List<int> stringToCodepoints(String str) { 11 List<int> stringToCodepoints(String str) {
12 List<int> codepoints; 12 List<int> codepoints;
13 // TODO is16BitCodeUnit() is used to work around a bug with frog/dartc 13 // TODO is16BitCodeUnit() is used to work around a bug with frog/dartc
14 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider 14 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider
15 // removing after this issue is resolved. 15 // removing after this issue is resolved.
16 if (is16BitCodeUnit()) { 16 if (is16BitCodeUnit()) {
17 codepoints = utf16CodeUnitsToCodepoints(str.charCodes()); 17 codepoints = utf16CodeUnitsToCodepoints(str.charCodes());
18 } else { 18 } else {
19 codepoints = str.charCodes(); 19 codepoints = str.charCodes();
20 } 20 }
21 return codepoints; 21 return codepoints;
22 } 22 }
23 23
24 /** 24 /**
25 * Generate a string for the provided Unicode codepoints. 25 * Generate a string from the provided Unicode codepoints.
26 */ 26 */
27 String codepointsToString(List<int> codepoints) { 27 String codepointsToString(List<int> codepoints) {
28 // TODO is16BitCodeUnit() is used to work around a bug with frog/dartc 28 // TODO is16BitCodeUnit() is used to work around a bug with frog/dartc
29 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider 29 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider
30 // removing after this issue is resolved. 30 // removing after this issue is resolved.
31 if (is16BitCodeUnit()) { 31 if (is16BitCodeUnit()) {
32 return new String.fromCharCodes( 32 return new String.fromCharCodes(
33 codepointsToUtf16CodeUnits(codepoints)); 33 codepointsToUtf16CodeUnits(codepoints));
34 } else { 34 } else {
35 return new String.fromCharCodes(codepoints); 35 return new String.fromCharCodes(codepoints);
36 } 36 }
37 } 37 }
OLDNEW
« no previous file with comments | « no previous file | utils/string_encoding/unicode_core.dart » ('j') | utils/string_encoding/unicode_core.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698