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

Unified Diff: sdk/lib/uri/encode_decode.dart

Issue 11411092: Revert "Add some support for the code-point code-unit distinction." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « sdk/lib/io/string_stream.dart ('k') | sdk/lib/utf/utf32.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/uri/encode_decode.dart
diff --git a/sdk/lib/uri/encode_decode.dart b/sdk/lib/uri/encode_decode.dart
index 09473f23ca515101d738ebe15ec731c1a3d39ab0..6338518a4a5a290b2dbfe959912ccbbeb07ffbc4 100644
--- a/sdk/lib/uri/encode_decode.dart
+++ b/sdk/lib/uri/encode_decode.dart
@@ -77,13 +77,22 @@ String _uriEncode(String canonical, String text) {
final String hex = '0123456789ABCDEF';
var byteToHex = (int v) => '%${hex[v >> 4]}${hex[v&0xf]}';
StringBuffer result = new StringBuffer();
- // TODO(erikcorry): Use the new character iterator.
for (int i = 0; i < text.length; i++) {
if (canonical.indexOf(text[i]) >= 0) {
result.add(text[i]);
} else {
int ch = text.charCodeAt(i);
- if (ch >= 0x10000) i++;
+ if (ch >= 0xD800 && ch < 0xDC00) {
+ // Low surrogate. We expect a next char high surrogate.
+ ++i;
+ int nextCh = text.length == i ? 0 : text.charCodeAt(i);
+ if (nextCh >= 0xDC00 && nextCh < 0xE000) {
+ // convert the pair to a U+10000 codepoint
+ ch = 0x10000 + ((ch-0xD800) << 10) + (nextCh - 0xDC00);
+ } else {
+ throw new ArgumentError('Malformed URI');
+ }
+ }
for (int codepoint in codepointsToUtf8([ch])) {
result.add(byteToHex(codepoint));
}
« no previous file with comments | « sdk/lib/io/string_stream.dart ('k') | sdk/lib/utf/utf32.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698