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

Side by Side Diff: test/dart_codegen/expect/core/uri.dart

Issue 963593002: Disable formatting and add new-lines to make tests faster. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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
OLDNEW
1 part of dart.core; 1 part of dart.core;
2 2 class Uri {final String _host;
3 class Uri { 3 num _port;
4 final String _host; 4 String _path;
5 num _port; 5 final String scheme;
6 String _path; 6 String get authority {
7 final String scheme; 7 if (!hasAuthority) return "";
8 String get authority { 8 var sb = new StringBuffer();
9 if (!hasAuthority) return ""; 9 _writeAuthority(sb);
10 var sb = new StringBuffer(); 10 return sb.toString();
11 _writeAuthority(sb); 11 }
12 return sb.toString(); 12 final String _userInfo;
13 } 13 String get userInfo => _userInfo;
14 final String _userInfo; 14 String get host {
15 String get userInfo => _userInfo; 15 if (_host == null) return "";
16 String get host { 16 if (_host.startsWith('[')) {
17 if (_host == null) return ""; 17 return _host.substring(1, _host.length - 1);
18 if (_host.startsWith('[')) { 18 }
19 return _host.substring(1, _host.length - 1); 19 return _host;
20 } 20 }
21 return _host; 21 int get port {
22 } 22 if (_port == null) return _defaultPort(scheme);
23 int get port { 23 return DDC$RT.cast(_port, num, int, "CastGeneral", """line 94, column 12 of d art:core/uri.dart: """, _port is int, true);
24 if (_port == null) return _defaultPort(scheme); 24 }
25 return DDC$RT.cast(_port, num, int, "CastGeneral", 25 static int _defaultPort(String scheme) {
26 """line 94, column 12 of dart:core/uri.dart: """, _port is int, true); 26 if (scheme == "http") return 80;
27 } 27 if (scheme == "https") return 443;
28 static int _defaultPort(String scheme) { 28 return 0;
29 if (scheme == "http") return 80; 29 }
30 if (scheme == "https") return 443; 30 String get path => _path;
31 return 0; 31 final String _query;
32 } 32 String get query => (_query == null) ? "" : _query;
33 String get path => _path; 33 final String _fragment;
34 final String _query; 34 String get fragment => (_fragment == null) ? "" : _fragment;
35 String get query => (_query == null) ? "" : _query; 35 List<String> _pathSegments;
36 final String _fragment; 36 Map<String, String> _queryParameters;
37 String get fragment => (_fragment == null) ? "" : _fragment; 37 static Uri parse(String uri) {
38 List<String> _pathSegments; 38 bool isRegName(int ch) {
39 Map<String, String> _queryParameters; 39 return ch < 128 && ((_regNameTable[ch >> 4] & (1 << (ch & 0x0f))) != 0);
40 static Uri parse(String uri) { 40 }
41 bool isRegName(int ch) { 41 const int EOI = -1;
42 return ch < 128 && ((_regNameTable[ch >> 4] & (1 << (ch & 0x0f))) != 0); 42 String scheme = "";
43 } 43 String userinfo = "";
44 const int EOI = -1; 44 String host = null;
45 String scheme = ""; 45 num port = null;
46 String userinfo = ""; 46 String path = null;
47 String host = null; 47 String query = null;
48 num port = null; 48 String fragment = null;
49 String path = null; 49 int index = 0;
50 String query = null; 50 int pathStart = 0;
51 String fragment = null; 51 int char = EOI;
52 int index = 0; 52 void parseAuth() {
53 int pathStart = 0; 53 if (index == uri.length) {
54 int char = EOI; 54 char = EOI;
55 void parseAuth() { 55 return;}
56 if (index == uri.length) { 56 int authStart = index;
57 int lastColon = -1;
58 int lastAt = -1;
59 char = uri.codeUnitAt(index);
60 while (index < uri.length) {
61 char = uri.codeUnitAt(index);
62 if (char == _SLASH || char == _QUESTION || char == _NUMBER_SIGN) {
63 break;
64 }
65 if (char == _AT_SIGN) {
66 lastAt = index;
67 lastColon = -1;
68 }
69 else if (char == _COLON) {
70 lastColon = index;
71 }
72 else if (char == _LEFT_BRACKET) {
73 lastColon = -1;
74 int endBracket = uri.indexOf(']', index + 1);
75 if (endBracket == -1) {
76 index = uri.length;
77 char = EOI;
78 break;
79 }
80 else {
81 index = endBracket;
82 }
83 }
84 index++;
85 char = EOI;
86 }
87 int hostStart = authStart;
88 int hostEnd = index;
89 if (lastAt >= 0) {
90 userinfo = _makeUserInfo(uri, authStart, lastAt);
91 hostStart = lastAt + 1;
92 }
93 if (lastColon >= 0) {
94 int portNumber;
95 if (lastColon + 1 < index) {
96 portNumber = 0;
97 for (int i = lastColon + 1;
98 i < index;
99 i++) {
100 int digit = uri.codeUnitAt(i);
101 if (_ZERO > digit || _NINE < digit) {
102 _fail(uri, i, "Invalid port number");
103 }
104 portNumber = portNumber * 10 + (digit - _ZERO);
105 }
106 }
107 port = _makePort(portNumber, scheme);
108 hostEnd = lastColon;
109 }
110 host = _makeHost(uri, hostStart, hostEnd, true);
111 if (index < uri.length) {
112 char = uri.codeUnitAt(index);
113 }
114 }
115 const int NOT_IN_PATH = 0;
116 const int IN_PATH = 1;
117 const int ALLOW_AUTH = 2;
118 int state = NOT_IN_PATH;
119 int i = index;
120 while (i < uri.length) {
121 char = uri.codeUnitAt(i);
122 if (char == _QUESTION || char == _NUMBER_SIGN) {
123 state = NOT_IN_PATH;
124 break;
125 }
126 if (char == _SLASH) {
127 state = (i == 0) ? ALLOW_AUTH : IN_PATH;
128 break;
129 }
130 if (char == _COLON) {
131 if (i == 0) _fail(uri, 0, "Invalid empty scheme");
132 scheme = _makeScheme(uri, i);
133 i++;
134 pathStart = i;
135 if (i == uri.length) {
57 char = EOI; 136 char = EOI;
58 return; 137 state = NOT_IN_PATH;
59 } 138 }
60 int authStart = index; 139 else {
61 int lastColon = -1; 140 char = uri.codeUnitAt(i);
62 int lastAt = -1; 141 if (char == _QUESTION || char == _NUMBER_SIGN) {
142 state = NOT_IN_PATH;
143 }
144 else if (char == _SLASH) {
145 state = ALLOW_AUTH;
146 }
147 else {
148 state = IN_PATH;
149 }
150 }
151 break;
152 }
153 i++;
154 char = EOI;
155 }
156 index = i;
157 if (state == ALLOW_AUTH) {
158 assert (char == _SLASH); index++;
159 if (index == uri.length) {
160 char = EOI;
161 state = NOT_IN_PATH;
162 }
163 else {
63 char = uri.codeUnitAt(index); 164 char = uri.codeUnitAt(index);
64 while (index < uri.length) { 165 if (char == _SLASH) {
65 char = uri.codeUnitAt(index);
66 if (char == _SLASH || char == _QUESTION || char == _NUMBER_SIGN) {
67 break;
68 }
69 if (char == _AT_SIGN) {
70 lastAt = index;
71 lastColon = -1;
72 } else if (char == _COLON) {
73 lastColon = index;
74 } else if (char == _LEFT_BRACKET) {
75 lastColon = -1;
76 int endBracket = uri.indexOf(']', index + 1);
77 if (endBracket == -1) {
78 index = uri.length;
79 char = EOI;
80 break;
81 } else {
82 index = endBracket;
83 }
84 }
85 index++; 166 index++;
86 char = EOI; 167 parseAuth();
87 } 168 pathStart = index;
88 int hostStart = authStart; 169 }
89 int hostEnd = index; 170 if (char == _QUESTION || char == _NUMBER_SIGN || char == EOI) {
90 if (lastAt >= 0) {
91 userinfo = _makeUserInfo(uri, authStart, lastAt);
92 hostStart = lastAt + 1;
93 }
94 if (lastColon >= 0) {
95 int portNumber;
96 if (lastColon + 1 < index) {
97 portNumber = 0;
98 for (int i = lastColon + 1; i < index; i++) {
99 int digit = uri.codeUnitAt(i);
100 if (_ZERO > digit || _NINE < digit) {
101 _fail(uri, i, "Invalid port number");
102 }
103 portNumber = portNumber * 10 + (digit - _ZERO);
104 }
105 }
106 port = _makePort(portNumber, scheme);
107 hostEnd = lastColon;
108 }
109 host = _makeHost(uri, hostStart, hostEnd, true);
110 if (index < uri.length) {
111 char = uri.codeUnitAt(index);
112 }
113 }
114 const int NOT_IN_PATH = 0;
115 const int IN_PATH = 1;
116 const int ALLOW_AUTH = 2;
117 int state = NOT_IN_PATH;
118 int i = index;
119 while (i < uri.length) {
120 char = uri.codeUnitAt(i);
121 if (char == _QUESTION || char == _NUMBER_SIGN) {
122 state = NOT_IN_PATH; 171 state = NOT_IN_PATH;
172 }
173 else {
174 state = IN_PATH;
175 }
176 }
177 }
178 assert (state == IN_PATH || state == NOT_IN_PATH); if (state == IN_PATH) {
179 while (++index < uri.length) {
180 char = uri.codeUnitAt(index);
181 if (char == _QUESTION || char == _NUMBER_SIGN) {
123 break; 182 break;
124 } 183 }
125 if (char == _SLASH) { 184 char = EOI;
126 state = (i == 0) ? ALLOW_AUTH : IN_PATH; 185 }
127 break; 186 state = NOT_IN_PATH;
128 } 187 }
129 if (char == _COLON) { 188 assert (state == NOT_IN_PATH); bool isFile = (scheme == "file");
130 if (i == 0) _fail(uri, 0, "Invalid empty scheme"); 189 bool ensureLeadingSlash = host != null;
131 scheme = _makeScheme(uri, i); 190 path = _makePath(uri, pathStart, index, null, ensureLeadingSlash, isFile);
132 i++; 191 if (char == _QUESTION) {
133 pathStart = i; 192 int numberSignIndex = uri.indexOf('#', index + 1);
134 if (i == uri.length) { 193 if (numberSignIndex < 0) {
135 char = EOI; 194 query = _makeQuery(uri, index + 1, uri.length, null);
136 state = NOT_IN_PATH; 195 }
137 } else { 196 else {
138 char = uri.codeUnitAt(i); 197 query = _makeQuery(uri, index + 1, numberSignIndex, null);
139 if (char == _QUESTION || char == _NUMBER_SIGN) { 198 fragment = _makeFragment(uri, numberSignIndex + 1, uri.length);
140 state = NOT_IN_PATH; 199 }
141 } else if (char == _SLASH) { 200 }
142 state = ALLOW_AUTH; 201 else if (char == _NUMBER_SIGN) {
143 } else { 202 fragment = _makeFragment(uri, index + 1, uri.length);
144 state = IN_PATH; 203 }
145 } 204 return new Uri._internal(scheme, userinfo, host, port, path, query, fragment) ;
146 } 205 }
147 break; 206 static void _fail(String uri, int index, String message) {
148 } 207 throw new FormatException(message, uri, index);
149 i++; 208 }
150 char = EOI; 209 Uri._internal(this.scheme, this._userInfo, this._host, this._port, this._path, this._query, this._fragment);
151 } 210 factory Uri({
152 index = i; 211 String scheme : "", String userInfo : "", String host, int port, String path, Iterable<String> pathSegments, String query, Map<String, String> queryParameters , String fragment}
153 if (state == ALLOW_AUTH) { 212 ) {
154 assert(char == _SLASH); 213 scheme = _makeScheme(scheme, _stringOrNullLength(scheme));
155 index++; 214 userInfo = _makeUserInfo(userInfo, 0, _stringOrNullLength(userInfo));
156 if (index == uri.length) { 215 host = _makeHost(host, 0, _stringOrNullLength(host), false);
157 char = EOI; 216 if (query == "") query = null;
158 state = NOT_IN_PATH; 217 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters);
159 } else { 218 fragment = _makeFragment(fragment, 0, _stringOrNullLength(fragment));
160 char = uri.codeUnitAt(index); 219 port = _makePort(port, scheme);
161 if (char == _SLASH) { 220 bool isFile = (scheme == "file");
162 index++; 221 if (host == null && (userInfo.isNotEmpty || port != null || isFile)) {
163 parseAuth(); 222 host = "";
164 pathStart = index; 223 }
165 } 224 bool ensureLeadingSlash = host != null;
166 if (char == _QUESTION || char == _NUMBER_SIGN || char == EOI) { 225 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, ensureLead ingSlash, isFile);
167 state = NOT_IN_PATH; 226 return new Uri._internal(scheme, userInfo, host, port, path, query, fragment) ;
168 } else { 227 }
169 state = IN_PATH; 228 factory Uri.http(String authority, String unencodedPath, [Map<String, String> q ueryParameters]) {
170 } 229 return _makeHttpUri("http", authority, unencodedPath, queryParameters);
171 } 230 }
172 } 231 factory Uri.https(String authority, String unencodedPath, [Map<String, String> queryParameters]) {
173 assert(state == IN_PATH || state == NOT_IN_PATH); 232 return _makeHttpUri("https", authority, unencodedPath, queryParameters);
174 if (state == IN_PATH) { 233 }
175 while (++index < uri.length) { 234 static Uri _makeHttpUri(String scheme, String authority, String unencodedPath, Map<String, String> queryParameters) {
176 char = uri.codeUnitAt(index); 235 var userInfo = "";
177 if (char == _QUESTION || char == _NUMBER_SIGN) { 236 var host = null;
178 break; 237 var port = null;
179 } 238 if (authority != null && authority.isNotEmpty) {
180 char = EOI; 239 var hostStart = 0;
181 } 240 bool hasUserInfo = false;
182 state = NOT_IN_PATH; 241 for (int i = 0;
183 } 242 i < authority.length;
184 assert(state == NOT_IN_PATH); 243 i++) {
185 bool isFile = (scheme == "file"); 244 if (authority.codeUnitAt(i) == _AT_SIGN) {
186 bool ensureLeadingSlash = host != null; 245 hasUserInfo = true;
187 path = _makePath(uri, pathStart, index, null, ensureLeadingSlash, isFile); 246 userInfo = authority.substring(0, i);
188 if (char == _QUESTION) { 247 hostStart = i + 1;
189 int numberSignIndex = uri.indexOf('#', index + 1); 248 break;
190 if (numberSignIndex < 0) { 249 }
191 query = _makeQuery(uri, index + 1, uri.length, null); 250 }
192 } else { 251 var hostEnd = hostStart;
193 query = _makeQuery(uri, index + 1, numberSignIndex, null); 252 if (hostStart < authority.length && authority.codeUnitAt(hostStart) == _LEF T_BRACKET) {
194 fragment = _makeFragment(uri, numberSignIndex + 1, uri.length); 253 for (;
195 } 254 hostEnd < authority.length;
196 } else if (char == _NUMBER_SIGN) { 255 hostEnd++) {
197 fragment = _makeFragment(uri, index + 1, uri.length); 256 if (authority.codeUnitAt(hostEnd) == _RIGHT_BRACKET) break;
198 } 257 }
199 return new Uri._internal( 258 if (hostEnd == authority.length) {
200 scheme, userinfo, host, port, path, query, fragment); 259 throw new FormatException("Invalid IPv6 host entry.", authority, hostSta rt);
201 } 260 }
202 static void _fail(String uri, int index, String message) { 261 parseIPv6Address(authority, hostStart + 1, hostEnd);
203 throw new FormatException(message, uri, index); 262 hostEnd++;
204 } 263 if (hostEnd != authority.length && authority.codeUnitAt(hostEnd) != _COLO N) {
205 Uri._internal(this.scheme, this._userInfo, this._host, this._port, this._path, 264 throw new FormatException("Invalid end of authority", authority, hostEnd );
206 this._query, this._fragment); 265 }
207 factory Uri({String scheme: "", String userInfo: "", String host, int port, 266 }
208 String path, Iterable<String> pathSegments, String query, 267 bool hasPort = false;
209 Map<String, String> queryParameters, String fragment}) { 268 for (;
210 scheme = _makeScheme(scheme, _stringOrNullLength(scheme)); 269 hostEnd < authority.length;
211 userInfo = _makeUserInfo(userInfo, 0, _stringOrNullLength(userInfo)); 270 hostEnd++) {
212 host = _makeHost(host, 0, _stringOrNullLength(host), false); 271 if (authority.codeUnitAt(hostEnd) == _COLON) {
213 if (query == "") query = null; 272 var portString = authority.substring(hostEnd + 1);
214 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters); 273 if (portString.isNotEmpty) port = int.parse(portString);
215 fragment = _makeFragment(fragment, 0, _stringOrNullLength(fragment)); 274 break;
275 }
276 }
277 host = authority.substring(hostStart, hostEnd);
278 }
279 return new Uri(scheme: scheme, userInfo: userInfo, host: host, port: port, pa thSegments: unencodedPath.split("/"), queryParameters: queryParameters);
280 }
281 factory Uri.file(String path, {
282 bool windows}
283 ) {
284 windows = windows == null ? Uri._isWindows : windows;
285 return ((__x41) => DDC$RT.cast(__x41, dynamic, Uri, "CastGeneral", """line 69 8, column 12 of dart:core/uri.dart: """, __x41 is Uri, true))(windows ? _makeWin dowsFileUrl(path) : _makeFileUri(path));
286 }
287 static Uri get base {
288 String uri = ((__x42) => DDC$RT.cast(__x42, dynamic, String, "CastGeneral", "" "line 711, column 18 of dart:core/uri.dart: """, __x42 is String, true))(Primiti ves.currentUri());
289 if (uri != null) return Uri.parse(uri);
290 throw new UnsupportedError("'Uri.base' is not supported");
291 }
292 static bool get _isWindows => false;
293 static _checkNonWindowsPathReservedCharacters(List<String> segments, bool argum entError) {
294 segments.forEach((segment) {
295 if (segment.contains("/")) {
296 if (argumentError) {
297 throw new ArgumentError("Illegal path character $segment");
298 }
299 else {
300 throw new UnsupportedError("Illegal path character $segment");
301 }
302 }
303 }
304 );
305 }
306 static _checkWindowsPathReservedCharacters(List<String> segments, bool argument Error, [int firstSegment = 0]) {
307 segments.skip(firstSegment).forEach((segment) {
308 if (segment.contains(new RegExp(r'["*/:<>?\\|]'))) {
309 if (argumentError) {
310 throw new ArgumentError("Illegal character in path");
311 }
312 else {
313 throw new UnsupportedError("Illegal character in path");
314 }
315 }
316 }
317 );
318 }
319 static _checkWindowsDriveLetter(int charCode, bool argumentError) {
320 if ((_UPPER_CASE_A <= charCode && charCode <= _UPPER_CASE_Z) || (_LOWER_CASE_A <= charCode && charCode <= _LOWER_CASE_Z)) {
321 return;}
322 if (argumentError) {
323 throw new ArgumentError("Illegal drive letter " + new String.fromCharCode(ch arCode));
324 }
325 else {
326 throw new UnsupportedError("Illegal drive letter " + new String.fromCharCode (charCode));
327 }
328 }
329 static _makeFileUri(String path) {
330 String sep = "/";
331 if (path.startsWith(sep)) {
332 return new Uri(scheme: "file", pathSegments: path.split(sep));
333 }
334 else {
335 return new Uri(pathSegments: path.split(sep));
336 }
337 }
338 static _makeWindowsFileUrl(String path) {
339 if (path.startsWith("\\\\?\\")) {
340 if (path.startsWith("\\\\?\\UNC\\")) {
341 path = "\\${path.substring(7)}
342 ";
343 }
344 else {
345 path = path.substring(4);
346 if (path.length < 3 || path.codeUnitAt(1) != _COLON || path.codeUnitAt(2) ! = _BACKSLASH) {
347 throw new ArgumentError("Windows paths with \\\\?\\ prefix must be absolut e");
348 }
349 }
350 }
351 else {
352 path = path.replaceAll("/", "\\");
353 }
354 String sep = "\\";
355 if (path.length > 1 && path[1] == ":") {
356 _checkWindowsDriveLetter(path.codeUnitAt(0), true);
357 if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) {
358 throw new ArgumentError("Windows paths with drive letter must be absolute");
359 }
360 var pathSegments = path.split(sep);
361 _checkWindowsPathReservedCharacters(pathSegments, true, 1);
362 return new Uri(scheme: "file", pathSegments: pathSegments);
363 }
364 if (path.length > 0 && path[0] == sep) {
365 if (path.length > 1 && path[1] == sep) {
366 int pathStart = path.indexOf("\\", 2);
367 String hostPart = pathStart == -1 ? path.substring(2) : path.substring(2, p athStart);
368 String pathPart = pathStart == -1 ? "" : path.substring(pathStart + 1);
369 var pathSegments = pathPart.split(sep);
370 _checkWindowsPathReservedCharacters(pathSegments, true);
371 return new Uri(scheme: "file", host: hostPart, pathSegments: pathSegments);
372 }
373 else {
374 var pathSegments = path.split(sep);
375 _checkWindowsPathReservedCharacters(pathSegments, true);
376 return new Uri(scheme: "file", pathSegments: pathSegments);
377 }
378 }
379 else {
380 var pathSegments = path.split(sep);
381 _checkWindowsPathReservedCharacters(pathSegments, true);
382 return new Uri(pathSegments: pathSegments);
383 }
384 }
385 Uri replace({
386 String scheme, String userInfo, String host, int port, String path, Iterable<Str ing> pathSegments, String query, Map<String, String> queryParameters, String fra gment}
387 ) {
388 bool schemeChanged = false;
389 if (scheme != null) {
390 scheme = _makeScheme(scheme, scheme.length);
391 schemeChanged = true;
392 }
393 else {
394 scheme = this.scheme;
395 }
396 bool isFile = (scheme == "file");
397 if (userInfo != null) {
398 userInfo = _makeUserInfo(userInfo, 0, userInfo.length);
399 }
400 else {
401 userInfo = this.userInfo;
402 }
403 if (port != null) {
404 port = _makePort(port, scheme);
405 }
406 else {
407 port = ((__x43) => DDC$RT.cast(__x43, num, int, "CastGeneral", """line 893, co lumn 14 of dart:core/uri.dart: """, __x43 is int, true))(this._port);
408 if (schemeChanged) {
216 port = _makePort(port, scheme); 409 port = _makePort(port, scheme);
217 bool isFile = (scheme == "file"); 410 }
218 if (host == null && (userInfo.isNotEmpty || port != null || isFile)) { 411 }
219 host = ""; 412 if (host != null) {
220 } 413 host = _makeHost(host, 0, host.length, false);
221 bool ensureLeadingSlash = host != null; 414 }
222 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, 415 else if (this.hasAuthority) {
223 ensureLeadingSlash, isFile); 416 host = this.host;
224 return new Uri._internal( 417 }
225 scheme, userInfo, host, port, path, query, fragment); 418 else if (userInfo.isNotEmpty || port != null || isFile) {
226 } 419 host = "";
227 factory Uri.http(String authority, String unencodedPath, 420 }
228 [Map<String, String> queryParameters]) { 421 bool ensureLeadingSlash = (host != null);
229 return _makeHttpUri("http", authority, unencodedPath, queryParameters); 422 if (path != null || pathSegments != null) {
230 } 423 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, ensureLeadi ngSlash, isFile);
231 factory Uri.https(String authority, String unencodedPath, 424 }
232 [Map<String, String> queryParameters]) { 425 else {
233 return _makeHttpUri("https", authority, unencodedPath, queryParameters); 426 path = this.path;
234 } 427 if ((isFile || (ensureLeadingSlash && !path.isEmpty)) && !path.startsWith('/' )) {
235 static Uri _makeHttpUri(String scheme, String authority, String unencodedPath, 428 path = "/$path";
236 Map<String, String> queryParameters) { 429 }
237 var userInfo = ""; 430 }
238 var host = null; 431 if (query != null || queryParameters != null) {
239 var port = null; 432 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters);
240 if (authority != null && authority.isNotEmpty) { 433 }
241 var hostStart = 0; 434 else if (this.hasQuery) {
242 bool hasUserInfo = false; 435 query = this.query;
243 for (int i = 0; i < authority.length; i++) { 436 }
244 if (authority.codeUnitAt(i) == _AT_SIGN) { 437 if (fragment != null) {
245 hasUserInfo = true; 438 fragment = _makeFragment(fragment, 0, fragment.length);
246 userInfo = authority.substring(0, i); 439 }
247 hostStart = i + 1; 440 else if (this.hasFragment) {
248 break; 441 fragment = this.fragment;
249 } 442 }
250 } 443 return new Uri._internal(scheme, userInfo, host, port, path, query, fragment);
251 var hostEnd = hostStart; 444 }
252 if (hostStart < authority.length && 445 List<String> get pathSegments {
253 authority.codeUnitAt(hostStart) == _LEFT_BRACKET) { 446 if (_pathSegments == null) {
254 for (; hostEnd < authority.length; hostEnd++) { 447 var pathToSplit = !path.isEmpty && path.codeUnitAt(0) == _SLASH ? path.substri ng(1) : path;
255 if (authority.codeUnitAt(hostEnd) == _RIGHT_BRACKET) break; 448 _pathSegments = ((__x44) => DDC$RT.cast(__x44, DDC$RT.type((DDC$collection$.U nmodifiableListView<dynamic> _) {
256 } 449 }
257 if (hostEnd == authority.length) { 450 ), DDC$RT.type((List<String> _) {
258 throw new FormatException( 451 }
259 "Invalid IPv6 host entry.", authority, hostStart); 452 ), "CastExact", """line 949, column 23 of dart:core/uri.dart: """, __x44 is Li st<String>, false))(new UnmodifiableListView(pathToSplit == "" ? const <String> [] : pathToSplit.split("/").map(Uri.decodeComponent).toList(growable: false)));
260 } 453 }
261 parseIPv6Address(authority, hostStart + 1, hostEnd); 454 return _pathSegments;
262 hostEnd++; 455 }
263 if (hostEnd != authority.length && 456 Map<String, String> get queryParameters {
264 authority.codeUnitAt(hostEnd) != _COLON) { 457 if (_queryParameters == null) {
265 throw new FormatException( 458 _queryParameters = ((__x45) => DDC$RT.cast(__x45, DDC$RT.type((DDC$collection$ .UnmodifiableMapView<dynamic, dynamic> _) {
266 "Invalid end of authority", authority, hostEnd); 459 }
267 } 460 ), DDC$RT.type((Map<String, String> _) {
268 } 461 }
269 bool hasPort = false; 462 ), "CastExact", """line 973, column 26 of dart:core/uri.dart: """, __x45 is Ma p<String, String>, false))(new UnmodifiableMapView(splitQueryString(query)));
270 for (; hostEnd < authority.length; hostEnd++) { 463 }
271 if (authority.codeUnitAt(hostEnd) == _COLON) { 464 return _queryParameters;
272 var portString = authority.substring(hostEnd + 1); 465 }
273 if (portString.isNotEmpty) port = int.parse(portString); 466 static int _makePort(int port, String scheme) {
274 break; 467 if (port != null && port == _defaultPort(scheme)) return ((__x46) => DDC$RT.cast (__x46, Null, int, "CastLiteral", """line 980, column 62 of dart:core/uri.dart: """, __x46 is int, true))(null);
275 } 468 return port;
276 } 469 }
277 host = authority.substring(hostStart, hostEnd); 470 static String _makeHost(String host, int start, int end, bool strictIPv6) {
278 } 471 if (host == null) return null;
279 return new Uri( 472 if (start == end) return "";
280 scheme: scheme, 473 if (host.codeUnitAt(start) == _LEFT_BRACKET) {
281 userInfo: userInfo, 474 if (host.codeUnitAt(end - 1) != _RIGHT_BRACKET) {
282 host: host, 475 _fail(host, start, 'Missing end `]` to match `[` in host');
283 port: port, 476 }
284 pathSegments: unencodedPath.split("/"), 477 parseIPv6Address(host, start + 1, end - 1);
285 queryParameters: queryParameters); 478 return host.substring(start, end).toLowerCase();
286 } 479 }
287 factory Uri.file(String path, {bool windows}) { 480 if (!strictIPv6) {
288 windows = windows == null ? Uri._isWindows : windows; 481 for (int i = start;
289 return ((__x41) => DDC$RT.cast(__x41, dynamic, Uri, "CastGeneral", 482 i < end;
290 """line 698, column 12 of dart:core/uri.dart: """, __x41 is Uri, 483 i++) {
291 true))(windows ? _makeWindowsFileUrl(path) : _makeFileUri(path)); 484 if (host.codeUnitAt(i) == _COLON) {
292 } 485 parseIPv6Address(host, start, end);
293 static Uri get base { 486 return '[$host]';
294 String uri = ((__x42) => DDC$RT.cast(__x42, dynamic, String, "CastGeneral", 487 }
295 """line 711, column 18 of dart:core/uri.dart: """, __x42 is String, 488 }
296 true))(Primitives.currentUri()); 489 }
297 if (uri != null) return Uri.parse(uri); 490 return _normalizeRegName(host, start, end);
298 throw new UnsupportedError("'Uri.base' is not supported"); 491 }
299 } 492 static bool _isRegNameChar(int char) {
300 static bool get _isWindows => false; 493 return char < 127 && (_regNameTable[char >> 4] & (1 << (char & 0xf))) != 0;
301 static _checkNonWindowsPathReservedCharacters( 494 }
302 List<String> segments, bool argumentError) { 495 static String _normalizeRegName(String host, int start, int end) {
303 segments.forEach((segment) { 496 StringBuffer buffer;
304 if (segment.contains("/")) { 497 int sectionStart = start;
305 if (argumentError) { 498 int index = start;
306 throw new ArgumentError("Illegal path character $segment"); 499 bool isNormalized = true;
307 } else { 500 while (index < end) {
308 throw new UnsupportedError("Illegal path character $segment"); 501 int char = host.codeUnitAt(index);
309 } 502 if (char == _PERCENT) {
310 } 503 String replacement = _normalizeEscape(host, index, true);
311 }); 504 if (replacement == null && isNormalized) {
312 } 505 index += 3;
313 static _checkWindowsPathReservedCharacters( 506 continue;
314 List<String> segments, bool argumentError, [int firstSegment = 0]) { 507 }
315 segments.skip(firstSegment).forEach((segment) { 508 if (buffer == null) buffer = new StringBuffer();
316 if (segment.contains(new RegExp(r'["*/:<>?\\|]'))) { 509 String slice = host.substring(sectionStart, index);
317 if (argumentError) { 510 if (!isNormalized) slice = slice.toLowerCase();
318 throw new ArgumentError("Illegal character in path"); 511 buffer.write(slice);
319 } else { 512 int sourceLength = 3;
320 throw new UnsupportedError("Illegal character in path"); 513 if (replacement == null) {
321 } 514 replacement = host.substring(index, index + 3);
322 } 515 }
323 }); 516 else if (replacement == "%") {
324 } 517 replacement = "%25";
325 static _checkWindowsDriveLetter(int charCode, bool argumentError) { 518 sourceLength = 1;
326 if ((_UPPER_CASE_A <= charCode && charCode <= _UPPER_CASE_Z) || 519 }
327 (_LOWER_CASE_A <= charCode && charCode <= _LOWER_CASE_Z)) { 520 buffer.write(replacement);
328 return; 521 index += sourceLength;
329 } 522 sectionStart = index;
330 if (argumentError) { 523 isNormalized = true;
331 throw new ArgumentError( 524 }
332 "Illegal drive letter " + new String.fromCharCode(charCode)); 525 else if (_isRegNameChar(char)) {
333 } else { 526 if (isNormalized && _UPPER_CASE_A <= char && _UPPER_CASE_Z >= char) {
334 throw new UnsupportedError( 527 if (buffer == null) buffer = new StringBuffer();
335 "Illegal drive letter " + new String.fromCharCode(charCode)); 528 if (sectionStart < index) {
336 } 529 buffer.write(host.substring(sectionStart, index));
337 } 530 sectionStart = index;
338 static _makeFileUri(String path) { 531 }
339 String sep = "/"; 532 isNormalized = false;
340 if (path.startsWith(sep)) { 533 }
341 return new Uri(scheme: "file", pathSegments: path.split(sep)); 534 index++;
342 } else { 535 }
343 return new Uri(pathSegments: path.split(sep)); 536 else if (_isGeneralDelimiter(char)) {
344 } 537 _fail(host, index, "Invalid character");
345 } 538 }
346 static _makeWindowsFileUrl(String path) { 539 else {
347 if (path.startsWith("\\\\?\\")) { 540 int sourceLength = 1;
348 if (path.startsWith("\\\\?\\UNC\\")) { 541 if ((char & 0xFC00) == 0xD800 && (index + 1) < end) {
349 path = "\\${path.substring(7)}"; 542 int tail = host.codeUnitAt(index + 1);
350 } else { 543 if ((tail & 0xFC00) == 0xDC00) {
351 path = path.substring(4); 544 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
352 if (path.length < 3 || 545 sourceLength = 2;
353 path.codeUnitAt(1) != _COLON || 546 }
354 path.codeUnitAt(2) != _BACKSLASH) { 547 }
355 throw new ArgumentError( 548 if (buffer == null) buffer = new StringBuffer();
356 "Windows paths with \\\\?\\ prefix must be absolute"); 549 String slice = host.substring(sectionStart, index);
357 } 550 if (!isNormalized) slice = slice.toLowerCase();
358 } 551 buffer.write(slice);
359 } else { 552 buffer.write(_escapeChar(char));
360 path = path.replaceAll("/", "\\"); 553 index += sourceLength;
361 } 554 sectionStart = index;
362 String sep = "\\"; 555 }
363 if (path.length > 1 && path[1] == ":") { 556 }
364 _checkWindowsDriveLetter(path.codeUnitAt(0), true); 557 if (buffer == null) return host.substring(start, end);
365 if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) { 558 if (sectionStart < end) {
366 throw new ArgumentError( 559 String slice = host.substring(sectionStart, end);
367 "Windows paths with drive letter must be absolute"); 560 if (!isNormalized) slice = slice.toLowerCase();
368 } 561 buffer.write(slice);
369 var pathSegments = path.split(sep); 562 }
370 _checkWindowsPathReservedCharacters(pathSegments, true, 1); 563 return buffer.toString();
371 return new Uri(scheme: "file", pathSegments: pathSegments); 564 }
372 } 565 static String _makeScheme(String scheme, int end) {
373 if (path.length > 0 && path[0] == sep) { 566 if (end == 0) return "";
374 if (path.length > 1 && path[1] == sep) { 567 final int firstCodeUnit = scheme.codeUnitAt(0);
375 int pathStart = path.indexOf("\\", 2); 568 if (!_isAlphabeticCharacter(firstCodeUnit)) {
376 String hostPart = 569 _fail(scheme, 0, "Scheme not starting with alphabetic character");
377 pathStart == -1 ? path.substring(2) : path.substring(2, pathStart); 570 }
378 String pathPart = pathStart == -1 ? "" : path.substring(pathStart + 1); 571 bool allLowercase = firstCodeUnit >= _LOWER_CASE_A;
379 var pathSegments = pathPart.split(sep); 572 for (int i = 0;
380 _checkWindowsPathReservedCharacters(pathSegments, true); 573 i < end;
381 return new Uri( 574 i++) {
382 scheme: "file", host: hostPart, pathSegments: pathSegments); 575 final int codeUnit = scheme.codeUnitAt(i);
383 } else { 576 if (!_isSchemeCharacter(codeUnit)) {
384 var pathSegments = path.split(sep); 577 _fail(scheme, i, "Illegal scheme character");
385 _checkWindowsPathReservedCharacters(pathSegments, true); 578 }
386 return new Uri(scheme: "file", pathSegments: pathSegments); 579 if (codeUnit < _LOWER_CASE_A || codeUnit > _LOWER_CASE_Z) {
387 } 580 allLowercase = false;
388 } else { 581 }
389 var pathSegments = path.split(sep); 582 }
390 _checkWindowsPathReservedCharacters(pathSegments, true); 583 scheme = scheme.substring(0, end);
391 return new Uri(pathSegments: pathSegments); 584 if (!allLowercase) scheme = scheme.toLowerCase();
392 } 585 return scheme;
393 } 586 }
394 Uri replace({String scheme, String userInfo, String host, int port, 587 static String _makeUserInfo(String userInfo, int start, int end) {
395 String path, Iterable<String> pathSegments, String query, 588 if (userInfo == null) return "";
396 Map<String, String> queryParameters, String fragment}) { 589 return _normalize(userInfo, start, end, DDC$RT.cast(_userinfoTable, dynamic, DD C$RT.type((List<int> _) {
397 bool schemeChanged = false; 590 }
398 if (scheme != null) { 591 ), "CastGeneral", """line 1130, column 45 of dart:core/uri.dart: """, _userinfoT able is List<int>, false));
399 scheme = _makeScheme(scheme, scheme.length); 592 }
400 schemeChanged = true; 593 static String _makePath(String path, int start, int end, Iterable<String> pathS egments, bool ensureLeadingSlash, bool isFile) {
401 } else { 594 if (path == null && pathSegments == null) return isFile ? "/" : "";
402 scheme = this.scheme; 595 if (path != null && pathSegments != null) {
403 } 596 throw new ArgumentError('Both path and pathSegments specified');
404 bool isFile = (scheme == "file"); 597 }
405 if (userInfo != null) { 598 var result;
406 userInfo = _makeUserInfo(userInfo, 0, userInfo.length); 599 if (path != null) {
407 } else { 600 result = _normalize(path, start, end, DDC$RT.cast(_pathCharOrSlashTable, dynam ic, DDC$RT.type((List<int> _) {
408 userInfo = this.userInfo; 601 }
409 } 602 ), "CastGeneral", """line 1143, column 45 of dart:core/uri.dart: """, _pathCha rOrSlashTable is List<int>, false));
410 if (port != null) { 603 }
411 port = _makePort(port, scheme); 604 else {
412 } else { 605 result = pathSegments.map((s) => _uriEncode(DDC$RT.cast(_pathCharTable, dynami c, DDC$RT.type((List<int> _) {
413 port = ((__x43) => DDC$RT.cast(__x43, num, int, "CastGeneral", 606 }
414 """line 893, column 14 of dart:core/uri.dart: """, __x43 is int, 607 ), "CastGeneral", """line 1145, column 51 of dart:core/uri.dart: """, _pathCha rTable is List<int>, false), DDC$RT.cast(s, dynamic, String, "CastGeneral", """l ine 1145, column 67 of dart:core/uri.dart: """, s is String, true))).join("/");
415 true))(this._port); 608 }
416 if (schemeChanged) { 609 if (result.isEmpty) {
417 port = _makePort(port, scheme); 610 if (isFile) return "/";
418 } 611 }
419 } 612 else if ((isFile || ensureLeadingSlash) && result.codeUnitAt(0) != _SLASH) {
420 if (host != null) { 613 return "/$result";
421 host = _makeHost(host, 0, host.length, false); 614 }
422 } else if (this.hasAuthority) { 615 return DDC$RT.cast(result, dynamic, String, "CastGeneral", """line 1153, column 12 of dart:core/uri.dart: """, result is String, true);
423 host = this.host; 616 }
424 } else if (userInfo.isNotEmpty || port != null || isFile) { 617 static String _makeQuery(String query, int start, int end, Map<String, String> queryParameters) {
425 host = ""; 618 if (query == null && queryParameters == null) return null;
426 } 619 if (query != null && queryParameters != null) {
427 bool ensureLeadingSlash = (host != null); 620 throw new ArgumentError('Both query and queryParameters specified');
428 if (path != null || pathSegments != null) { 621 }
429 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, 622 if (query != null) return _normalize(query, start, end, DDC$RT.cast(_queryCharT able, dynamic, DDC$RT.type((List<int> _) {
430 ensureLeadingSlash, isFile); 623 }
431 } else { 624 ), "CastGeneral", """line 1162, column 61 of dart:core/uri.dart: """, _queryChar Table is List<int>, false));
432 path = this.path; 625 var result = new StringBuffer();
433 if ((isFile || (ensureLeadingSlash && !path.isEmpty)) && 626 var first = true;
434 !path.startsWith('/')) { 627 queryParameters.forEach((key, value) {
435 path = "/$path"; 628 if (!first) {
436 } 629 result.write("&");
437 } 630 }
438 if (query != null || queryParameters != null) { 631 first = false;
439 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters); 632 result.write(Uri.encodeQueryComponent(DDC$RT.cast(key, dynamic, String, "Cast General", """line 1171, column 45 of dart:core/uri.dart: """, key is String, tru e)));
440 } else if (this.hasQuery) { 633 if (value != null && !value.isEmpty) {
441 query = this.query; 634 result.write("=");
442 } 635 result.write(Uri.encodeQueryComponent(DDC$RT.cast(value, dynamic, String, " CastGeneral", """line 1174, column 47 of dart:core/uri.dart: """, value is Strin g, true)));
443 if (fragment != null) { 636 }
444 fragment = _makeFragment(fragment, 0, fragment.length); 637 }
445 } else if (this.hasFragment) { 638 );
446 fragment = this.fragment; 639 return result.toString();
447 } 640 }
448 return new Uri._internal( 641 static String _makeFragment(String fragment, int start, int end) {
449 scheme, userInfo, host, port, path, query, fragment); 642 if (fragment == null) return null;
450 } 643 return _normalize(fragment, start, end, DDC$RT.cast(_queryCharTable, dynamic, D DC$RT.type((List<int> _) {
451 List<String> get pathSegments { 644 }
452 if (_pathSegments == null) { 645 ), "CastGeneral", """line 1182, column 45 of dart:core/uri.dart: """, _queryChar Table is List<int>, false));
453 var pathToSplit = !path.isEmpty && path.codeUnitAt(0) == _SLASH 646 }
454 ? path.substring(1) 647 static int _stringOrNullLength(String s) => (s == null) ? 0 : s.length;
455 : path; 648 static bool _isHexDigit(int char) {
456 _pathSegments = ((__x44) => DDC$RT.cast(__x44, 649 if (_NINE >= char) return _ZERO <= char;
457 DDC$RT.type((DDC$collection$.UnmodifiableListView<dynamic> _) {}), 650 char |= 0x20;
458 DDC$RT.type((List<String> _) {}), "CastExact", 651 return _LOWER_CASE_A <= char && _LOWER_CASE_F >= char;
459 """line 949, column 23 of dart:core/uri.dart: """, 652 }
460 __x44 is List<String>, false))(new UnmodifiableListView( 653 static int _hexValue(int char) {
461 pathToSplit == "" 654 assert (_isHexDigit(char)); if (_NINE >= char) return char - _ZERO;
462 ? const <String>[] 655 char |= 0x20;
463 : pathToSplit 656 return char - (_LOWER_CASE_A - 10);
464 .split("/") 657 }
465 .map(Uri.decodeComponent) 658 static String _normalizeEscape(String source, int index, bool lowerCase) {
466 .toList(growable: false))); 659 assert (source.codeUnitAt(index) == _PERCENT); if (index + 2 >= source.length) {
467 } 660 return "%";
468 return _pathSegments; 661 }
469 } 662 int firstDigit = source.codeUnitAt(index + 1);
470 Map<String, String> get queryParameters { 663 int secondDigit = source.codeUnitAt(index + 2);
471 if (_queryParameters == null) { 664 if (!_isHexDigit(firstDigit) || !_isHexDigit(secondDigit)) {
472 _queryParameters = ((__x45) => DDC$RT.cast(__x45, DDC$RT.type( 665 return "%";
473 (DDC$collection$.UnmodifiableMapView<dynamic, dynamic> _) {}), 666 }
474 DDC$RT.type((Map<String, String> _) {}), "CastExact", 667 int value = _hexValue(firstDigit) * 16 + _hexValue(secondDigit);
475 """line 973, column 26 of dart:core/uri.dart: """, 668 if (_isUnreservedChar(value)) {
476 __x45 is Map<String, String>, 669 if (lowerCase && _UPPER_CASE_A <= value && _UPPER_CASE_Z >= value) {
477 false))(new UnmodifiableMapView(splitQueryString(query))); 670 value |= 0x20;
478 } 671 }
479 return _queryParameters; 672 return new String.fromCharCode(value);
480 } 673 }
481 static int _makePort(int port, String scheme) { 674 if (firstDigit >= _LOWER_CASE_A || secondDigit >= _LOWER_CASE_A) {
482 if (port != null && port == _defaultPort(scheme)) return ((__x46) => DDC$RT 675 return source.substring(index, index + 3).toUpperCase();
483 .cast(__x46, Null, int, "CastLiteral", 676 }
484 """line 980, column 62 of dart:core/uri.dart: """, __x46 is int, 677 return null;
485 true))(null); 678 }
486 return port; 679 static bool _isUnreservedChar(int ch) {
487 } 680 return ch < 127 && ((_unreservedTable[ch >> 4] & (1 << (ch & 0x0f))) != 0);
488 static String _makeHost(String host, int start, int end, bool strictIPv6) { 681 }
489 if (host == null) return null; 682 static String _escapeChar(char) {
490 if (start == end) return ""; 683 assert (char <= 0x10ffff); const hexDigits = "0123456789ABCDEF";
491 if (host.codeUnitAt(start) == _LEFT_BRACKET) { 684 List codeUnits;
492 if (host.codeUnitAt(end - 1) != _RIGHT_BRACKET) { 685 if (char < 0x80) {
493 _fail(host, start, 'Missing end `]` to match `[` in host'); 686 codeUnits = new List(3);
494 } 687 codeUnits[0] = _PERCENT;
495 parseIPv6Address(host, start + 1, end - 1); 688 codeUnits[1] = hexDigits.codeUnitAt(((__x47) => DDC$RT.cast(__x47, dynamic, i nt, "CastGeneral", """line 1252, column 43 of dart:core/uri.dart: """, __x47 is int, true))(char >> 4));
496 return host.substring(start, end).toLowerCase(); 689 codeUnits[2] = hexDigits.codeUnitAt(((__x48) => DDC$RT.cast(__x48, dynamic, i nt, "CastGeneral", """line 1253, column 43 of dart:core/uri.dart: """, __x48 is int, true))(char & 0xf));
497 } 690 }
498 if (!strictIPv6) { 691 else {
499 for (int i = start; i < end; i++) { 692 int flag = 0xc0;
500 if (host.codeUnitAt(i) == _COLON) { 693 int encodedBytes = 2;
501 parseIPv6Address(host, start, end); 694 if (char > 0x7ff) {
502 return '[$host]'; 695 flag = 0xe0;
503 } 696 encodedBytes = 3;
504 } 697 if (char > 0xffff) {
505 } 698 encodedBytes = 4;
506 return _normalizeRegName(host, start, end); 699 flag = 0xf0;
507 } 700 }
508 static bool _isRegNameChar(int char) { 701 }
509 return char < 127 && (_regNameTable[char >> 4] & (1 << (char & 0xf))) != 0; 702 codeUnits = new List(3 * encodedBytes);
510 } 703 int index = 0;
511 static String _normalizeRegName(String host, int start, int end) { 704 while (--encodedBytes >= 0) {
512 StringBuffer buffer; 705 int byte = ((__x49) => DDC$RT.cast(__x49, dynamic, int, "CastGeneral", """li ne 1269, column 20 of dart:core/uri.dart: """, __x49 is int, true))(((char >> (6 * encodedBytes)) & 0x3f) | flag);
513 int sectionStart = start; 706 codeUnits[index] = _PERCENT;
514 int index = start; 707 codeUnits[index + 1] = hexDigits.codeUnitAt(byte >> 4);
515 bool isNormalized = true; 708 codeUnits[index + 2] = hexDigits.codeUnitAt(byte & 0xf);
516 while (index < end) { 709 index += 3;
517 int char = host.codeUnitAt(index); 710 flag = 0x80;
518 if (char == _PERCENT) { 711 }
519 String replacement = _normalizeEscape(host, index, true); 712 }
520 if (replacement == null && isNormalized) { 713 return new String.fromCharCodes(codeUnits);
521 index += 3; 714 }
522 continue; 715 static String _normalize(String component, int start, int end, List<int> charTa ble) {
523 } 716 StringBuffer buffer;
524 if (buffer == null) buffer = new StringBuffer(); 717 int sectionStart = start;
525 String slice = host.substring(sectionStart, index); 718 int index = start;
526 if (!isNormalized) slice = slice.toLowerCase(); 719 while (index < end) {
527 buffer.write(slice); 720 int char = component.codeUnitAt(index);
528 int sourceLength = 3; 721 if (char < 127 && (charTable[char >> 4] & (1 << (char & 0x0f))) != 0) {
529 if (replacement == null) { 722 index++;
530 replacement = host.substring(index, index + 3); 723 }
531 } else if (replacement == "%") { 724 else {
532 replacement = "%25"; 725 String replacement;
533 sourceLength = 1; 726 int sourceLength;
534 } 727 if (char == _PERCENT) {
535 buffer.write(replacement); 728 replacement = _normalizeEscape(component, index, false);
536 index += sourceLength; 729 if (replacement == null) {
537 sectionStart = index; 730 index += 3;
538 isNormalized = true; 731 continue;
539 } else if (_isRegNameChar(char)) { 732 }
540 if (isNormalized && _UPPER_CASE_A <= char && _UPPER_CASE_Z >= char) { 733 if ("%" == replacement) {
541 if (buffer == null) buffer = new StringBuffer(); 734 replacement = "%25";
542 if (sectionStart < index) { 735 sourceLength = 1;
543 buffer.write(host.substring(sectionStart, index)); 736 }
544 sectionStart = index; 737 else {
545 } 738 sourceLength = 3;
546 isNormalized = false; 739 }
547 } 740 }
548 index++; 741 else if (_isGeneralDelimiter(char)) {
549 } else if (_isGeneralDelimiter(char)) { 742 _fail(component, index, "Invalid character");
550 _fail(host, index, "Invalid character"); 743 }
551 } else { 744 else {
552 int sourceLength = 1; 745 sourceLength = 1;
553 if ((char & 0xFC00) == 0xD800 && (index + 1) < end) { 746 if ((char & 0xFC00) == 0xD800) {
554 int tail = host.codeUnitAt(index + 1); 747 if (index + 1 < end) {
555 if ((tail & 0xFC00) == 0xDC00) { 748 int tail = component.codeUnitAt(index + 1);
556 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff); 749 if ((tail & 0xFC00) == 0xDC00) {
557 sourceLength = 2; 750 sourceLength = 2;
558 } 751 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
559 }
560 if (buffer == null) buffer = new StringBuffer();
561 String slice = host.substring(sectionStart, index);
562 if (!isNormalized) slice = slice.toLowerCase();
563 buffer.write(slice);
564 buffer.write(_escapeChar(char));
565 index += sourceLength;
566 sectionStart = index;
567 }
568 }
569 if (buffer == null) return host.substring(start, end);
570 if (sectionStart < end) {
571 String slice = host.substring(sectionStart, end);
572 if (!isNormalized) slice = slice.toLowerCase();
573 buffer.write(slice);
574 }
575 return buffer.toString();
576 }
577 static String _makeScheme(String scheme, int end) {
578 if (end == 0) return "";
579 final int firstCodeUnit = scheme.codeUnitAt(0);
580 if (!_isAlphabeticCharacter(firstCodeUnit)) {
581 _fail(scheme, 0, "Scheme not starting with alphabetic character");
582 }
583 bool allLowercase = firstCodeUnit >= _LOWER_CASE_A;
584 for (int i = 0; i < end; i++) {
585 final int codeUnit = scheme.codeUnitAt(i);
586 if (!_isSchemeCharacter(codeUnit)) {
587 _fail(scheme, i, "Illegal scheme character");
588 }
589 if (codeUnit < _LOWER_CASE_A || codeUnit > _LOWER_CASE_Z) {
590 allLowercase = false;
591 }
592 }
593 scheme = scheme.substring(0, end);
594 if (!allLowercase) scheme = scheme.toLowerCase();
595 return scheme;
596 }
597 static String _makeUserInfo(String userInfo, int start, int end) {
598 if (userInfo == null) return "";
599 return _normalize(userInfo, start, end, DDC$RT.cast(_userinfoTable, dynamic,
600 DDC$RT.type((List<int> _) {}), "CastGeneral",
601 """line 1130, column 45 of dart:core/uri.dart: """,
602 _userinfoTable is List<int>, false));
603 }
604 static String _makePath(String path, int start, int end,
605 Iterable<String> pathSegments, bool ensureLeadingSlash, bool isFile) {
606 if (path == null && pathSegments == null) return isFile ? "/" : "";
607 if (path != null && pathSegments != null) {
608 throw new ArgumentError('Both path and pathSegments specified');
609 }
610 var result;
611 if (path != null) {
612 result = _normalize(path, start, end, DDC$RT.cast(_pathCharOrSlashTable,
613 dynamic, DDC$RT.type((List<int> _) {}), "CastGeneral",
614 """line 1143, column 45 of dart:core/uri.dart: """,
615 _pathCharOrSlashTable is List<int>, false));
616 } else {
617 result = pathSegments
618 .map((s) => _uriEncode(DDC$RT.cast(_pathCharTable, dynamic,
619 DDC$RT.type((List<int> _) {}), "CastGeneral",
620 """line 1145, column 51 of dart:core/uri.dart: """,
621 _pathCharTable is List<int>, false), DDC$RT.cast(s, dynamic,
622 String, "CastGeneral",
623 """line 1145, column 67 of dart:core/uri.dart: """, s is String,
624 true)))
625 .join("/");
626 }
627 if (result.isEmpty) {
628 if (isFile) return "/";
629 } else if ((isFile || ensureLeadingSlash) &&
630 result.codeUnitAt(0) != _SLASH) {
631 return "/$result";
632 }
633 return DDC$RT.cast(result, dynamic, String, "CastGeneral",
634 """line 1153, column 12 of dart:core/uri.dart: """, result is String,
635 true);
636 }
637 static String _makeQuery(
638 String query, int start, int end, Map<String, String> queryParameters) {
639 if (query == null && queryParameters == null) return null;
640 if (query != null && queryParameters != null) {
641 throw new ArgumentError('Both query and queryParameters specified');
642 }
643 if (query != null) return _normalize(query, start, end, DDC$RT.cast(
644 _queryCharTable, dynamic, DDC$RT.type((List<int> _) {}), "CastGeneral",
645 """line 1162, column 61 of dart:core/uri.dart: """,
646 _queryCharTable is List<int>, false));
647 var result = new StringBuffer();
648 var first = true;
649 queryParameters.forEach((key, value) {
650 if (!first) {
651 result.write("&");
652 }
653 first = false;
654 result.write(Uri.encodeQueryComponent(DDC$RT.cast(key, dynamic, String,
655 "CastGeneral", """line 1171, column 45 of dart:core/uri.dart: """,
656 key is String, true)));
657 if (value != null && !value.isEmpty) {
658 result.write("=");
659 result.write(Uri.encodeQueryComponent(DDC$RT.cast(value, dynamic,
660 String, "CastGeneral",
661 """line 1174, column 47 of dart:core/uri.dart: """, value is String,
662 true)));
663 }
664 });
665 return result.toString();
666 }
667 static String _makeFragment(String fragment, int start, int end) {
668 if (fragment == null) return null;
669 return _normalize(fragment, start, end, DDC$RT.cast(_queryCharTable,
670 dynamic, DDC$RT.type((List<int> _) {}), "CastGeneral",
671 """line 1182, column 45 of dart:core/uri.dart: """,
672 _queryCharTable is List<int>, false));
673 }
674 static int _stringOrNullLength(String s) => (s == null) ? 0 : s.length;
675 static bool _isHexDigit(int char) {
676 if (_NINE >= char) return _ZERO <= char;
677 char |= 0x20;
678 return _LOWER_CASE_A <= char && _LOWER_CASE_F >= char;
679 }
680 static int _hexValue(int char) {
681 assert(_isHexDigit(char));
682 if (_NINE >= char) return char - _ZERO;
683 char |= 0x20;
684 return char - (_LOWER_CASE_A - 10);
685 }
686 static String _normalizeEscape(String source, int index, bool lowerCase) {
687 assert(source.codeUnitAt(index) == _PERCENT);
688 if (index + 2 >= source.length) {
689 return "%";
690 }
691 int firstDigit = source.codeUnitAt(index + 1);
692 int secondDigit = source.codeUnitAt(index + 2);
693 if (!_isHexDigit(firstDigit) || !_isHexDigit(secondDigit)) {
694 return "%";
695 }
696 int value = _hexValue(firstDigit) * 16 + _hexValue(secondDigit);
697 if (_isUnreservedChar(value)) {
698 if (lowerCase && _UPPER_CASE_A <= value && _UPPER_CASE_Z >= value) {
699 value |= 0x20;
700 }
701 return new String.fromCharCode(value);
702 }
703 if (firstDigit >= _LOWER_CASE_A || secondDigit >= _LOWER_CASE_A) {
704 return source.substring(index, index + 3).toUpperCase();
705 }
706 return null;
707 }
708 static bool _isUnreservedChar(int ch) {
709 return ch < 127 && ((_unreservedTable[ch >> 4] & (1 << (ch & 0x0f))) != 0);
710 }
711 static String _escapeChar(char) {
712 assert(char <= 0x10ffff);
713 const hexDigits = "0123456789ABCDEF";
714 List codeUnits;
715 if (char < 0x80) {
716 codeUnits = new List(3);
717 codeUnits[0] = _PERCENT;
718 codeUnits[1] = hexDigits.codeUnitAt(((__x47) => DDC$RT.cast(__x47,
719 dynamic, int, "CastGeneral",
720 """line 1252, column 43 of dart:core/uri.dart: """, __x47 is int,
721 true))(char >> 4));
722 codeUnits[2] = hexDigits.codeUnitAt(((__x48) => DDC$RT.cast(__x48,
723 dynamic, int, "CastGeneral",
724 """line 1253, column 43 of dart:core/uri.dart: """, __x48 is int,
725 true))(char & 0xf));
726 } else {
727 int flag = 0xc0;
728 int encodedBytes = 2;
729 if (char > 0x7ff) {
730 flag = 0xe0;
731 encodedBytes = 3;
732 if (char > 0xffff) {
733 encodedBytes = 4;
734 flag = 0xf0;
735 }
736 }
737 codeUnits = new List(3 * encodedBytes);
738 int index = 0;
739 while (--encodedBytes >= 0) {
740 int byte = ((__x49) => DDC$RT.cast(__x49, dynamic, int, "CastGeneral",
741 """line 1269, column 20 of dart:core/uri.dart: """, __x49 is int,
742 true))(((char >> (6 * encodedBytes)) & 0x3f) | flag);
743 codeUnits[index] = _PERCENT;
744 codeUnits[index + 1] = hexDigits.codeUnitAt(byte >> 4);
745 codeUnits[index + 2] = hexDigits.codeUnitAt(byte & 0xf);
746 index += 3;
747 flag = 0x80;
748 }
749 }
750 return new String.fromCharCodes(codeUnits);
751 }
752 static String _normalize(
753 String component, int start, int end, List<int> charTable) {
754 StringBuffer buffer;
755 int sectionStart = start;
756 int index = start;
757 while (index < end) {
758 int char = component.codeUnitAt(index);
759 if (char < 127 && (charTable[char >> 4] & (1 << (char & 0x0f))) != 0) {
760 index++;
761 } else {
762 String replacement;
763 int sourceLength;
764 if (char == _PERCENT) {
765 replacement = _normalizeEscape(component, index, false);
766 if (replacement == null) {
767 index += 3;
768 continue;
769 }
770 if ("%" == replacement) {
771 replacement = "%25";
772 sourceLength = 1;
773 } else {
774 sourceLength = 3;
775 }
776 } else if (_isGeneralDelimiter(char)) {
777 _fail(component, index, "Invalid character");
778 } else {
779 sourceLength = 1;
780 if ((char & 0xFC00) == 0xD800) {
781 if (index + 1 < end) {
782 int tail = component.codeUnitAt(index + 1);
783 if ((tail & 0xFC00) == 0xDC00) {
784 sourceLength = 2;
785 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
786 }
787 } 752 }
788 } 753 }
789 replacement = _escapeChar(char); 754 }
790 } 755 replacement = _escapeChar(char);
791 if (buffer == null) buffer = new StringBuffer(); 756 }
792 buffer.write(component.substring(sectionStart, index)); 757 if (buffer == null) buffer = new StringBuffer();
793 buffer.write(replacement); 758 buffer.write(component.substring(sectionStart, index));
794 index += sourceLength; 759 buffer.write(replacement);
795 sectionStart = index; 760 index += sourceLength;
796 } 761 sectionStart = index;
797 } 762 }
798 if (buffer == null) { 763 }
799 return component.substring(start, end); 764 if (buffer == null) {
800 } 765 return component.substring(start, end);
801 if (sectionStart < end) { 766 }
802 buffer.write(component.substring(sectionStart, end)); 767 if (sectionStart < end) {
803 } 768 buffer.write(component.substring(sectionStart, end));
804 return buffer.toString(); 769 }
805 } 770 return buffer.toString();
806 static bool _isSchemeCharacter(int ch) { 771 }
807 return ch < 128 && ((_schemeTable[ch >> 4] & (1 << (ch & 0x0f))) != 0); 772 static bool _isSchemeCharacter(int ch) {
808 } 773 return ch < 128 && ((_schemeTable[ch >> 4] & (1 << (ch & 0x0f))) != 0);
809 static bool _isGeneralDelimiter(int ch) { 774 }
810 return ch <= _RIGHT_BRACKET && 775 static bool _isGeneralDelimiter(int ch) {
811 ((_genDelimitersTable[ch >> 4] & (1 << (ch & 0x0f))) != 0); 776 return ch <= _RIGHT_BRACKET && ((_genDelimitersTable[ch >> 4] & (1 << (ch & 0x0f ))) != 0);
812 } 777 }
813 bool get isAbsolute => scheme != "" && fragment == ""; 778 bool get isAbsolute => scheme != "" && fragment == "";
814 String _merge(String base, String reference) { 779 String _merge(String base, String reference) {
815 if (base.isEmpty) return "/$reference"; 780 if (base.isEmpty) return "/$reference";
816 int backCount = 0; 781 int backCount = 0;
817 int refStart = 0; 782 int refStart = 0;
818 while (reference.startsWith("../", refStart)) { 783 while (reference.startsWith("../", refStart)) {
819 refStart += 3; 784 refStart += 3;
820 backCount++; 785 backCount++;
821 } 786 }
822 int baseEnd = base.lastIndexOf('/'); 787 int baseEnd = base.lastIndexOf('/');
823 while (baseEnd > 0 && backCount > 0) { 788 while (baseEnd > 0 && backCount > 0) {
824 int newEnd = base.lastIndexOf('/', baseEnd - 1); 789 int newEnd = base.lastIndexOf('/', baseEnd - 1);
825 if (newEnd < 0) { 790 if (newEnd < 0) {
826 break; 791 break;
827 } 792 }
828 int delta = baseEnd - newEnd; 793 int delta = baseEnd - newEnd;
829 if ((delta == 2 || delta == 3) && 794 if ((delta == 2 || delta == 3) && base.codeUnitAt(newEnd + 1) == _DOT && (del ta == 2 || base.codeUnitAt(newEnd + 2) == _DOT)) {
830 base.codeUnitAt(newEnd + 1) == _DOT && 795 break;
831 (delta == 2 || base.codeUnitAt(newEnd + 2) == _DOT)) { 796 }
832 break; 797 baseEnd = newEnd;
833 } 798 backCount--;
834 baseEnd = newEnd; 799 }
835 backCount--; 800 return base.substring(0, baseEnd + 1) + reference.substring(refStart - 3 * back Count);
836 } 801 }
837 return base.substring(0, baseEnd + 1) + 802 bool _hasDotSegments(String path) {
838 reference.substring(refStart - 3 * backCount); 803 if (path.length > 0 && path.codeUnitAt(0) == _DOT) return true;
839 } 804 int index = path.indexOf("/.");
840 bool _hasDotSegments(String path) { 805 return index != -1;
841 if (path.length > 0 && path.codeUnitAt(0) == _DOT) return true; 806 }
842 int index = path.indexOf("/."); 807 String _removeDotSegments(String path) {
843 return index != -1; 808 if (!_hasDotSegments(path)) return path;
844 } 809 List<String> output = ((__x50) => DDC$RT.cast(__x50, DDC$RT.type((List<dynamic> _) {
845 String _removeDotSegments(String path) { 810 }
846 if (!_hasDotSegments(path)) return path; 811 ), DDC$RT.type((List<String> _) {
847 List<String> output = ((__x50) => DDC$RT.cast(__x50, 812 }
848 DDC$RT.type((List<dynamic> _) {}), DDC$RT.type((List<String> _) {}), 813 ), "CastLiteral", """line 1406, column 27 of dart:core/uri.dart: """, __x50 is L ist<String>, false))([]);
849 "CastLiteral", """line 1406, column 27 of dart:core/uri.dart: """, 814 bool appendSlash = false;
850 __x50 is List<String>, false))([]); 815 for (String segment in path.split("/")) {
851 bool appendSlash = false; 816 appendSlash = false;
852 for (String segment in path.split("/")) { 817 if (segment == "..") {
853 appendSlash = false; 818 if (!output.isEmpty && ((output.length != 1) || (output[0] != ""))) output.r emoveLast();
854 if (segment == "..") { 819 appendSlash = true;
855 if (!output.isEmpty && 820 }
856 ((output.length != 1) || (output[0] != ""))) output.removeLast(); 821 else if ("." == segment) {
857 appendSlash = true; 822 appendSlash = true;
858 } else if ("." == segment) { 823 }
859 appendSlash = true; 824 else {
860 } else { 825 output.add(segment);
861 output.add(segment); 826 }
862 } 827 }
863 } 828 if (appendSlash) output.add("");
864 if (appendSlash) output.add(""); 829 return output.join("/");
865 return output.join("/"); 830 }
866 } 831 Uri resolve(String reference) {
867 Uri resolve(String reference) { 832 return resolveUri(Uri.parse(reference));
868 return resolveUri(Uri.parse(reference)); 833 }
869 } 834 Uri resolveUri(Uri reference) {
870 Uri resolveUri(Uri reference) { 835 String targetScheme;
871 String targetScheme; 836 String targetUserInfo = "";
872 String targetUserInfo = ""; 837 String targetHost;
873 String targetHost; 838 int targetPort;
874 int targetPort; 839 String targetPath;
875 String targetPath; 840 String targetQuery;
876 String targetQuery; 841 if (reference.scheme.isNotEmpty) {
877 if (reference.scheme.isNotEmpty) { 842 targetScheme = reference.scheme;
878 targetScheme = reference.scheme; 843 if (reference.hasAuthority) {
879 if (reference.hasAuthority) { 844 targetUserInfo = reference.userInfo;
880 targetUserInfo = reference.userInfo; 845 targetHost = reference.host;
881 targetHost = reference.host; 846 targetPort = ((__x51) => DDC$RT.cast(__x51, dynamic, int, "CastGeneral", "" "line 1460, column 22 of dart:core/uri.dart: """, __x51 is int, true))(reference .hasPort ? reference.port : null);
882 targetPort = ((__x51) => DDC$RT.cast(__x51, dynamic, int, "CastGeneral", 847 }
883 """line 1460, column 22 of dart:core/uri.dart: """, __x51 is int, 848 targetPath = _removeDotSegments(reference.path);
884 true))(reference.hasPort ? reference.port : null); 849 if (reference.hasQuery) {
885 } 850 targetQuery = reference.query;
886 targetPath = _removeDotSegments(reference.path); 851 }
887 if (reference.hasQuery) { 852 }
853 else {
854 targetScheme = this.scheme;
855 if (reference.hasAuthority) {
856 targetUserInfo = reference.userInfo;
857 targetHost = reference.host;
858 targetPort = _makePort(((__x52) => DDC$RT.cast(__x52, dynamic, int, "CastGe neral", """line 1471, column 32 of dart:core/uri.dart: """, __x52 is int, true)) (reference.hasPort ? reference.port : null), targetScheme);
859 targetPath = _removeDotSegments(reference.path);
860 if (reference.hasQuery) targetQuery = reference.query;
861 }
862 else {
863 if (reference.path == "") {
864 targetPath = this._path;
865 if (reference.hasQuery) {
888 targetQuery = reference.query; 866 targetQuery = reference.query;
889 } 867 }
890 } else { 868 else {
891 targetScheme = this.scheme; 869 targetQuery = this._query;
892 if (reference.hasAuthority) { 870 }
893 targetUserInfo = reference.userInfo; 871 }
894 targetHost = reference.host; 872 else {
895 targetPort = _makePort(((__x52) => DDC$RT.cast(__x52, dynamic, int, 873 if (reference.path.startsWith("/")) {
896 "CastGeneral", """line 1471, column 32 of dart:core/uri.dart: """,
897 __x52 is int,
898 true))(reference.hasPort ? reference.port : null), targetScheme);
899 targetPath = _removeDotSegments(reference.path); 874 targetPath = _removeDotSegments(reference.path);
900 if (reference.hasQuery) targetQuery = reference.query; 875 }
901 } else { 876 else {
902 if (reference.path == "") { 877 targetPath = _removeDotSegments(_merge(this._path, reference.path));
903 targetPath = this._path; 878 }
904 if (reference.hasQuery) { 879 if (reference.hasQuery) targetQuery = reference.query;
905 targetQuery = reference.query; 880 }
906 } else { 881 targetUserInfo = this._userInfo;
907 targetQuery = this._query; 882 targetHost = this._host;
908 } 883 targetPort = ((__x53) => DDC$RT.cast(__x53, num, int, "CastGeneral", """lin e 1493, column 22 of dart:core/uri.dart: """, __x53 is int, true))(this._port);
909 } else { 884 }
910 if (reference.path.startsWith("/")) { 885 }
911 targetPath = _removeDotSegments(reference.path); 886 String fragment = ((__x54) => DDC$RT.cast(__x54, dynamic, String, "CastGeneral" , """line 1496, column 23 of dart:core/uri.dart: """, __x54 is String, true))(re ference.hasFragment ? reference.fragment : null);
912 } else { 887 return new Uri._internal(targetScheme, targetUserInfo, targetHost, targetPort, targetPath, targetQuery, fragment);
913 targetPath = _removeDotSegments(_merge(this._path, reference.path)); 888 }
914 } 889 bool get hasAuthority => _host != null;
915 if (reference.hasQuery) targetQuery = reference.query; 890 bool get hasPort => _port != null;
916 } 891 bool get hasQuery => _query != null;
917 targetUserInfo = this._userInfo; 892 bool get hasFragment => _fragment != null;
918 targetHost = this._host; 893 String get origin {
919 targetPort = ((__x53) => DDC$RT.cast(__x53, num, int, "CastGeneral", 894 if (scheme == "" || _host == null || _host == "") {
920 """line 1493, column 22 of dart:core/uri.dart: """, __x53 is int, 895 throw new StateError("Cannot use origin without a scheme: $this");
921 true))(this._port); 896 }
922 } 897 if (scheme != "http" && scheme != "https") {
923 } 898 throw new StateError("Origin is only applicable schemes http and https: $this" );
924 String fragment = ((__x54) => DDC$RT.cast(__x54, dynamic, String, 899 }
925 "CastGeneral", """line 1496, column 23 of dart:core/uri.dart: """, 900 if (_port == null) return "$scheme://$_host";
926 __x54 is String, 901 return "$scheme://$_host:$_port";
927 true))(reference.hasFragment ? reference.fragment : null); 902 }
928 return new Uri._internal(targetScheme, targetUserInfo, targetHost, 903 String toFilePath({
929 targetPort, targetPath, targetQuery, fragment); 904 bool windows}
930 } 905 ) {
931 bool get hasAuthority => _host != null; 906 if (scheme != "" && scheme != "file") {
932 bool get hasPort => _port != null; 907 throw new UnsupportedError("Cannot extract a file path from a $scheme URI");
933 bool get hasQuery => _query != null; 908 }
934 bool get hasFragment => _fragment != null; 909 if (query != "") {
935 String get origin { 910 throw new UnsupportedError("Cannot extract a file path from a URI with a query component");
936 if (scheme == "" || _host == null || _host == "") { 911 }
937 throw new StateError("Cannot use origin without a scheme: $this"); 912 if (fragment != "") {
938 } 913 throw new UnsupportedError("Cannot extract a file path from a URI with a fragm ent component");
939 if (scheme != "http" && scheme != "https") { 914 }
940 throw new StateError( 915 if (windows == null) windows = _isWindows;
941 "Origin is only applicable schemes http and https: $this"); 916 return windows ? _toWindowsFilePath() : _toFilePath();
942 } 917 }
943 if (_port == null) return "$scheme://$_host"; 918 String _toFilePath() {
944 return "$scheme://$_host:$_port"; 919 if (host != "") {
945 } 920 throw new UnsupportedError("Cannot extract a non-Windows file path from a file URI " "with an authority");
946 String toFilePath({bool windows}) { 921 }
947 if (scheme != "" && scheme != "file") { 922 _checkNonWindowsPathReservedCharacters(pathSegments, false);
948 throw new UnsupportedError( 923 var result = new StringBuffer();
949 "Cannot extract a file path from a $scheme URI"); 924 if (_isPathAbsolute) result.write("/");
950 } 925 result.writeAll(pathSegments, "/");
951 if (query != "") { 926 return result.toString();
952 throw new UnsupportedError( 927 }
953 "Cannot extract a file path from a URI with a query component"); 928 String _toWindowsFilePath() {
954 } 929 bool hasDriveLetter = false;
955 if (fragment != "") { 930 var segments = pathSegments;
956 throw new UnsupportedError( 931 if (segments.length > 0 && segments[0].length == 2 && segments[0].codeUnitAt(1) == _COLON) {
957 "Cannot extract a file path from a URI with a fragment component"); 932 _checkWindowsDriveLetter(segments[0].codeUnitAt(0), false);
958 } 933 _checkWindowsPathReservedCharacters(segments, false, 1);
959 if (windows == null) windows = _isWindows; 934 hasDriveLetter = true;
960 return windows ? _toWindowsFilePath() : _toFilePath(); 935 }
961 } 936 else {
962 String _toFilePath() { 937 _checkWindowsPathReservedCharacters(segments, false);
963 if (host != "") { 938 }
964 throw new UnsupportedError( 939 var result = new StringBuffer();
965 "Cannot extract a non-Windows file path from a file URI " "with an aut hority"); 940 if (_isPathAbsolute && !hasDriveLetter) result.write("\\");
966 } 941 if (host != "") {
967 _checkNonWindowsPathReservedCharacters(pathSegments, false); 942 result.write("\\");
968 var result = new StringBuffer(); 943 result.write(host);
969 if (_isPathAbsolute) result.write("/"); 944 result.write("\\");
970 result.writeAll(pathSegments, "/"); 945 }
971 return result.toString(); 946 result.writeAll(segments, "\\");
972 } 947 if (hasDriveLetter && segments.length == 1) result.write("\\");
973 String _toWindowsFilePath() { 948 return result.toString();
974 bool hasDriveLetter = false; 949 }
975 var segments = pathSegments; 950 bool get _isPathAbsolute {
976 if (segments.length > 0 && 951 if (path == null || path.isEmpty) return false;
977 segments[0].length == 2 && 952 return path.startsWith('/');
978 segments[0].codeUnitAt(1) == _COLON) { 953 }
979 _checkWindowsDriveLetter(segments[0].codeUnitAt(0), false); 954 void _writeAuthority(StringSink ss) {
980 _checkWindowsPathReservedCharacters(segments, false, 1); 955 if (_userInfo.isNotEmpty) {
981 hasDriveLetter = true; 956 ss.write(_userInfo);
982 } else { 957 ss.write("@");
983 _checkWindowsPathReservedCharacters(segments, false); 958 }
984 } 959 if (_host != null) ss.write(_host);
985 var result = new StringBuffer(); 960 if (_port != null) {
986 if (_isPathAbsolute && !hasDriveLetter) result.write("\\"); 961 ss.write(":");
987 if (host != "") { 962 ss.write(_port);
988 result.write("\\"); 963 }
989 result.write(host); 964 }
990 result.write("\\"); 965 String toString() {
991 } 966 StringBuffer sb = new StringBuffer();
992 result.writeAll(segments, "\\"); 967 _addIfNonEmpty(sb, scheme, scheme, ':');
993 if (hasDriveLetter && segments.length == 1) result.write("\\"); 968 if (hasAuthority || path.startsWith("//") || (scheme == "file")) {
994 return result.toString(); 969 sb.write("//");
995 } 970 _writeAuthority(sb);
996 bool get _isPathAbsolute { 971 }
997 if (path == null || path.isEmpty) return false; 972 sb.write(path);
998 return path.startsWith('/'); 973 if (_query != null) {
999 } 974 sb..write("?")..write(_query);
1000 void _writeAuthority(StringSink ss) { 975 }
1001 if (_userInfo.isNotEmpty) { 976 if (_fragment != null) {
1002 ss.write(_userInfo); 977 sb..write("#")..write(_fragment);
1003 ss.write("@"); 978 }
1004 } 979 return sb.toString();
1005 if (_host != null) ss.write(_host); 980 }
1006 if (_port != null) { 981 bool operator ==(other) {
1007 ss.write(":"); 982 if (other is! Uri) return false;
1008 ss.write(_port); 983 Uri uri = DDC$RT.cast(other, dynamic, Uri, "CastGeneral", """line 1702, column 15 of dart:core/uri.dart: """, other is Uri, true);
1009 } 984 return scheme == uri.scheme && hasAuthority == uri.hasAuthority && userInfo == uri.userInfo && host == uri.host && port == uri.port && path == uri.path && hasQ uery == uri.hasQuery && query == uri.query && hasFragment == uri.hasFragment && fragment == uri.fragment;
1010 } 985 }
1011 String toString() { 986 int get hashCode {
1012 StringBuffer sb = new StringBuffer(); 987 int combine(part, current) {
1013 _addIfNonEmpty(sb, scheme, scheme, ':'); 988 return ((__x55) => DDC$RT.cast(__x55, dynamic, int, "CastGeneral", """line 171 8, column 14 of dart:core/uri.dart: """, __x55 is int, true))((current * 31 + pa rt.hashCode) & 0x3FFFFFFF);
1014 if (hasAuthority || path.startsWith("//") || (scheme == "file")) { 989 }
1015 sb.write("//"); 990 return combine(scheme, combine(userInfo, combine(host, combine(port, combine(pa th, combine(query, combine(fragment, 1)))))));
1016 _writeAuthority(sb); 991 }
1017 } 992 static void _addIfNonEmpty(StringBuffer sb, String test, String first, String s econd) {
1018 sb.write(path); 993 if ("" != test) {
1019 if (_query != null) { 994 sb.write(first);
1020 sb 995 sb.write(second);
1021 ..write("?") 996 }
1022 ..write(_query); 997 }
1023 } 998 static String encodeComponent(String component) {
1024 if (_fragment != null) { 999 return _uriEncode(DDC$RT.cast(_unreserved2396Table, dynamic, DDC$RT.type((List<i nt> _) {
1025 sb 1000 }
1026 ..write("#") 1001 ), "CastGeneral", """line 1753, column 23 of dart:core/uri.dart: """, _unreserve d2396Table is List<int>, false), component);
1027 ..write(_fragment); 1002 }
1028 } 1003 static String encodeQueryComponent(String component, {
1029 return sb.toString(); 1004 Encoding encoding : UTF8}
1030 } 1005 ) {
1031 bool operator ==(other) { 1006 return _uriEncode(DDC$RT.cast(_unreservedTable, dynamic, DDC$RT.type((List<int> _) {
1032 if (other is! Uri) return false; 1007 }
1033 Uri uri = DDC$RT.cast(other, dynamic, Uri, "CastGeneral", 1008 ), "CastGeneral", """line 1792, column 9 of dart:core/uri.dart: """, _unreserved Table is List<int>, false), component, encoding: encoding, spaceToPlus: true);
1034 """line 1702, column 15 of dart:core/uri.dart: """, other is Uri, true); 1009 }
1035 return scheme == uri.scheme && 1010 static String decodeComponent(String encodedComponent) {
1036 hasAuthority == uri.hasAuthority && 1011 return _uriDecode(encodedComponent);
1037 userInfo == uri.userInfo && 1012 }
1038 host == uri.host && 1013 static String decodeQueryComponent(String encodedComponent, {
1039 port == uri.port && 1014 Encoding encoding : UTF8}
1040 path == uri.path && 1015 ) {
1041 hasQuery == uri.hasQuery && 1016 return _uriDecode(encodedComponent, plusToSpace: true, encoding: encoding);
1042 query == uri.query && 1017 }
1043 hasFragment == uri.hasFragment && 1018 static String encodeFull(String uri) {
1044 fragment == uri.fragment; 1019 return _uriEncode(DDC$RT.cast(_encodeFullTable, dynamic, DDC$RT.type((List<int> _) {
1045 } 1020 }
1046 int get hashCode { 1021 ), "CastGeneral", """line 1836, column 23 of dart:core/uri.dart: """, _encodeFul lTable is List<int>, false), uri);
1047 int combine(part, current) { 1022 }
1048 return ((__x55) => DDC$RT.cast(__x55, dynamic, int, "CastGeneral", 1023 static String decodeFull(String uri) {
1049 """line 1718, column 14 of dart:core/uri.dart: """, __x55 is int, 1024 return _uriDecode(uri);
1050 true))((current * 31 + part.hashCode) & 0x3FFFFFFF); 1025 }
1051 } 1026 static Map<String, String> splitQueryString(String query, {
1052 return combine(scheme, combine(userInfo, combine(host, 1027 Encoding encoding : UTF8}
1053 combine(port, combine(path, combine(query, combine(fragment, 1))))))); 1028 ) {
1054 } 1029 return ((__x56) => DDC$RT.cast(__x56, dynamic, DDC$RT.type((Map<String, String> _) {
1055 static void _addIfNonEmpty( 1030 }
1056 StringBuffer sb, String test, String first, String second) { 1031 ), "CastGeneral", """line 1868, column 12 of dart:core/uri.dart: """, __x56 is M ap<String, String>, false))(query.split("&").fold({
1057 if ("" != test) { 1032 }
1058 sb.write(first); 1033 , (map, element) {
1059 sb.write(second); 1034 int index = ((__x57) => DDC$RT.cast(__x57, dynamic, int, "CastGeneral", """lin e 1869, column 19 of dart:core/uri.dart: """, __x57 is int, true))(element.index Of("="));
1060 } 1035 if (index == -1) {
1061 } 1036 if (element != "") {
1062 static String encodeComponent(String component) { 1037 map[decodeQueryComponent(DDC$RT.cast(element, dynamic, String, "CastGenera l", """line 1872, column 36 of dart:core/uri.dart: """, element is String, true) , encoding: encoding)] = "";
1063 return _uriEncode(DDC$RT.cast(_unreserved2396Table, dynamic, 1038 }
1064 DDC$RT.type((List<int> _) {}), "CastGeneral", 1039 }
1065 """line 1753, column 23 of dart:core/uri.dart: """, 1040 else if (index != 0) {
1066 _unreserved2396Table is List<int>, false), component); 1041 var key = element.substring(0, index);
1067 } 1042 var value = element.substring(index + 1);
1068 static String encodeQueryComponent(String component, 1043 map[Uri.decodeQueryComponent(DDC$RT.cast(key, dynamic, String, "CastGeneral ", """line 1877, column 38 of dart:core/uri.dart: """, key is String, true), enc oding: encoding)] = decodeQueryComponent(DDC$RT.cast(value, dynamic, String, "Ca stGeneral", """line 1878, column 34 of dart:core/uri.dart: """, value is String, true), encoding: encoding);
1069 {Encoding encoding: UTF8}) { 1044 }
1070 return _uriEncode(DDC$RT.cast(_unreservedTable, dynamic, 1045 return map;
1071 DDC$RT.type((List<int> _) {}), "CastGeneral", 1046 }
1072 """line 1792, column 9 of dart:core/uri.dart: """, 1047 ));
1073 _unreservedTable is List<int>, false), component, 1048 }
1074 encoding: encoding, spaceToPlus: true); 1049 static List<int> parseIPv4Address(String host) {
1075 } 1050 void error(String msg) {
1076 static String decodeComponent(String encodedComponent) { 1051 throw new FormatException('Illegal IPv4 address, $msg');
1077 return _uriDecode(encodedComponent); 1052 }
1078 } 1053 var bytes = host.split('.');
1079 static String decodeQueryComponent(String encodedComponent, 1054 if (bytes.length != 4) {
1080 {Encoding encoding: UTF8}) { 1055 error('IPv4 address should contain exactly 4 parts');
1081 return _uriDecode(encodedComponent, plusToSpace: true, encoding: encoding); 1056 }
1082 } 1057 return ((__x58) => DDC$RT.cast(__x58, DDC$RT.type((List<dynamic> _) {
1083 static String encodeFull(String uri) { 1058 }
1084 return _uriEncode(DDC$RT.cast(_encodeFullTable, dynamic, 1059 ), DDC$RT.type((List<int> _) {
1085 DDC$RT.type((List<int> _) {}), "CastGeneral", 1060 }
1086 """line 1836, column 23 of dart:core/uri.dart: """, 1061 ), "CastDynamic", """line 1900, column 12 of dart:core/uri.dart: """, __x58 is L ist<int>, false))(bytes.map((byteString) {
1087 _encodeFullTable is List<int>, false), uri); 1062 int byte = int.parse(DDC$RT.cast(byteString, dynamic, String, "CastGeneral", " ""line 1902, column 32 of dart:core/uri.dart: """, byteString is String, true));
1088 } 1063 if (byte < 0 || byte > 255) {
1089 static String decodeFull(String uri) { 1064 error('each part must be in the range of `0..255`');
1090 return _uriDecode(uri); 1065 }
1091 } 1066 return byte;
1092 static Map<String, String> splitQueryString(String query, 1067 }
1093 {Encoding encoding: UTF8}) { 1068 ).toList());
1094 return ((__x56) => DDC$RT.cast(__x56, dynamic, 1069 }
1095 DDC$RT.type((Map<String, String> _) {}), "CastGeneral", 1070 static List<int> parseIPv6Address(String host, [int start = 0, int end]) {
1096 """line 1868, column 12 of dart:core/uri.dart: """, 1071 if (end == null) end = host.length;
1097 __x56 is Map<String, String>, false))(query 1072 void error(String msg, [position]) {
1098 .split("&") 1073 throw new FormatException('Illegal IPv6 address, $msg', host, position);
1099 .fold({}, (map, element) { 1074 }
1100 int index = ((__x57) => DDC$RT.cast(__x57, dynamic, int, "CastGeneral", 1075 int parseHex(int start, int end) {
1101 """line 1869, column 19 of dart:core/uri.dart: """, __x57 is int, 1076 if (end - start > 4) {
1102 true))(element.indexOf("=")); 1077 error('an IPv6 part can only contain a maximum of 4 hex digits', start);
1103 if (index == -1) { 1078 }
1104 if (element != "") { 1079 int value = int.parse(host.substring(start, end), radix: 16);
1105 map[decodeQueryComponent(DDC$RT.cast(element, dynamic, String, 1080 if (value < 0 || value > (1 << 16) - 1) {
1106 "CastGeneral", """line 1872, column 36 of dart:core/uri.dart: """, 1081 error('each part must be in the range of `0x0..0xFFFF`', start);
1107 element is String, true), encoding: encoding)] = ""; 1082 }
1108 } 1083 return value;
1109 } else if (index != 0) { 1084 }
1110 var key = element.substring(0, index); 1085 if (host.length < 2) error('address is too short');
1111 var value = element.substring(index + 1); 1086 List<int> parts = ((__x59) => DDC$RT.cast(__x59, DDC$RT.type((List<dynamic> _) {
1112 map[Uri.decodeQueryComponent(DDC$RT.cast(key, dynamic, String, 1087 }
1113 "CastGeneral", 1088 ), DDC$RT.type((List<int> _) {
1114 """line 1877, column 38 of dart:core/uri.dart: """, 1089 }
1115 key is String, true), 1090 ), "CastLiteral", """line 1950, column 23 of dart:core/uri.dart: """, __x59 is L ist<int>, false))([]);
1116 encoding: encoding)] = decodeQueryComponent(DDC$RT.cast(value, 1091 bool wildcardSeen = false;
1117 dynamic, String, "CastGeneral", 1092 int partStart = start;
1118 """line 1878, column 34 of dart:core/uri.dart: """, 1093 for (int i = start;
1119 value is String, true), encoding: encoding); 1094 i < end;
1120 } 1095 i++) {
1121 return map; 1096 if (host.codeUnitAt(i) == _COLON) {
1122 })); 1097 if (i == start) {
1123 } 1098 i++;
1124 static List<int> parseIPv4Address(String host) { 1099 if (host.codeUnitAt(i) != _COLON) {
1125 void error(String msg) { 1100 error('invalid start colon.', i);
1126 throw new FormatException('Illegal IPv4 address, $msg'); 1101 }
1127 } 1102 partStart = i;
1128 var bytes = host.split('.'); 1103 }
1129 if (bytes.length != 4) { 1104 if (i == partStart) {
1130 error('IPv4 address should contain exactly 4 parts'); 1105 if (wildcardSeen) {
1131 } 1106 error('only one wildcard `::` is allowed', i);
1132 return ((__x58) => DDC$RT.cast(__x58, DDC$RT.type((List<dynamic> _) {}), 1107 }
1133 DDC$RT.type((List<int> _) {}), "CastDynamic", 1108 wildcardSeen = true;
1134 """line 1900, column 12 of dart:core/uri.dart: """, __x58 is List<int>, 1109 parts.add(-1);
1135 false))(bytes.map((byteString) { 1110 }
1136 int byte = int.parse(DDC$RT.cast(byteString, dynamic, String, 1111 else {
1137 "CastGeneral", """line 1902, column 32 of dart:core/uri.dart: """, 1112 parts.add(parseHex(partStart, i));
1138 byteString is String, true)); 1113 }
1139 if (byte < 0 || byte > 255) { 1114 partStart = i + 1;
1140 error('each part must be in the range of `0..255`'); 1115 }
1141 } 1116 }
1142 return byte; 1117 if (parts.length == 0) error('too few parts');
1143 }).toList()); 1118 bool atEnd = (partStart == end);
1144 } 1119 bool isLastWildcard = (parts.last == -1);
1145 static List<int> parseIPv6Address(String host, [int start = 0, int end]) { 1120 if (atEnd && !isLastWildcard) {
1146 if (end == null) end = host.length; 1121 error('expected a part after last `:`', end);
1147 void error(String msg, [position]) { 1122 }
1148 throw new FormatException('Illegal IPv6 address, $msg', host, position); 1123 if (!atEnd) {
1149 } 1124 try {
1150 int parseHex(int start, int end) { 1125 parts.add(parseHex(partStart, end));
1151 if (end - start > 4) { 1126 }
1152 error('an IPv6 part can only contain a maximum of 4 hex digits', start); 1127 catch (e) {
1153 } 1128 try {
1154 int value = int.parse(host.substring(start, end), radix: 16); 1129 List<int> last = parseIPv4Address(host.substring(partStart, end));
1155 if (value < 0 || value > (1 << 16) - 1) { 1130 parts.add(last[0] << 8 | last[1]);
1156 error('each part must be in the range of `0x0..0xFFFF`', start); 1131 parts.add(last[2] << 8 | last[3]);
1157 } 1132 }
1158 return value; 1133 catch (e) {
1159 } 1134 error('invalid end of IPv6 address.', partStart);
1160 if (host.length < 2) error('address is too short'); 1135 }
1161 List<int> parts = ((__x59) => DDC$RT.cast(__x59, 1136 }
1162 DDC$RT.type((List<dynamic> _) {}), DDC$RT.type((List<int> _) {}), 1137 }
1163 "CastLiteral", """line 1950, column 23 of dart:core/uri.dart: """, 1138 if (wildcardSeen) {
1164 __x59 is List<int>, false))([]); 1139 if (parts.length > 7) {
1165 bool wildcardSeen = false; 1140 error('an address with a wildcard must have less than 7 parts');
1166 int partStart = start; 1141 }
1167 for (int i = start; i < end; i++) { 1142 }
1168 if (host.codeUnitAt(i) == _COLON) { 1143 else if (parts.length != 8) {
1169 if (i == start) { 1144 error('an address without a wildcard must contain exactly 8 parts');
1170 i++; 1145 }
1171 if (host.codeUnitAt(i) != _COLON) { 1146 List bytes = new List<int>(16);
1172 error('invalid start colon.', i); 1147 for (int i = 0, index = 0;
1173 } 1148 i < parts.length;
1174 partStart = i; 1149 i++) {
1175 } 1150 int value = parts[i];
1176 if (i == partStart) { 1151 if (value == -1) {
1177 if (wildcardSeen) { 1152 int wildCardLength = 9 - parts.length;
1178 error('only one wildcard `::` is allowed', i); 1153 for (int j = 0;
1179 } 1154 j < wildCardLength;
1180 wildcardSeen = true; 1155 j++) {
1181 parts.add(-1); 1156 bytes[index] = 0;
1182 } else { 1157 bytes[index + 1] = 0;
1183 parts.add(parseHex(partStart, i)); 1158 index += 2;
1184 } 1159 }
1185 partStart = i + 1; 1160 }
1186 } 1161 else {
1187 } 1162 bytes[index] = value >> 8;
1188 if (parts.length == 0) error('too few parts'); 1163 bytes[index + 1] = value & 0xff;
1189 bool atEnd = (partStart == end); 1164 index += 2;
1190 bool isLastWildcard = (parts.last == -1); 1165 }
1191 if (atEnd && !isLastWildcard) { 1166 }
1192 error('expected a part after last `:`', end); 1167 return DDC$RT.cast(bytes, DDC$RT.type((List<dynamic> _) {
1193 } 1168 }
1194 if (!atEnd) { 1169 ), DDC$RT.type((List<int> _) {
1195 try { 1170 }
1196 parts.add(parseHex(partStart, end)); 1171 ), "CastDynamic", """line 2022, column 12 of dart:core/uri.dart: """, bytes is L ist<int>, false);
1197 } catch (e) { 1172 }
1198 try { 1173 static const int _SPACE = 0x20;
1199 List<int> last = parseIPv4Address(host.substring(partStart, end)); 1174 static const int _DOUBLE_QUOTE = 0x22;
1200 parts.add(last[0] << 8 | last[1]); 1175 static const int _NUMBER_SIGN = 0x23;
1201 parts.add(last[2] << 8 | last[3]); 1176 static const int _PERCENT = 0x25;
1202 } catch (e) { 1177 static const int _ASTERISK = 0x2A;
1203 error('invalid end of IPv6 address.', partStart); 1178 static const int _PLUS = 0x2B;
1204 } 1179 static const int _DOT = 0x2E;
1205 } 1180 static const int _SLASH = 0x2F;
1206 } 1181 static const int _ZERO = 0x30;
1207 if (wildcardSeen) { 1182 static const int _NINE = 0x39;
1208 if (parts.length > 7) { 1183 static const int _COLON = 0x3A;
1209 error('an address with a wildcard must have less than 7 parts'); 1184 static const int _LESS = 0x3C;
1210 } 1185 static const int _GREATER = 0x3E;
1211 } else if (parts.length != 8) { 1186 static const int _QUESTION = 0x3F;
1212 error('an address without a wildcard must contain exactly 8 parts'); 1187 static const int _AT_SIGN = 0x40;
1213 } 1188 static const int _UPPER_CASE_A = 0x41;
1214 List bytes = new List<int>(16); 1189 static const int _UPPER_CASE_F = 0x46;
1215 for (int i = 0, index = 0; i < parts.length; i++) { 1190 static const int _UPPER_CASE_Z = 0x5A;
1216 int value = parts[i]; 1191 static const int _LEFT_BRACKET = 0x5B;
1217 if (value == -1) { 1192 static const int _BACKSLASH = 0x5C;
1218 int wildCardLength = 9 - parts.length; 1193 static const int _RIGHT_BRACKET = 0x5D;
1219 for (int j = 0; j < wildCardLength; j++) { 1194 static const int _LOWER_CASE_A = 0x61;
1220 bytes[index] = 0; 1195 static const int _LOWER_CASE_F = 0x66;
1221 bytes[index + 1] = 0; 1196 static const int _LOWER_CASE_Z = 0x7A;
1222 index += 2; 1197 static const int _BAR = 0x7C;
1223 } 1198 static String _uriEncode(List<int> canonicalTable, String text, {
1224 } else { 1199 Encoding encoding : UTF8, bool spaceToPlus : false}
1225 bytes[index] = value >> 8; 1200 ) {
1226 bytes[index + 1] = value & 0xff; 1201 byteToHex(byte, buffer) {
1227 index += 2; 1202 const String hex = '0123456789ABCDEF';
1228 } 1203 buffer.writeCharCode(hex.codeUnitAt(((__x60) => DDC$RT.cast(__x60, dynamic, i nt, "CastGeneral", """line 2063, column 43 of dart:core/uri.dart: """, __x60 is int, true))(byte >> 4)));
1229 } 1204 buffer.writeCharCode(hex.codeUnitAt(((__x61) => DDC$RT.cast(__x61, dynamic, i nt, "CastGeneral", """line 2064, column 43 of dart:core/uri.dart: """, __x61 is int, true))(byte & 0x0f)));
1230 return DDC$RT.cast(bytes, DDC$RT.type((List<dynamic> _) {}), 1205 }
1231 DDC$RT.type((List<int> _) {}), "CastDynamic", 1206 StringBuffer result = new StringBuffer();
1232 """line 2022, column 12 of dart:core/uri.dart: """, bytes is List<int>, 1207 var bytes = encoding.encode(text);
1233 false); 1208 for (int i = 0;
1234 } 1209 i < bytes.length;
1235 static const int _SPACE = 0x20; 1210 i++) {
1236 static const int _DOUBLE_QUOTE = 0x22; 1211 int byte = bytes[i];
1237 static const int _NUMBER_SIGN = 0x23; 1212 if (byte < 128 && ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) {
1238 static const int _PERCENT = 0x25; 1213 result.writeCharCode(byte);
1239 static const int _ASTERISK = 0x2A; 1214 }
1240 static const int _PLUS = 0x2B; 1215 else if (spaceToPlus && byte == _SPACE) {
1241 static const int _DOT = 0x2E; 1216 result.writeCharCode(_PLUS);
1242 static const int _SLASH = 0x2F; 1217 }
1243 static const int _ZERO = 0x30; 1218 else {
1244 static const int _NINE = 0x39; 1219 result.writeCharCode(_PERCENT);
1245 static const int _COLON = 0x3A; 1220 byteToHex(byte, result);
1246 static const int _LESS = 0x3C; 1221 }
1247 static const int _GREATER = 0x3E; 1222 }
1248 static const int _QUESTION = 0x3F; 1223 return result.toString();
1249 static const int _AT_SIGN = 0x40; 1224 }
1250 static const int _UPPER_CASE_A = 0x41; 1225 static int _hexCharPairToByte(String s, int pos) {
1251 static const int _UPPER_CASE_F = 0x46; 1226 int byte = 0;
1252 static const int _UPPER_CASE_Z = 0x5A; 1227 for (int i = 0;
1253 static const int _LEFT_BRACKET = 0x5B; 1228 i < 2;
1254 static const int _BACKSLASH = 0x5C; 1229 i++) {
1255 static const int _RIGHT_BRACKET = 0x5D; 1230 var charCode = s.codeUnitAt(pos + i);
1256 static const int _LOWER_CASE_A = 0x61; 1231 if (0x30 <= charCode && charCode <= 0x39) {
1257 static const int _LOWER_CASE_F = 0x66; 1232 byte = byte * 16 + charCode - 0x30;
1258 static const int _LOWER_CASE_Z = 0x7A; 1233 }
1259 static const int _BAR = 0x7C; 1234 else {
1260 static String _uriEncode(List<int> canonicalTable, String text, 1235 charCode |= 0x20;
1261 {Encoding encoding: UTF8, bool spaceToPlus: false}) { 1236 if (0x61 <= charCode && charCode <= 0x66) {
1262 byteToHex(byte, buffer) { 1237 byte = byte * 16 + charCode - 0x57;
1263 const String hex = '0123456789ABCDEF'; 1238 }
1264 buffer.writeCharCode(hex.codeUnitAt(((__x60) => DDC$RT.cast(__x60, 1239 else {
1265 dynamic, int, "CastGeneral", 1240 throw new ArgumentError("Invalid URL encoding");
1266 """line 2063, column 43 of dart:core/uri.dart: """, __x60 is int, 1241 }
1267 true))(byte >> 4))); 1242 }
1268 buffer.writeCharCode(hex.codeUnitAt(((__x61) => DDC$RT.cast(__x61, 1243 }
1269 dynamic, int, "CastGeneral", 1244 return byte;
1270 """line 2064, column 43 of dart:core/uri.dart: """, __x61 is int, 1245 }
1271 true))(byte & 0x0f))); 1246 static String _uriDecode(String text, {
1272 } 1247 bool plusToSpace : false, Encoding encoding : UTF8}
1273 StringBuffer result = new StringBuffer(); 1248 ) {
1274 var bytes = encoding.encode(text); 1249 bool simple = true;
1275 for (int i = 0; i < bytes.length; i++) { 1250 for (int i = 0;
1276 int byte = bytes[i]; 1251 i < text.length && simple;
1277 if (byte < 128 && 1252 i++) {
1278 ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { 1253 var codeUnit = text.codeUnitAt(i);
1279 result.writeCharCode(byte); 1254 simple = codeUnit != _PERCENT && codeUnit != _PLUS;
1280 } else if (spaceToPlus && byte == _SPACE) { 1255 }
1281 result.writeCharCode(_PLUS); 1256 List<int> bytes;
1282 } else { 1257 if (simple) {
1283 result.writeCharCode(_PERCENT); 1258 if (encoding == UTF8 || encoding == LATIN1) {
1284 byteToHex(byte, result); 1259 return text;
1285 } 1260 }
1286 } 1261 else {
1287 return result.toString(); 1262 bytes = text.codeUnits;
1288 } 1263 }
1289 static int _hexCharPairToByte(String s, int pos) { 1264 }
1290 int byte = 0; 1265 else {
1291 for (int i = 0; i < 2; i++) { 1266 bytes = ((__x62) => DDC$RT.cast(__x62, DDC$RT.type((List<dynamic> _) {
1292 var charCode = s.codeUnitAt(pos + i); 1267 }
1293 if (0x30 <= charCode && charCode <= 0x39) { 1268 ), DDC$RT.type((List<int> _) {
1294 byte = byte * 16 + charCode - 0x30; 1269 }
1295 } else { 1270 ), "CastExact", """line 2138, column 15 of dart:core/uri.dart: """, __x62 is L ist<int>, false))(new List());
1296 charCode |= 0x20; 1271 for (int i = 0;
1297 if (0x61 <= charCode && charCode <= 0x66) { 1272 i < text.length;
1298 byte = byte * 16 + charCode - 0x57; 1273 i++) {
1299 } else { 1274 var codeUnit = text.codeUnitAt(i);
1300 throw new ArgumentError("Invalid URL encoding"); 1275 if (codeUnit > 127) {
1301 } 1276 throw new ArgumentError("Illegal percent encoding in URI");
1302 } 1277 }
1303 } 1278 if (codeUnit == _PERCENT) {
1304 return byte; 1279 if (i + 3 > text.length) {
1305 } 1280 throw new ArgumentError('Truncated URI');
1306 static String _uriDecode(String text, 1281 }
1307 {bool plusToSpace: false, Encoding encoding: UTF8}) { 1282 bytes.add(_hexCharPairToByte(text, i + 1));
1308 bool simple = true; 1283 i += 2;
1309 for (int i = 0; i < text.length && simple; i++) { 1284 }
1310 var codeUnit = text.codeUnitAt(i); 1285 else if (plusToSpace && codeUnit == _PLUS) {
1311 simple = codeUnit != _PERCENT && codeUnit != _PLUS; 1286 bytes.add(_SPACE);
1312 } 1287 }
1313 List<int> bytes; 1288 else {
1314 if (simple) { 1289 bytes.add(codeUnit);
1315 if (encoding == UTF8 || encoding == LATIN1) { 1290 }
1316 return text; 1291 }
1317 } else { 1292 }
1318 bytes = text.codeUnits; 1293 return encoding.decode(bytes);
1319 } 1294 }
1320 } else { 1295 static bool _isAlphabeticCharacter(int codeUnit) => (codeUnit >= _LOWER_CASE_A && codeUnit <= _LOWER_CASE_Z) || (codeUnit >= _UPPER_CASE_A && codeUnit <= _UPPE R_CASE_Z);
1321 bytes = ((__x62) => DDC$RT.cast(__x62, DDC$RT.type((List<dynamic> _) {}), 1296 static const _unreservedTable = const [0x0000, 0x0000, 0x6000, 0x03ff, 0xfffe, 0x87ff, 0xfffe, 0x47ff];
1322 DDC$RT.type((List<int> _) {}), "CastExact", 1297 static const _unreserved2396Table = const [0x0000, 0x0000, 0x6782, 0x03ff, 0xff fe, 0x87ff, 0xfffe, 0x47ff];
1323 """line 2138, column 15 of dart:core/uri.dart: """, 1298 static const _encodeFullTable = const [0x0000, 0x0000, 0xffda, 0xafff, 0xffff, 0x87ff, 0xfffe, 0x47ff];
1324 __x62 is List<int>, false))(new List()); 1299 static const _schemeTable = const [0x0000, 0x0000, 0x6800, 0x03ff, 0xfffe, 0x07 ff, 0xfffe, 0x07ff];
1325 for (int i = 0; i < text.length; i++) { 1300 static const _schemeLowerTable = const [0x0000, 0x0000, 0x6800, 0x03ff, 0x0000, 0x0000, 0xfffe, 0x07ff];
1326 var codeUnit = text.codeUnitAt(i); 1301 static const _subDelimitersTable = const [0x0000, 0x0000, 0x7fd2, 0x2bff, 0xfff e, 0x87ff, 0xfffe, 0x47ff];
1327 if (codeUnit > 127) { 1302 static const _genDelimitersTable = const [0x0000, 0x0000, 0x8008, 0x8400, 0x000 1, 0x2800, 0x0000, 0x0000];
1328 throw new ArgumentError("Illegal percent encoding in URI"); 1303 static const _userinfoTable = const [0x0000, 0x0000, 0x7fd2, 0x2fff, 0xfffe, 0x 87ff, 0xfffe, 0x47ff];
1329 } 1304 static const _regNameTable = const [0x0000, 0x0000, 0x7ff2, 0x2bff, 0xfffe, 0x8 7ff, 0xfffe, 0x47ff];
1330 if (codeUnit == _PERCENT) { 1305 static const _pathCharTable = const [0x0000, 0x0000, 0x7fd2, 0x2fff, 0xffff, 0x 87ff, 0xfffe, 0x47ff];
1331 if (i + 3 > text.length) { 1306 static const _pathCharOrSlashTable = const [0x0000, 0x0000, 0xffd2, 0x2fff, 0xf fff, 0x87ff, 0xfffe, 0x47ff];
1332 throw new ArgumentError('Truncated URI'); 1307 static const _queryCharTable = const [0x0000, 0x0000, 0xffd2, 0xafff, 0xffff, 0 x87ff, 0xfffe, 0x47ff];
1333 } 1308 }
1334 bytes.add(_hexCharPairToByte(text, i + 1));
1335 i += 2;
1336 } else if (plusToSpace && codeUnit == _PLUS) {
1337 bytes.add(_SPACE);
1338 } else {
1339 bytes.add(codeUnit);
1340 }
1341 }
1342 }
1343 return encoding.decode(bytes);
1344 }
1345 static bool _isAlphabeticCharacter(int codeUnit) =>
1346 (codeUnit >= _LOWER_CASE_A && codeUnit <= _LOWER_CASE_Z) ||
1347 (codeUnit >= _UPPER_CASE_A && codeUnit <= _UPPER_CASE_Z);
1348 static const _unreservedTable = const [
1349 0x0000,
1350 0x0000,
1351 0x6000,
1352 0x03ff,
1353 0xfffe,
1354 0x87ff,
1355 0xfffe,
1356 0x47ff
1357 ];
1358 static const _unreserved2396Table = const [
1359 0x0000,
1360 0x0000,
1361 0x6782,
1362 0x03ff,
1363 0xfffe,
1364 0x87ff,
1365 0xfffe,
1366 0x47ff
1367 ];
1368 static const _encodeFullTable = const [
1369 0x0000,
1370 0x0000,
1371 0xffda,
1372 0xafff,
1373 0xffff,
1374 0x87ff,
1375 0xfffe,
1376 0x47ff
1377 ];
1378 static const _schemeTable = const [
1379 0x0000,
1380 0x0000,
1381 0x6800,
1382 0x03ff,
1383 0xfffe,
1384 0x07ff,
1385 0xfffe,
1386 0x07ff
1387 ];
1388 static const _schemeLowerTable = const [
1389 0x0000,
1390 0x0000,
1391 0x6800,
1392 0x03ff,
1393 0x0000,
1394 0x0000,
1395 0xfffe,
1396 0x07ff
1397 ];
1398 static const _subDelimitersTable = const [
1399 0x0000,
1400 0x0000,
1401 0x7fd2,
1402 0x2bff,
1403 0xfffe,
1404 0x87ff,
1405 0xfffe,
1406 0x47ff
1407 ];
1408 static const _genDelimitersTable = const [
1409 0x0000,
1410 0x0000,
1411 0x8008,
1412 0x8400,
1413 0x0001,
1414 0x2800,
1415 0x0000,
1416 0x0000
1417 ];
1418 static const _userinfoTable = const [
1419 0x0000,
1420 0x0000,
1421 0x7fd2,
1422 0x2fff,
1423 0xfffe,
1424 0x87ff,
1425 0xfffe,
1426 0x47ff
1427 ];
1428 static const _regNameTable = const [
1429 0x0000,
1430 0x0000,
1431 0x7ff2,
1432 0x2bff,
1433 0xfffe,
1434 0x87ff,
1435 0xfffe,
1436 0x47ff
1437 ];
1438 static const _pathCharTable = const [
1439 0x0000,
1440 0x0000,
1441 0x7fd2,
1442 0x2fff,
1443 0xffff,
1444 0x87ff,
1445 0xfffe,
1446 0x47ff
1447 ];
1448 static const _pathCharOrSlashTable = const [
1449 0x0000,
1450 0x0000,
1451 0xffd2,
1452 0x2fff,
1453 0xffff,
1454 0x87ff,
1455 0xfffe,
1456 0x47ff
1457 ];
1458 static const _queryCharTable = const [
1459 0x0000,
1460 0x0000,
1461 0xffd2,
1462 0xafff,
1463 0xffff,
1464 0x87ff,
1465 0xfffe,
1466 0x47ff
1467 ];
1468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698