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

Side by Side Diff: lib/uri/encode_decode.dart

Issue 10989013: Change IllegalArgumentException to ArgumentError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated co19 test expectations. Created 8 years, 2 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 /** 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } else { 83 } else {
84 int ch = text.charCodeAt(i); 84 int ch = text.charCodeAt(i);
85 if (ch >= 0xD800 && ch < 0xDC00) { 85 if (ch >= 0xD800 && ch < 0xDC00) {
86 // Low surrogate. We expect a next char high surrogate. 86 // Low surrogate. We expect a next char high surrogate.
87 ++i; 87 ++i;
88 int nextCh = text.length == i ? 0 : text.charCodeAt(i); 88 int nextCh = text.length == i ? 0 : text.charCodeAt(i);
89 if (nextCh >= 0xDC00 && nextCh < 0xE000) { 89 if (nextCh >= 0xDC00 && nextCh < 0xE000) {
90 // convert the pair to a U+10000 codepoint 90 // convert the pair to a U+10000 codepoint
91 ch = 0x10000 + ((ch-0xD800) << 10) + (nextCh - 0xDC00); 91 ch = 0x10000 + ((ch-0xD800) << 10) + (nextCh - 0xDC00);
92 } else { 92 } else {
93 throw new IllegalArgumentException('Malformed URI'); 93 throw new ArgumentError('Malformed URI');
94 } 94 }
95 } 95 }
96 for (int codepoint in codepointsToUtf8([ch])) { 96 for (int codepoint in codepointsToUtf8([ch])) {
97 result.add(byteToHex(codepoint)); 97 result.add(byteToHex(codepoint));
98 } 98 }
99 } 99 }
100 } 100 }
101 return result.toString(); 101 return result.toString();
102 } 102 }
103 103
(...skipping 21 matching lines...) Expand all
125 List<int> codepoints = new List<int>(); 125 List<int> codepoints = new List<int>();
126 for (int i = 0; i < text.length;) { 126 for (int i = 0; i < text.length;) {
127 String ch = text[i]; 127 String ch = text[i];
128 if (ch != '%') { 128 if (ch != '%') {
129 result.add(ch); 129 result.add(ch);
130 i++; 130 i++;
131 } else { 131 } else {
132 codepoints.clear(); 132 codepoints.clear();
133 while (ch == '%') { 133 while (ch == '%') {
134 if (++i > text.length - 2) { 134 if (++i > text.length - 2) {
135 throw new IllegalArgumentException('Truncated URI'); 135 throw new ArgumentError('Truncated URI');
136 } 136 }
137 codepoints.add(_hexCharPairToByte(text, i)); 137 codepoints.add(_hexCharPairToByte(text, i));
138 i += 2; 138 i += 2;
139 if (i == text.length) 139 if (i == text.length)
140 break; 140 break;
141 ch = text[i]; 141 ch = text[i];
142 } 142 }
143 result.add(decodeUtf8(codepoints)); 143 result.add(decodeUtf8(codepoints));
144 } 144 }
145 } 145 }
146 return result.toString(); 146 return result.toString();
147 } 147 }
148 148
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698