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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_string.dart

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Implemented feedback from patch set 3 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
Index: sdk/lib/_internal/compiler/implementation/lib/js_string.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_string.dart b/sdk/lib/_internal/compiler/implementation/lib/js_string.dart
index d796ef2d39442e16547df701a1e74ab5fe4ef9ea..737aecdfcefbb1878f67cc0b49ce3d62f70da4f1 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_string.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_string.dart
@@ -13,7 +13,7 @@ part of _interceptors;
class JSString implements String {
const JSString();
- int charCodeAt(index) {
+ int codeUnitAt(index) {
if (index is !num) throw new ArgumentError(index);
if (index < 0) throw new RangeError.value(index);
if (index >= length) throw new RangeError.value(index);
@@ -86,10 +86,32 @@ class JSString implements String {
return JS('String', r'#.trim()', this);
}
- List<int> get charCodes {
+ int charCodeAt(int index) {
+ if (index is !num) throw new ArgumentError(index);
+ if (index < 0) throw new RangeError.value(index);
+ if (index >= length) throw new RangeError.value(index);
+ int codeUnit = JS('int', r'#.charCodeAt(#)', this, index);
+ if (codeUnit < 0xd800 || codeUnit >= 0xe000) return codeUnit;
+ if (index + 1 == length) return codeUnit;
+ int codeUnit2 = JS('int', r'#.charCodeAt(#)', this, index + 1);
+ return 0x10000 + ((codeUnit & 0x3ff) << 10) + (codeUnit2 & 0x3ff);
+ }
+
+ List<int> get codeUnits {
List<int> result = new List<int>(length);
for (int i = 0; i < length; i++) {
- result[i] = charCodeAt(i);
+ result[i] = JS('int', '#.charCodeAt(#)', this, i);
+ }
+ return result;
+ }
+
+ List<int> get charCodes {
+ int len = length;
+ List<int> result = <int>[];
+ for (int i = 0, j = 0; i < len; i++, j++) {
+ int code = charCodeAt(i);
+ if (code >= 0x10000) i++;
+ result.add(code);
}
return result;
}

Powered by Google App Engine
This is Rietveld 408576698