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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/string_stream.dart ('k') | sdk/lib/utf/utf32.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * Javascript-like URI encode/decode functions. 6 * Javascript-like URI encode/decode functions.
7 * The documentation here borrows heavily from the original Javascript 7 * The documentation here borrows heavily from the original Javascript
8 * doumentation on MDN at: 8 * doumentation on MDN at:
9 * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects 9 * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects
10 */ 10 */
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 /** 71 /**
72 * This is the internal implementation of JavaScript's encodeURI function. 72 * This is the internal implementation of JavaScript's encodeURI function.
73 * It encodes all characters in the string [text] except for those 73 * It encodes all characters in the string [text] except for those
74 * that appear in [canonical], and returns the escaped string. 74 * that appear in [canonical], and returns the escaped string.
75 */ 75 */
76 String _uriEncode(String canonical, String text) { 76 String _uriEncode(String canonical, String text) {
77 final String hex = '0123456789ABCDEF'; 77 final String hex = '0123456789ABCDEF';
78 var byteToHex = (int v) => '%${hex[v >> 4]}${hex[v&0xf]}'; 78 var byteToHex = (int v) => '%${hex[v >> 4]}${hex[v&0xf]}';
79 StringBuffer result = new StringBuffer(); 79 StringBuffer result = new StringBuffer();
80 // TODO(erikcorry): Use the new character iterator.
81 for (int i = 0; i < text.length; i++) { 80 for (int i = 0; i < text.length; i++) {
82 if (canonical.indexOf(text[i]) >= 0) { 81 if (canonical.indexOf(text[i]) >= 0) {
83 result.add(text[i]); 82 result.add(text[i]);
84 } else { 83 } else {
85 int ch = text.charCodeAt(i); 84 int ch = text.charCodeAt(i);
86 if (ch >= 0x10000) i++; 85 if (ch >= 0xD800 && ch < 0xDC00) {
86 // Low surrogate. We expect a next char high surrogate.
87 ++i;
88 int nextCh = text.length == i ? 0 : text.charCodeAt(i);
89 if (nextCh >= 0xDC00 && nextCh < 0xE000) {
90 // convert the pair to a U+10000 codepoint
91 ch = 0x10000 + ((ch-0xD800) << 10) + (nextCh - 0xDC00);
92 } else {
93 throw new ArgumentError('Malformed URI');
94 }
95 }
87 for (int codepoint in codepointsToUtf8([ch])) { 96 for (int codepoint in codepointsToUtf8([ch])) {
88 result.add(byteToHex(codepoint)); 97 result.add(byteToHex(codepoint));
89 } 98 }
90 } 99 }
91 } 100 }
92 return result.toString(); 101 return result.toString();
93 } 102 }
94 103
95 /** 104 /**
96 * Convert a byte (2 character hex sequence) in string [s] starting 105 * Convert a byte (2 character hex sequence) in string [s] starting
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (i == text.length) 139 if (i == text.length)
131 break; 140 break;
132 ch = text[i]; 141 ch = text[i];
133 } 142 }
134 result.add(decodeUtf8(codepoints)); 143 result.add(decodeUtf8(codepoints));
135 } 144 }
136 } 145 }
137 return result.toString(); 146 return result.toString();
138 } 147 }
139 148
OLDNEW
« 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