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

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

Issue 959073002: Fix new line breaks on } (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
« no previous file with comments | « test/dart_codegen/expect/core/list.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of dart.core; 1 part of dart.core;
2 class Uri {final String _host; 2 class Uri {final String _host;
3 num _port; 3 num _port;
4 String _path; 4 String _path;
5 final String scheme; 5 final String scheme;
6 String get authority { 6 String get authority {
7 if (!hasAuthority) return ""; 7 if (!hasAuthority) return "";
8 var sb = new StringBuffer(); 8 var sb = new StringBuffer();
9 _writeAuthority(sb); 9 _writeAuthority(sb);
10 return sb.toString(); 10 return sb.toString();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 int hostStart = authStart; 87 int hostStart = authStart;
88 int hostEnd = index; 88 int hostEnd = index;
89 if (lastAt >= 0) { 89 if (lastAt >= 0) {
90 userinfo = _makeUserInfo(uri, authStart, lastAt); 90 userinfo = _makeUserInfo(uri, authStart, lastAt);
91 hostStart = lastAt + 1; 91 hostStart = lastAt + 1;
92 } 92 }
93 if (lastColon >= 0) { 93 if (lastColon >= 0) {
94 int portNumber; 94 int portNumber;
95 if (lastColon + 1 < index) { 95 if (lastColon + 1 < index) {
96 portNumber = 0; 96 portNumber = 0;
97 for (int i = lastColon + 1; 97 for (int i = lastColon + 1; i < index; i++) {
98 i < index;
99 i++) {
100 int digit = uri.codeUnitAt(i); 98 int digit = uri.codeUnitAt(i);
101 if (_ZERO > digit || _NINE < digit) { 99 if (_ZERO > digit || _NINE < digit) {
102 _fail(uri, i, "Invalid port number"); 100 _fail(uri, i, "Invalid port number");
103 } 101 }
104 portNumber = portNumber * 10 + (digit - _ZERO); 102 portNumber = portNumber * 10 + (digit - _ZERO);
105 } 103 }
106 } 104 }
107 port = _makePort(portNumber, scheme); 105 port = _makePort(portNumber, scheme);
108 hostEnd = lastColon; 106 hostEnd = lastColon;
109 } 107 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 factory Uri.https(String authority, String unencodedPath, [Map<String, String> queryParameters]) { 229 factory Uri.https(String authority, String unencodedPath, [Map<String, String> queryParameters]) {
232 return _makeHttpUri("https", authority, unencodedPath, queryParameters); 230 return _makeHttpUri("https", authority, unencodedPath, queryParameters);
233 } 231 }
234 static Uri _makeHttpUri(String scheme, String authority, String unencodedPath, Map<String, String> queryParameters) { 232 static Uri _makeHttpUri(String scheme, String authority, String unencodedPath, Map<String, String> queryParameters) {
235 var userInfo = ""; 233 var userInfo = "";
236 var host = null; 234 var host = null;
237 var port = null; 235 var port = null;
238 if (authority != null && authority.isNotEmpty) { 236 if (authority != null && authority.isNotEmpty) {
239 var hostStart = 0; 237 var hostStart = 0;
240 bool hasUserInfo = false; 238 bool hasUserInfo = false;
241 for (int i = 0; 239 for (int i = 0; i < authority.length; i++) {
242 i < authority.length;
243 i++) {
244 if (authority.codeUnitAt(i) == _AT_SIGN) { 240 if (authority.codeUnitAt(i) == _AT_SIGN) {
245 hasUserInfo = true; 241 hasUserInfo = true;
246 userInfo = authority.substring(0, i); 242 userInfo = authority.substring(0, i);
247 hostStart = i + 1; 243 hostStart = i + 1;
248 break; 244 break;
249 } 245 }
250 } 246 }
251 var hostEnd = hostStart; 247 var hostEnd = hostStart;
252 if (hostStart < authority.length && authority.codeUnitAt(hostStart) == _LEF T_BRACKET) { 248 if (hostStart < authority.length && authority.codeUnitAt(hostStart) == _LEF T_BRACKET) {
253 for (; 249 for (; hostEnd < authority.length; hostEnd++) {
254 hostEnd < authority.length;
255 hostEnd++) {
256 if (authority.codeUnitAt(hostEnd) == _RIGHT_BRACKET) break; 250 if (authority.codeUnitAt(hostEnd) == _RIGHT_BRACKET) break;
257 } 251 }
258 if (hostEnd == authority.length) { 252 if (hostEnd == authority.length) {
259 throw new FormatException("Invalid IPv6 host entry.", authority, hostSta rt); 253 throw new FormatException("Invalid IPv6 host entry.", authority, hostSta rt);
260 } 254 }
261 parseIPv6Address(authority, hostStart + 1, hostEnd); 255 parseIPv6Address(authority, hostStart + 1, hostEnd);
262 hostEnd++; 256 hostEnd++;
263 if (hostEnd != authority.length && authority.codeUnitAt(hostEnd) != _COLO N) { 257 if (hostEnd != authority.length && authority.codeUnitAt(hostEnd) != _COLO N) {
264 throw new FormatException("Invalid end of authority", authority, hostEnd ); 258 throw new FormatException("Invalid end of authority", authority, hostEnd );
265 } 259 }
266 } 260 }
267 bool hasPort = false; 261 bool hasPort = false;
268 for (; 262 for (; hostEnd < authority.length; hostEnd++) {
269 hostEnd < authority.length;
270 hostEnd++) {
271 if (authority.codeUnitAt(hostEnd) == _COLON) { 263 if (authority.codeUnitAt(hostEnd) == _COLON) {
272 var portString = authority.substring(hostEnd + 1); 264 var portString = authority.substring(hostEnd + 1);
273 if (portString.isNotEmpty) port = int.parse(portString); 265 if (portString.isNotEmpty) port = int.parse(portString);
274 break; 266 break;
275 } 267 }
276 } 268 }
277 host = authority.substring(hostStart, hostEnd); 269 host = authority.substring(hostStart, hostEnd);
278 } 270 }
279 return new Uri(scheme: scheme, userInfo: userInfo, host: host, port: port, pa thSegments: unencodedPath.split("/"), queryParameters: queryParameters); 271 return new Uri(scheme: scheme, userInfo: userInfo, host: host, port: port, pa thSegments: unencodedPath.split("/"), queryParameters: queryParameters);
280 } 272 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (path.startsWith(sep)) { 319 if (path.startsWith(sep)) {
328 return new Uri(scheme: "file", pathSegments: path.split(sep)); 320 return new Uri(scheme: "file", pathSegments: path.split(sep));
329 } 321 }
330 else { 322 else {
331 return new Uri(pathSegments: path.split(sep)); 323 return new Uri(pathSegments: path.split(sep));
332 } 324 }
333 } 325 }
334 static _makeWindowsFileUrl(String path) { 326 static _makeWindowsFileUrl(String path) {
335 if (path.startsWith("\\\\?\\")) { 327 if (path.startsWith("\\\\?\\")) {
336 if (path.startsWith("\\\\?\\UNC\\")) { 328 if (path.startsWith("\\\\?\\UNC\\")) {
337 path = "\\${path.substring(7)} 329 path = "\\${path.substring(7)}";
338 "; 330 }
339 } 331 else {
340 else { 332 path = path.substring(4);
341 path = path.substring(4); 333 if (path.length < 3 || path.codeUnitAt(1) != _COLON || path.codeUnitAt(2) != _BACKSLASH) {
342 if (path.length < 3 || path.codeUnitAt(1) != _COLON || path.codeUnitAt(2) ! = _BACKSLASH) { 334 throw new ArgumentError("Windows paths with \\\\?\\ prefix must be absol ute");
343 throw new ArgumentError("Windows paths with \\\\?\\ prefix must be absolut e"); 335 }
344 } 336 }
345 } 337 }
346 } 338 else {
347 else { 339 path = path.replaceAll("/", "\\");
348 path = path.replaceAll("/", "\\"); 340 }
349 } 341 String sep = "\\";
350 String sep = "\\"; 342 if (path.length > 1 && path[1] == ":") {
351 if (path.length > 1 && path[1] == ":") { 343 _checkWindowsDriveLetter(path.codeUnitAt(0), true);
352 _checkWindowsDriveLetter(path.codeUnitAt(0), true); 344 if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) {
353 if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) { 345 throw new ArgumentError("Windows paths with drive letter must be absolute" );
354 throw new ArgumentError("Windows paths with drive letter must be absolute"); 346 }
355 } 347 var pathSegments = path.split(sep);
356 var pathSegments = path.split(sep); 348 _checkWindowsPathReservedCharacters(pathSegments, true, 1);
357 _checkWindowsPathReservedCharacters(pathSegments, true, 1); 349 return new Uri(scheme: "file", pathSegments: pathSegments);
358 return new Uri(scheme: "file", pathSegments: pathSegments); 350 }
359 } 351 if (path.length > 0 && path[0] == sep) {
360 if (path.length > 0 && path[0] == sep) { 352 if (path.length > 1 && path[1] == sep) {
361 if (path.length > 1 && path[1] == sep) { 353 int pathStart = path.indexOf("\\", 2);
362 int pathStart = path.indexOf("\\", 2); 354 String hostPart = pathStart == -1 ? path.substring(2) : path.substring(2, pathStart);
363 String hostPart = pathStart == -1 ? path.substring(2) : path.substring(2, p athStart); 355 String pathPart = pathStart == -1 ? "" : path.substring(pathStart + 1);
364 String pathPart = pathStart == -1 ? "" : path.substring(pathStart + 1); 356 var pathSegments = pathPart.split(sep);
365 var pathSegments = pathPart.split(sep); 357 _checkWindowsPathReservedCharacters(pathSegments, true);
366 _checkWindowsPathReservedCharacters(pathSegments, true); 358 return new Uri(scheme: "file", host: hostPart, pathSegments: pathSegments );
367 return new Uri(scheme: "file", host: hostPart, pathSegments: pathSegments); 359 }
360 else {
361 var pathSegments = path.split(sep);
362 _checkWindowsPathReservedCharacters(pathSegments, true);
363 return new Uri(scheme: "file", pathSegments: pathSegments);
364 }
368 } 365 }
369 else { 366 else {
370 var pathSegments = path.split(sep); 367 var pathSegments = path.split(sep);
371 _checkWindowsPathReservedCharacters(pathSegments, true); 368 _checkWindowsPathReservedCharacters(pathSegments, true);
372 return new Uri(scheme: "file", pathSegments: pathSegments); 369 return new Uri(pathSegments: pathSegments);
373 } 370 }
374 } 371 }
375 else {
376 var pathSegments = path.split(sep);
377 _checkWindowsPathReservedCharacters(pathSegments, true);
378 return new Uri(pathSegments: pathSegments);
379 }
380 }
381 Uri replace({ 372 Uri replace({
382 String scheme, String userInfo, String host, int port, String path, Iterable<Str ing> pathSegments, String query, Map<String, String> queryParameters, String fra gment} 373 String scheme, String userInfo, String host, int port, String path, Iterable<S tring> pathSegments, String query, Map<String, String> queryParameters, String f ragment}
383 ) { 374 ) {
384 bool schemeChanged = false; 375 bool schemeChanged = false;
385 if (scheme != null) { 376 if (scheme != null) {
386 scheme = _makeScheme(scheme, scheme.length); 377 scheme = _makeScheme(scheme, scheme.length);
387 schemeChanged = true; 378 schemeChanged = true;
388 } 379 }
389 else { 380 else {
390 scheme = this.scheme; 381 scheme = this.scheme;
391 } 382 }
392 bool isFile = (scheme == "file"); 383 bool isFile = (scheme == "file");
393 if (userInfo != null) { 384 if (userInfo != null) {
394 userInfo = _makeUserInfo(userInfo, 0, userInfo.length); 385 userInfo = _makeUserInfo(userInfo, 0, userInfo.length);
395 } 386 }
396 else { 387 else {
397 userInfo = this.userInfo; 388 userInfo = this.userInfo;
398 } 389 }
399 if (port != null) { 390 if (port != null) {
400 port = _makePort(port, scheme);
401 }
402 else {
403 port = ((__x11) => DDC$RT.cast(__x11, num, int, "CastGeneral", """line 889, co lumn 14 of dart:core/uri.dart: """, __x11 is int, true))(this._port);
404 if (schemeChanged) {
405 port = _makePort(port, scheme); 391 port = _makePort(port, scheme);
406 } 392 }
407 } 393 else {
408 if (host != null) { 394 port = ((__x11) => DDC$RT.cast(__x11, num, int, "CastGeneral", """line 889, column 14 of dart:core/uri.dart: """, __x11 is int, true))(this._port);
409 host = _makeHost(host, 0, host.length, false); 395 if (schemeChanged) {
410 } 396 port = _makePort(port, scheme);
411 else if (this.hasAuthority) { 397 }
412 host = this.host; 398 }
413 } 399 if (host != null) {
414 else if (userInfo.isNotEmpty || port != null || isFile) { 400 host = _makeHost(host, 0, host.length, false);
415 host = ""; 401 }
416 } 402 else if (this.hasAuthority) {
417 bool ensureLeadingSlash = (host != null); 403 host = this.host;
418 if (path != null || pathSegments != null) { 404 }
419 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, ensureLeadi ngSlash, isFile); 405 else if (userInfo.isNotEmpty || port != null || isFile) {
420 } 406 host = "";
421 else { 407 }
422 path = this.path; 408 bool ensureLeadingSlash = (host != null);
423 if ((isFile || (ensureLeadingSlash && !path.isEmpty)) && !path.startsWith('/' )) { 409 if (path != null || pathSegments != null) {
424 path = "/$path"; 410 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, ensureLea dingSlash, isFile);
425 } 411 }
426 } 412 else {
427 if (query != null || queryParameters != null) { 413 path = this.path;
428 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters); 414 if ((isFile || (ensureLeadingSlash && !path.isEmpty)) && !path.startsWith(' /')) {
429 } 415 path = "/$path";
430 else if (this.hasQuery) { 416 }
431 query = this.query; 417 }
432 } 418 if (query != null || queryParameters != null) {
433 if (fragment != null) { 419 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters);
434 fragment = _makeFragment(fragment, 0, fragment.length); 420 }
435 } 421 else if (this.hasQuery) {
436 else if (this.hasFragment) { 422 query = this.query;
437 fragment = this.fragment; 423 }
438 } 424 if (fragment != null) {
439 return new Uri._internal(scheme, userInfo, host, port, path, query, fragment); 425 fragment = _makeFragment(fragment, 0, fragment.length);
440 } 426 }
427 else if (this.hasFragment) {
428 fragment = this.fragment;
429 }
430 return new Uri._internal(scheme, userInfo, host, port, path, query, fragment) ;
431 }
441 List<String> get pathSegments { 432 List<String> get pathSegments {
442 if (_pathSegments == null) { 433 if (_pathSegments == null) {
443 var pathToSplit = !path.isEmpty && path.codeUnitAt(0) == _SLASH ? path.substri ng(1) : path; 434 var pathToSplit = !path.isEmpty && path.codeUnitAt(0) == _SLASH ? path.subst ring(1) : path;
444 _pathSegments = ((__x12) => DDC$RT.cast(__x12, DDC$RT.type((DDC$collection$.U nmodifiableListView<dynamic> _) { 435 _pathSegments = ((__x12) => DDC$RT.cast(__x12, DDC$RT.type((DDC$collection$ .UnmodifiableListView<dynamic> _) {
445 } 436 }
446 ), DDC$RT.type((List<String> _) { 437 ), DDC$RT.type((List<String> _) {
447 } 438 }
448 ), "CastExact", """line 945, column 23 of dart:core/uri.dart: """, __x12 is Li st<String>, false))(new UnmodifiableListView(pathToSplit == "" ? const <String> [] : pathToSplit.split("/").map(Uri.decodeComponent).toList(growable: false))); 439 ), "CastExact", """line 945, column 23 of dart:core/uri.dart: """, __x12 is List<String>, false))(new UnmodifiableListView(pathToSplit == "" ? const <String > [] : pathToSplit.split("/").map(Uri.decodeComponent).toList(growable: false))) ;
449 } 440 }
450 return _pathSegments; 441 return _pathSegments;
451 } 442 }
452 Map<String, String> get queryParameters { 443 Map<String, String> get queryParameters {
453 if (_queryParameters == null) { 444 if (_queryParameters == null) {
454 _queryParameters = ((__x13) => DDC$RT.cast(__x13, DDC$RT.type((DDC$collection$ .UnmodifiableMapView<dynamic, dynamic> _) { 445 _queryParameters = ((__x13) => DDC$RT.cast(__x13, DDC$RT.type((DDC$collectio n$.UnmodifiableMapView<dynamic, dynamic> _) {
455 } 446 }
456 ), DDC$RT.type((Map<String, String> _) { 447 ), DDC$RT.type((Map<String, String> _) {
457 } 448 }
458 ), "CastExact", """line 969, column 26 of dart:core/uri.dart: """, __x13 is Ma p<String, String>, false))(new UnmodifiableMapView(splitQueryString(query))); 449 ), "CastExact", """line 969, column 26 of dart:core/uri.dart: """, __x13 is Map<String, String>, false))(new UnmodifiableMapView(splitQueryString(query)));
459 } 450 }
460 return _queryParameters; 451 return _queryParameters;
461 } 452 }
462 static int _makePort(int port, String scheme) { 453 static int _makePort(int port, String scheme) {
463 if (port != null && port == _defaultPort(scheme)) return ((__x14) => DDC$RT.cast (__x14, Null, int, "CastLiteral", """line 976, column 62 of dart:core/uri.dart: """, __x14 is int, true))(null); 454 if (port != null && port == _defaultPort(scheme)) return ((__x14) => DDC$RT.ca st(__x14, Null, int, "CastLiteral", """line 976, column 62 of dart:core/uri.dart : """, __x14 is int, true))(null);
464 return port; 455 return port;
465 } 456 }
466 static String _makeHost(String host, int start, int end, bool strictIPv6) { 457 static String _makeHost(String host, int start, int end, bool strictIPv6) {
467 if (host == null) return null; 458 if (host == null) return null;
468 if (start == end) return ""; 459 if (start == end) return "";
469 if (host.codeUnitAt(start) == _LEFT_BRACKET) { 460 if (host.codeUnitAt(start) == _LEFT_BRACKET) {
470 if (host.codeUnitAt(end - 1) != _RIGHT_BRACKET) { 461 if (host.codeUnitAt(end - 1) != _RIGHT_BRACKET) {
471 _fail(host, start, 'Missing end `]` to match `[` in host'); 462 _fail(host, start, 'Missing end `]` to match `[` in host');
472 } 463 }
473 parseIPv6Address(host, start + 1, end - 1); 464 parseIPv6Address(host, start + 1, end - 1);
474 return host.substring(start, end).toLowerCase(); 465 return host.substring(start, end).toLowerCase();
475 } 466 }
476 if (!strictIPv6) { 467 if (!strictIPv6) {
477 for (int i = start; 468 for (int i = start; i < end; i++) {
478 i < end; 469 if (host.codeUnitAt(i) == _COLON) {
479 i++) { 470 parseIPv6Address(host, start, end);
480 if (host.codeUnitAt(i) == _COLON) { 471 return '[$host]';
481 parseIPv6Address(host, start, end); 472 }
482 return '[$host]'; 473 }
483 } 474 }
484 } 475 return _normalizeRegName(host, start, end);
485 } 476 }
486 return _normalizeRegName(host, start, end);
487 }
488 static bool _isRegNameChar(int char) { 477 static bool _isRegNameChar(int char) {
489 return char < 127 && (_regNameTable[char >> 4] & (1 << (char & 0xf))) != 0; 478 return char < 127 && (_regNameTable[char >> 4] & (1 << (char & 0xf))) != 0;
490 } 479 }
491 static String _normalizeRegName(String host, int start, int end) { 480 static String _normalizeRegName(String host, int start, int end) {
492 StringBuffer buffer; 481 StringBuffer buffer;
493 int sectionStart = start; 482 int sectionStart = start;
494 int index = start; 483 int index = start;
495 bool isNormalized = true; 484 bool isNormalized = true;
496 while (index < end) { 485 while (index < end) {
497 int char = host.codeUnitAt(index); 486 int char = host.codeUnitAt(index);
498 if (char == _PERCENT) { 487 if (char == _PERCENT) {
499 String replacement = _normalizeEscape(host, index, true); 488 String replacement = _normalizeEscape(host, index, true);
500 if (replacement == null && isNormalized) { 489 if (replacement == null && isNormalized) {
501 index += 3; 490 index += 3;
502 continue; 491 continue;
503 } 492 }
504 if (buffer == null) buffer = new StringBuffer(); 493 if (buffer == null) buffer = new StringBuffer();
505 String slice = host.substring(sectionStart, index); 494 String slice = host.substring(sectionStart, index);
495 if (!isNormalized) slice = slice.toLowerCase();
496 buffer.write(slice);
497 int sourceLength = 3;
498 if (replacement == null) {
499 replacement = host.substring(index, index + 3);
500 }
501 else if (replacement == "%") {
502 replacement = "%25";
503 sourceLength = 1;
504 }
505 buffer.write(replacement);
506 index += sourceLength;
507 sectionStart = index;
508 isNormalized = true;
509 }
510 else if (_isRegNameChar(char)) {
511 if (isNormalized && _UPPER_CASE_A <= char && _UPPER_CASE_Z >= char) {
512 if (buffer == null) buffer = new StringBuffer();
513 if (sectionStart < index) {
514 buffer.write(host.substring(sectionStart, index));
515 sectionStart = index;
516 }
517 isNormalized = false;
518 }
519 index++;
520 }
521 else if (_isGeneralDelimiter(char)) {
522 _fail(host, index, "Invalid character");
523 }
524 else {
525 int sourceLength = 1;
526 if ((char & 0xFC00) == 0xD800 && (index + 1) < end) {
527 int tail = host.codeUnitAt(index + 1);
528 if ((tail & 0xFC00) == 0xDC00) {
529 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
530 sourceLength = 2;
531 }
532 }
533 if (buffer == null) buffer = new StringBuffer();
534 String slice = host.substring(sectionStart, index);
535 if (!isNormalized) slice = slice.toLowerCase();
536 buffer.write(slice);
537 buffer.write(_escapeChar(char));
538 index += sourceLength;
539 sectionStart = index;
540 }
541 }
542 if (buffer == null) return host.substring(start, end);
543 if (sectionStart < end) {
544 String slice = host.substring(sectionStart, end);
506 if (!isNormalized) slice = slice.toLowerCase(); 545 if (!isNormalized) slice = slice.toLowerCase();
507 buffer.write(slice); 546 buffer.write(slice);
508 int sourceLength = 3; 547 }
509 if (replacement == null) { 548 return buffer.toString();
510 replacement = host.substring(index, index + 3); 549 }
511 }
512 else if (replacement == "%") {
513 replacement = "%25";
514 sourceLength = 1;
515 }
516 buffer.write(replacement);
517 index += sourceLength;
518 sectionStart = index;
519 isNormalized = true;
520 }
521 else if (_isRegNameChar(char)) {
522 if (isNormalized && _UPPER_CASE_A <= char && _UPPER_CASE_Z >= char) {
523 if (buffer == null) buffer = new StringBuffer();
524 if (sectionStart < index) {
525 buffer.write(host.substring(sectionStart, index));
526 sectionStart = index;
527 }
528 isNormalized = false;
529 }
530 index++;
531 }
532 else if (_isGeneralDelimiter(char)) {
533 _fail(host, index, "Invalid character");
534 }
535 else {
536 int sourceLength = 1;
537 if ((char & 0xFC00) == 0xD800 && (index + 1) < end) {
538 int tail = host.codeUnitAt(index + 1);
539 if ((tail & 0xFC00) == 0xDC00) {
540 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
541 sourceLength = 2;
542 }
543 }
544 if (buffer == null) buffer = new StringBuffer();
545 String slice = host.substring(sectionStart, index);
546 if (!isNormalized) slice = slice.toLowerCase();
547 buffer.write(slice);
548 buffer.write(_escapeChar(char));
549 index += sourceLength;
550 sectionStart = index;
551 }
552 }
553 if (buffer == null) return host.substring(start, end);
554 if (sectionStart < end) {
555 String slice = host.substring(sectionStart, end);
556 if (!isNormalized) slice = slice.toLowerCase();
557 buffer.write(slice);
558 }
559 return buffer.toString();
560 }
561 static String _makeScheme(String scheme, int end) { 550 static String _makeScheme(String scheme, int end) {
562 if (end == 0) return ""; 551 if (end == 0) return "";
563 final int firstCodeUnit = scheme.codeUnitAt(0); 552 final int firstCodeUnit = scheme.codeUnitAt(0);
564 if (!_isAlphabeticCharacter(firstCodeUnit)) { 553 if (!_isAlphabeticCharacter(firstCodeUnit)) {
565 _fail(scheme, 0, "Scheme not starting with alphabetic character"); 554 _fail(scheme, 0, "Scheme not starting with alphabetic character");
566 } 555 }
567 bool allLowercase = firstCodeUnit >= _LOWER_CASE_A; 556 bool allLowercase = firstCodeUnit >= _LOWER_CASE_A;
568 for (int i = 0; 557 for (int i = 0; i < end; i++) {
569 i < end; 558 final int codeUnit = scheme.codeUnitAt(i);
570 i++) { 559 if (!_isSchemeCharacter(codeUnit)) {
571 final int codeUnit = scheme.codeUnitAt(i); 560 _fail(scheme, i, "Illegal scheme character");
572 if (!_isSchemeCharacter(codeUnit)) { 561 }
573 _fail(scheme, i, "Illegal scheme character"); 562 if (codeUnit < _LOWER_CASE_A || codeUnit > _LOWER_CASE_Z) {
574 } 563 allLowercase = false;
575 if (codeUnit < _LOWER_CASE_A || codeUnit > _LOWER_CASE_Z) { 564 }
576 allLowercase = false; 565 }
577 } 566 scheme = scheme.substring(0, end);
578 } 567 if (!allLowercase) scheme = scheme.toLowerCase();
579 scheme = scheme.substring(0, end); 568 return scheme;
580 if (!allLowercase) scheme = scheme.toLowerCase(); 569 }
581 return scheme;
582 }
583 static String _makeUserInfo(String userInfo, int start, int end) { 570 static String _makeUserInfo(String userInfo, int start, int end) {
584 if (userInfo == null) return ""; 571 if (userInfo == null) return "";
585 return _normalize(userInfo, start, end, DDC$RT.cast(_userinfoTable, dynamic, DD C$RT.type((List<int> _) { 572 return _normalize(userInfo, start, end, DDC$RT.cast(_userinfoTable, dynamic, DDC$RT.type((List<int> _) {
586 } 573 }
587 ), "CastGeneral", """line 1126, column 45 of dart:core/uri.dart: """, _userinfoT able is List<int>, false)); 574 ), "CastGeneral", """line 1126, column 45 of dart:core/uri.dart: """, _userinf oTable is List<int>, false));
588 } 575 }
589 static String _makePath(String path, int start, int end, Iterable<String> pathS egments, bool ensureLeadingSlash, bool isFile) { 576 static String _makePath(String path, int start, int end, Iterable<String> pathS egments, bool ensureLeadingSlash, bool isFile) {
590 if (path == null && pathSegments == null) return isFile ? "/" : ""; 577 if (path == null && pathSegments == null) return isFile ? "/" : "";
591 if (path != null && pathSegments != null) { 578 if (path != null && pathSegments != null) {
592 throw new ArgumentError('Both path and pathSegments specified'); 579 throw new ArgumentError('Both path and pathSegments specified');
593 } 580 }
594 var result; 581 var result;
595 if (path != null) { 582 if (path != null) {
596 result = _normalize(path, start, end, DDC$RT.cast(_pathCharOrSlashTable, dynam ic, DDC$RT.type((List<int> _) { 583 result = _normalize(path, start, end, DDC$RT.cast(_pathCharOrSlashTable, dyn amic, DDC$RT.type((List<int> _) {
597 } 584 }
598 ), "CastGeneral", """line 1139, column 45 of dart:core/uri.dart: """, _pathCha rOrSlashTable is List<int>, false)); 585 ), "CastGeneral", """line 1139, column 45 of dart:core/uri.dart: """, _pathC harOrSlashTable is List<int>, false));
599 } 586 }
600 else { 587 else {
601 result = pathSegments.map((s) => _uriEncode(DDC$RT.cast(_pathCharTable, dynami c, DDC$RT.type((List<int> _) { 588 result = pathSegments.map((s) => _uriEncode(DDC$RT.cast(_pathCharTable, dyna mic, DDC$RT.type((List<int> _) {
602 } 589 }
603 ), "CastGeneral", """line 1141, column 51 of dart:core/uri.dart: """, _pathCha rTable is List<int>, false), DDC$RT.cast(s, dynamic, String, "CastGeneral", """l ine 1141, column 67 of dart:core/uri.dart: """, s is String, true))).join("/"); 590 ), "CastGeneral", """line 1141, column 51 of dart:core/uri.dart: """, _pathC harTable is List<int>, false), DDC$RT.cast(s, dynamic, String, "CastGeneral", "" "line 1141, column 67 of dart:core/uri.dart: """, s is String, true))).join("/") ;
604 } 591 }
605 if (result.isEmpty) { 592 if (result.isEmpty) {
606 if (isFile) return "/"; 593 if (isFile) return "/";
607 } 594 }
608 else if ((isFile || ensureLeadingSlash) && result.codeUnitAt(0) != _SLASH) { 595 else if ((isFile || ensureLeadingSlash) && result.codeUnitAt(0) != _SLASH) {
609 return "/$result"; 596 return "/$result";
610 } 597 }
611 return DDC$RT.cast(result, dynamic, String, "CastGeneral", """line 1149, column 12 of dart:core/uri.dart: """, result is String, true); 598 return DDC$RT.cast(result, dynamic, String, "CastGeneral", """line 1149, colu mn 12 of dart:core/uri.dart: """, result is String, true);
612 } 599 }
613 static String _makeQuery(String query, int start, int end, Map<String, String> queryParameters) { 600 static String _makeQuery(String query, int start, int end, Map<String, String> queryParameters) {
614 if (query == null && queryParameters == null) return null; 601 if (query == null && queryParameters == null) return null;
615 if (query != null && queryParameters != null) { 602 if (query != null && queryParameters != null) {
616 throw new ArgumentError('Both query and queryParameters specified'); 603 throw new ArgumentError('Both query and queryParameters specified');
617 } 604 }
618 if (query != null) return _normalize(query, start, end, DDC$RT.cast(_queryCharT able, dynamic, DDC$RT.type((List<int> _) { 605 if (query != null) return _normalize(query, start, end, DDC$RT.cast(_queryCha rTable, dynamic, DDC$RT.type((List<int> _) {
619 } 606 }
620 ), "CastGeneral", """line 1158, column 61 of dart:core/uri.dart: """, _queryChar Table is List<int>, false)); 607 ), "CastGeneral", """line 1158, column 61 of dart:core/uri.dart: """, _queryCh arTable is List<int>, false));
621 var result = new StringBuffer(); 608 var result = new StringBuffer();
622 var first = true; 609 var first = true;
623 queryParameters.forEach((key, value) { 610 queryParameters.forEach((key, value) {
624 if (!first) { 611 if (!first) {
625 result.write("&"); 612 result.write("&");
626 } 613 }
627 first = false; 614 first = false;
628 result.write(Uri.encodeQueryComponent(DDC$RT.cast(key, dynamic, String, "Cast General", """line 1167, column 45 of dart:core/uri.dart: """, key is String, tru e))); 615 result.write(Uri.encodeQueryComponent(DDC$RT.cast(key, dynamic, String, "Ca stGeneral", """line 1167, column 45 of dart:core/uri.dart: """, key is String, t rue)));
629 if (value != null && !value.isEmpty) { 616 if (value != null && !value.isEmpty) {
630 result.write("="); 617 result.write("=");
631 result.write(Uri.encodeQueryComponent(DDC$RT.cast(value, dynamic, String, " CastGeneral", """line 1170, column 47 of dart:core/uri.dart: """, value is Strin g, true))); 618 result.write(Uri.encodeQueryComponent(DDC$RT.cast(value, dynamic, String, "CastGeneral", """line 1170, column 47 of dart:core/uri.dart: """, value is Str ing, true)));
632 } 619 }
633 } 620 }
634 ); 621 );
635 return result.toString(); 622 return result.toString();
636 } 623 }
637 static String _makeFragment(String fragment, int start, int end) { 624 static String _makeFragment(String fragment, int start, int end) {
638 if (fragment == null) return null; 625 if (fragment == null) return null;
639 return _normalize(fragment, start, end, DDC$RT.cast(_queryCharTable, dynamic, D DC$RT.type((List<int> _) { 626 return _normalize(fragment, start, end, DDC$RT.cast(_queryCharTable, dynamic, DDC$RT.type((List<int> _) {
640 } 627 }
641 ), "CastGeneral", """line 1178, column 45 of dart:core/uri.dart: """, _queryChar Table is List<int>, false)); 628 ), "CastGeneral", """line 1178, column 45 of dart:core/uri.dart: """, _queryCh arTable is List<int>, false));
642 } 629 }
643 static int _stringOrNullLength(String s) => (s == null) ? 0 : s.length; 630 static int _stringOrNullLength(String s) => (s == null) ? 0 : s.length;
644 static bool _isHexDigit(int char) { 631 static bool _isHexDigit(int char) {
645 if (_NINE >= char) return _ZERO <= char; 632 if (_NINE >= char) return _ZERO <= char;
646 char |= 0x20; 633 char |= 0x20;
647 return _LOWER_CASE_A <= char && _LOWER_CASE_F >= char; 634 return _LOWER_CASE_A <= char && _LOWER_CASE_F >= char;
648 } 635 }
649 static int _hexValue(int char) { 636 static int _hexValue(int char) {
650 assert (_isHexDigit(char)); if (_NINE >= char) return char - _ZERO; 637 assert (_isHexDigit(char)); if (_NINE >= char) return char - _ZERO;
651 char |= 0x20; 638 char |= 0x20;
652 return char - (_LOWER_CASE_A - 10); 639 return char - (_LOWER_CASE_A - 10);
653 } 640 }
654 static String _normalizeEscape(String source, int index, bool lowerCase) { 641 static String _normalizeEscape(String source, int index, bool lowerCase) {
655 assert (source.codeUnitAt(index) == _PERCENT); if (index + 2 >= source.length) { 642 assert (source.codeUnitAt(index) == _PERCENT); if (index + 2 >= source.length) {
656 return "%"; 643 return "%";
657 } 644 }
658 int firstDigit = source.codeUnitAt(index + 1); 645 int firstDigit = source.codeUnitAt(index + 1);
659 int secondDigit = source.codeUnitAt(index + 2); 646 int secondDigit = source.codeUnitAt(index + 2);
660 if (!_isHexDigit(firstDigit) || !_isHexDigit(secondDigit)) { 647 if (!_isHexDigit(firstDigit) || !_isHexDigit(secondDigit)) {
661 return "%"; 648 return "%";
662 } 649 }
663 int value = _hexValue(firstDigit) * 16 + _hexValue(secondDigit); 650 int value = _hexValue(firstDigit) * 16 + _hexValue(secondDigit);
664 if (_isUnreservedChar(value)) { 651 if (_isUnreservedChar(value)) {
665 if (lowerCase && _UPPER_CASE_A <= value && _UPPER_CASE_Z >= value) { 652 if (lowerCase && _UPPER_CASE_A <= value && _UPPER_CASE_Z >= value) {
666 value |= 0x20; 653 value |= 0x20;
667 } 654 }
668 return new String.fromCharCode(value); 655 return new String.fromCharCode(value);
669 } 656 }
670 if (firstDigit >= _LOWER_CASE_A || secondDigit >= _LOWER_CASE_A) { 657 if (firstDigit >= _LOWER_CASE_A || secondDigit >= _LOWER_CASE_A) {
671 return source.substring(index, index + 3).toUpperCase(); 658 return source.substring(index, index + 3).toUpperCase();
672 } 659 }
673 return null; 660 return null;
674 } 661 }
675 static bool _isUnreservedChar(int ch) { 662 static bool _isUnreservedChar(int ch) {
676 return ch < 127 && ((_unreservedTable[ch >> 4] & (1 << (ch & 0x0f))) != 0); 663 return ch < 127 && ((_unreservedTable[ch >> 4] & (1 << (ch & 0x0f))) != 0);
677 } 664 }
678 static String _escapeChar(char) { 665 static String _escapeChar(char) {
679 assert (char <= 0x10ffff); const hexDigits = "0123456789ABCDEF"; 666 assert (char <= 0x10ffff); const hexDigits = "0123456789ABCDEF";
680 List codeUnits; 667 List codeUnits;
681 if (char < 0x80) { 668 if (char < 0x80) {
682 codeUnits = new List(3); 669 codeUnits = new List(3);
683 codeUnits[0] = _PERCENT; 670 codeUnits[0] = _PERCENT;
684 codeUnits[1] = hexDigits.codeUnitAt(((__x15) => DDC$RT.cast(__x15, dynamic, i nt, "CastGeneral", """line 1248, column 43 of dart:core/uri.dart: """, __x15 is int, true))(char >> 4)); 671 codeUnits[1] = hexDigits.codeUnitAt(((__x15) => DDC$RT.cast(__x15, dynamic, int, "CastGeneral", """line 1248, column 43 of dart:core/uri.dart: """, __x15 i s int, true))(char >> 4));
685 codeUnits[2] = hexDigits.codeUnitAt(((__x16) => DDC$RT.cast(__x16, dynamic, i nt, "CastGeneral", """line 1249, column 43 of dart:core/uri.dart: """, __x16 is int, true))(char & 0xf)); 672 codeUnits[2] = hexDigits.codeUnitAt(((__x16) => DDC$RT.cast(__x16, dynamic, int, "CastGeneral", """line 1249, column 43 of dart:core/uri.dart: """, __x16 i s int, true))(char & 0xf));
686 } 673 }
687 else { 674 else {
688 int flag = 0xc0; 675 int flag = 0xc0;
689 int encodedBytes = 2; 676 int encodedBytes = 2;
690 if (char > 0x7ff) { 677 if (char > 0x7ff) {
691 flag = 0xe0; 678 flag = 0xe0;
692 encodedBytes = 3; 679 encodedBytes = 3;
693 if (char > 0xffff) { 680 if (char > 0xffff) {
694 encodedBytes = 4; 681 encodedBytes = 4;
695 flag = 0xf0; 682 flag = 0xf0;
696 } 683 }
697 } 684 }
698 codeUnits = new List(3 * encodedBytes); 685 codeUnits = new List(3 * encodedBytes);
699 int index = 0; 686 int index = 0;
700 while (--encodedBytes >= 0) { 687 while (--encodedBytes >= 0) {
701 int byte = ((__x17) => DDC$RT.cast(__x17, dynamic, int, "CastGeneral", """li ne 1265, column 20 of dart:core/uri.dart: """, __x17 is int, true))(((char >> (6 * encodedBytes)) & 0x3f) | flag); 688 int byte = ((__x17) => DDC$RT.cast(__x17, dynamic, int, "CastGeneral", """ line 1265, column 20 of dart:core/uri.dart: """, __x17 is int, true))(((char >> (6 * encodedBytes)) & 0x3f) | flag);
702 codeUnits[index] = _PERCENT; 689 codeUnits[index] = _PERCENT;
703 codeUnits[index + 1] = hexDigits.codeUnitAt(byte >> 4); 690 codeUnits[index + 1] = hexDigits.codeUnitAt(byte >> 4);
704 codeUnits[index + 2] = hexDigits.codeUnitAt(byte & 0xf); 691 codeUnits[index + 2] = hexDigits.codeUnitAt(byte & 0xf);
705 index += 3; 692 index += 3;
706 flag = 0x80; 693 flag = 0x80;
707 } 694 }
708 } 695 }
709 return new String.fromCharCodes(codeUnits); 696 return new String.fromCharCodes(codeUnits);
710 } 697 }
711 static String _normalize(String component, int start, int end, List<int> charTa ble) { 698 static String _normalize(String component, int start, int end, List<int> charTa ble) {
712 StringBuffer buffer; 699 StringBuffer buffer;
713 int sectionStart = start; 700 int sectionStart = start;
714 int index = start; 701 int index = start;
715 while (index < end) { 702 while (index < end) {
716 int char = component.codeUnitAt(index); 703 int char = component.codeUnitAt(index);
717 if (char < 127 && (charTable[char >> 4] & (1 << (char & 0x0f))) != 0) { 704 if (char < 127 && (charTable[char >> 4] & (1 << (char & 0x0f))) != 0) {
718 index++; 705 index++;
719 } 706 }
720 else { 707 else {
721 String replacement; 708 String replacement;
722 int sourceLength; 709 int sourceLength;
723 if (char == _PERCENT) { 710 if (char == _PERCENT) {
724 replacement = _normalizeEscape(component, index, false); 711 replacement = _normalizeEscape(component, index, false);
725 if (replacement == null) { 712 if (replacement == null) {
726 index += 3; 713 index += 3;
727 continue; 714 continue;
728 } 715 }
729 if ("%" == replacement) { 716 if ("%" == replacement) {
730 replacement = "%25"; 717 replacement = "%25";
731 sourceLength = 1; 718 sourceLength = 1;
719 }
720 else {
721 sourceLength = 3;
722 }
723 }
724 else if (_isGeneralDelimiter(char)) {
725 _fail(component, index, "Invalid character");
732 } 726 }
733 else { 727 else {
734 sourceLength = 3; 728 sourceLength = 1;
735 } 729 if ((char & 0xFC00) == 0xD800) {
736 } 730 if (index + 1 < end) {
737 else if (_isGeneralDelimiter(char)) { 731 int tail = component.codeUnitAt(index + 1);
738 _fail(component, index, "Invalid character"); 732 if ((tail & 0xFC00) == 0xDC00) {
739 } 733 sourceLength = 2;
740 else { 734 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
741 sourceLength = 1; 735 }
742 if ((char & 0xFC00) == 0xD800) {
743 if (index + 1 < end) {
744 int tail = component.codeUnitAt(index + 1);
745 if ((tail & 0xFC00) == 0xDC00) {
746 sourceLength = 2;
747 char = 0x10000 | ((char & 0x3ff) << 10) | (tail & 0x3ff);
748 } 736 }
749 } 737 }
750 } 738 replacement = _escapeChar(char);
751 replacement = _escapeChar(char); 739 }
752 } 740 if (buffer == null) buffer = new StringBuffer();
753 if (buffer == null) buffer = new StringBuffer(); 741 buffer.write(component.substring(sectionStart, index));
754 buffer.write(component.substring(sectionStart, index)); 742 buffer.write(replacement);
755 buffer.write(replacement); 743 index += sourceLength;
756 index += sourceLength; 744 sectionStart = index;
757 sectionStart = index; 745 }
758 } 746 }
759 } 747 if (buffer == null) {
760 if (buffer == null) { 748 return component.substring(start, end);
761 return component.substring(start, end); 749 }
762 } 750 if (sectionStart < end) {
763 if (sectionStart < end) { 751 buffer.write(component.substring(sectionStart, end));
764 buffer.write(component.substring(sectionStart, end)); 752 }
765 } 753 return buffer.toString();
766 return buffer.toString(); 754 }
767 }
768 static bool _isSchemeCharacter(int ch) { 755 static bool _isSchemeCharacter(int ch) {
769 return ch < 128 && ((_schemeTable[ch >> 4] & (1 << (ch & 0x0f))) != 0); 756 return ch < 128 && ((_schemeTable[ch >> 4] & (1 << (ch & 0x0f))) != 0);
770 } 757 }
771 static bool _isGeneralDelimiter(int ch) { 758 static bool _isGeneralDelimiter(int ch) {
772 return ch <= _RIGHT_BRACKET && ((_genDelimitersTable[ch >> 4] & (1 << (ch & 0x0f ))) != 0); 759 return ch <= _RIGHT_BRACKET && ((_genDelimitersTable[ch >> 4] & (1 << (ch & 0x 0f))) != 0);
773 } 760 }
774 bool get isAbsolute => scheme != "" && fragment == ""; 761 bool get isAbsolute => scheme != "" && fragment == "";
775 String _merge(String base, String reference) { 762 String _merge(String base, String reference) {
776 if (base.isEmpty) return "/$reference"; 763 if (base.isEmpty) return "/$reference";
777 int backCount = 0; 764 int backCount = 0;
778 int refStart = 0; 765 int refStart = 0;
779 while (reference.startsWith("../", refStart)) { 766 while (reference.startsWith("../", refStart)) {
780 refStart += 3; 767 refStart += 3;
781 backCount++; 768 backCount++;
782 } 769 }
783 int baseEnd = base.lastIndexOf('/'); 770 int baseEnd = base.lastIndexOf('/');
784 while (baseEnd > 0 && backCount > 0) { 771 while (baseEnd > 0 && backCount > 0) {
785 int newEnd = base.lastIndexOf('/', baseEnd - 1); 772 int newEnd = base.lastIndexOf('/', baseEnd - 1);
786 if (newEnd < 0) { 773 if (newEnd < 0) {
787 break; 774 break;
788 } 775 }
789 int delta = baseEnd - newEnd; 776 int delta = baseEnd - newEnd;
790 if ((delta == 2 || delta == 3) && base.codeUnitAt(newEnd + 1) == _DOT && (del ta == 2 || base.codeUnitAt(newEnd + 2) == _DOT)) { 777 if ((delta == 2 || delta == 3) && base.codeUnitAt(newEnd + 1) == _DOT && (d elta == 2 || base.codeUnitAt(newEnd + 2) == _DOT)) {
791 break; 778 break;
792 } 779 }
793 baseEnd = newEnd; 780 baseEnd = newEnd;
794 backCount--; 781 backCount--;
795 } 782 }
796 return base.substring(0, baseEnd + 1) + reference.substring(refStart - 3 * back Count); 783 return base.substring(0, baseEnd + 1) + reference.substring(refStart - 3 * ba ckCount);
797 } 784 }
798 bool _hasDotSegments(String path) { 785 bool _hasDotSegments(String path) {
799 if (path.length > 0 && path.codeUnitAt(0) == _DOT) return true; 786 if (path.length > 0 && path.codeUnitAt(0) == _DOT) return true;
800 int index = path.indexOf("/."); 787 int index = path.indexOf("/.");
801 return index != -1; 788 return index != -1;
802 } 789 }
803 String _removeDotSegments(String path) { 790 String _removeDotSegments(String path) {
804 if (!_hasDotSegments(path)) return path; 791 if (!_hasDotSegments(path)) return path;
805 List<String> output = ((__x18) => DDC$RT.cast(__x18, DDC$RT.type((List<dynamic> _) { 792 List<String> output = ((__x18) => DDC$RT.cast(__x18, DDC$RT.type((List<dynami c> _) {
806 } 793 }
807 ), DDC$RT.type((List<String> _) { 794 ), DDC$RT.type((List<String> _) {
808 } 795 }
809 ), "CastLiteral", """line 1402, column 27 of dart:core/uri.dart: """, __x18 is L ist<String>, false))([]); 796 ), "CastLiteral", """line 1402, column 27 of dart:core/uri.dart: """, __x18 is List<String>, false))([]);
810 bool appendSlash = false; 797 bool appendSlash = false;
811 for (String segment in path.split("/")) { 798 for (String segment in path.split("/")) {
812 appendSlash = false; 799 appendSlash = false;
813 if (segment == "..") { 800 if (segment == "..") {
814 if (!output.isEmpty && ((output.length != 1) || (output[0] != ""))) output.r emoveLast(); 801 if (!output.isEmpty && ((output.length != 1) || (output[0] != ""))) output .removeLast();
815 appendSlash = true; 802 appendSlash = true;
816 } 803 }
817 else if ("." == segment) { 804 else if ("." == segment) {
818 appendSlash = true; 805 appendSlash = true;
819 } 806 }
820 else { 807 else {
821 output.add(segment); 808 output.add(segment);
822 } 809 }
823 } 810 }
824 if (appendSlash) output.add(""); 811 if (appendSlash) output.add("");
825 return output.join("/"); 812 return output.join("/");
826 } 813 }
827 Uri resolve(String reference) { 814 Uri resolve(String reference) {
828 return resolveUri(Uri.parse(reference)); 815 return resolveUri(Uri.parse(reference));
829 } 816 }
830 Uri resolveUri(Uri reference) { 817 Uri resolveUri(Uri reference) {
831 String targetScheme; 818 String targetScheme;
832 String targetUserInfo = ""; 819 String targetUserInfo = "";
833 String targetHost; 820 String targetHost;
834 int targetPort; 821 int targetPort;
835 String targetPath; 822 String targetPath;
836 String targetQuery; 823 String targetQuery;
837 if (reference.scheme.isNotEmpty) { 824 if (reference.scheme.isNotEmpty) {
838 targetScheme = reference.scheme; 825 targetScheme = reference.scheme;
839 if (reference.hasAuthority) { 826 if (reference.hasAuthority) {
840 targetUserInfo = reference.userInfo; 827 targetUserInfo = reference.userInfo;
841 targetHost = reference.host; 828 targetHost = reference.host;
842 targetPort = ((__x19) => DDC$RT.cast(__x19, dynamic, int, "CastGeneral", "" "line 1456, column 22 of dart:core/uri.dart: """, __x19 is int, true))(reference .hasPort ? reference.port : null); 829 targetPort = ((__x19) => DDC$RT.cast(__x19, dynamic, int, "CastGeneral", """line 1456, column 22 of dart:core/uri.dart: """, __x19 is int, true))(referen ce.hasPort ? reference.port : null);
843 } 830 }
844 targetPath = _removeDotSegments(reference.path);
845 if (reference.hasQuery) {
846 targetQuery = reference.query;
847 }
848 }
849 else {
850 targetScheme = this.scheme;
851 if (reference.hasAuthority) {
852 targetUserInfo = reference.userInfo;
853 targetHost = reference.host;
854 targetPort = _makePort(((__x20) => DDC$RT.cast(__x20, dynamic, int, "CastGe neral", """line 1467, column 32 of dart:core/uri.dart: """, __x20 is int, true)) (reference.hasPort ? reference.port : null), targetScheme);
855 targetPath = _removeDotSegments(reference.path); 831 targetPath = _removeDotSegments(reference.path);
856 if (reference.hasQuery) targetQuery = reference.query; 832 if (reference.hasQuery) {
857 } 833 targetQuery = reference.query;
858 else { 834 }
859 if (reference.path == "") { 835 }
860 targetPath = this._path; 836 else {
861 if (reference.hasQuery) { 837 targetScheme = this.scheme;
862 targetQuery = reference.query; 838 if (reference.hasAuthority) {
839 targetUserInfo = reference.userInfo;
840 targetHost = reference.host;
841 targetPort = _makePort(((__x20) => DDC$RT.cast(__x20, dynamic, int, "Cast General", """line 1467, column 32 of dart:core/uri.dart: """, __x20 is int, true ))(reference.hasPort ? reference.port : null), targetScheme);
842 targetPath = _removeDotSegments(reference.path);
843 if (reference.hasQuery) targetQuery = reference.query;
844 }
845 else {
846 if (reference.path == "") {
847 targetPath = this._path;
848 if (reference.hasQuery) {
849 targetQuery = reference.query;
850 }
851 else {
852 targetQuery = this._query;
853 }
863 } 854 }
864 else { 855 else {
865 targetQuery = this._query; 856 if (reference.path.startsWith("/")) {
866 } 857 targetPath = _removeDotSegments(reference.path);
867 } 858 }
868 else { 859 else {
869 if (reference.path.startsWith("/")) { 860 targetPath = _removeDotSegments(_merge(this._path, reference.path));
870 targetPath = _removeDotSegments(reference.path); 861 }
871 } 862 if (reference.hasQuery) targetQuery = reference.query;
872 else { 863 }
873 targetPath = _removeDotSegments(_merge(this._path, reference.path)); 864 targetUserInfo = this._userInfo;
874 } 865 targetHost = this._host;
875 if (reference.hasQuery) targetQuery = reference.query; 866 targetPort = ((__x21) => DDC$RT.cast(__x21, num, int, "CastGeneral", """l ine 1489, column 22 of dart:core/uri.dart: """, __x21 is int, true))(this._port) ;
876 } 867 }
877 targetUserInfo = this._userInfo; 868 }
878 targetHost = this._host; 869 String fragment = ((__x22) => DDC$RT.cast(__x22, dynamic, String, "CastGenera l", """line 1492, column 23 of dart:core/uri.dart: """, __x22 is String, true))( reference.hasFragment ? reference.fragment : null);
879 targetPort = ((__x21) => DDC$RT.cast(__x21, num, int, "CastGeneral", """lin e 1489, column 22 of dart:core/uri.dart: """, __x21 is int, true))(this._port); 870 return new Uri._internal(targetScheme, targetUserInfo, targetHost, targetPort , targetPath, targetQuery, fragment);
880 } 871 }
881 }
882 String fragment = ((__x22) => DDC$RT.cast(__x22, dynamic, String, "CastGeneral" , """line 1492, column 23 of dart:core/uri.dart: """, __x22 is String, true))(re ference.hasFragment ? reference.fragment : null);
883 return new Uri._internal(targetScheme, targetUserInfo, targetHost, targetPort, targetPath, targetQuery, fragment);
884 }
885 bool get hasAuthority => _host != null; 872 bool get hasAuthority => _host != null;
886 bool get hasPort => _port != null; 873 bool get hasPort => _port != null;
887 bool get hasQuery => _query != null; 874 bool get hasQuery => _query != null;
888 bool get hasFragment => _fragment != null; 875 bool get hasFragment => _fragment != null;
889 String get origin { 876 String get origin {
890 if (scheme == "" || _host == null || _host == "") { 877 if (scheme == "" || _host == null || _host == "") {
891 throw new StateError("Cannot use origin without a scheme: $this"); 878 throw new StateError("Cannot use origin without a scheme: $this");
892 } 879 }
893 if (scheme != "http" && scheme != "https") { 880 if (scheme != "http" && scheme != "https") {
894 throw new StateError("Origin is only applicable schemes http and https: $this" ); 881 throw new StateError("Origin is only applicable schemes http and https: $thi s");
895 } 882 }
896 if (_port == null) return "$scheme://$_host"; 883 if (_port == null) return "$scheme://$_host";
897 return "$scheme://$_host:$_port"; 884 return "$scheme://$_host:$_port";
898 } 885 }
899 String toFilePath({ 886 String toFilePath({
900 bool windows} 887 bool windows}
901 ) { 888 ) {
902 if (scheme != "" && scheme != "file") { 889 if (scheme != "" && scheme != "file") {
903 throw new UnsupportedError("Cannot extract a file path from a $scheme URI"); 890 throw new UnsupportedError("Cannot extract a file path from a $scheme URI");
904 } 891 }
905 if (query != "") { 892 if (query != "") {
906 throw new UnsupportedError("Cannot extract a file path from a URI with a query component"); 893 throw new UnsupportedError("Cannot extract a file path from a URI with a que ry component");
907 } 894 }
908 if (fragment != "") { 895 if (fragment != "") {
909 throw new UnsupportedError("Cannot extract a file path from a URI with a fragm ent component"); 896 throw new UnsupportedError("Cannot extract a file path from a URI with a fra gment component");
910 } 897 }
911 if (windows == null) windows = _isWindows; 898 if (windows == null) windows = _isWindows;
912 return windows ? _toWindowsFilePath() : _toFilePath(); 899 return windows ? _toWindowsFilePath() : _toFilePath();
913 } 900 }
914 String _toFilePath() { 901 String _toFilePath() {
915 if (host != "") { 902 if (host != "") {
916 throw new UnsupportedError("Cannot extract a non-Windows file path from a file URI " "with an authority"); 903 throw new UnsupportedError("Cannot extract a non-Windows file path from a fi le URI " "with an authority");
917 } 904 }
918 _checkNonWindowsPathReservedCharacters(pathSegments, false); 905 _checkNonWindowsPathReservedCharacters(pathSegments, false);
919 var result = new StringBuffer(); 906 var result = new StringBuffer();
920 if (_isPathAbsolute) result.write("/"); 907 if (_isPathAbsolute) result.write("/");
921 result.writeAll(pathSegments, "/"); 908 result.writeAll(pathSegments, "/");
922 return result.toString(); 909 return result.toString();
923 } 910 }
924 String _toWindowsFilePath() { 911 String _toWindowsFilePath() {
925 bool hasDriveLetter = false; 912 bool hasDriveLetter = false;
926 var segments = pathSegments; 913 var segments = pathSegments;
927 if (segments.length > 0 && segments[0].length == 2 && segments[0].codeUnitAt(1) == _COLON) { 914 if (segments.length > 0 && segments[0].length == 2 && segments[0].codeUnitAt( 1) == _COLON) {
928 _checkWindowsDriveLetter(segments[0].codeUnitAt(0), false); 915 _checkWindowsDriveLetter(segments[0].codeUnitAt(0), false);
929 _checkWindowsPathReservedCharacters(segments, false, 1); 916 _checkWindowsPathReservedCharacters(segments, false, 1);
930 hasDriveLetter = true; 917 hasDriveLetter = true;
931 } 918 }
932 else { 919 else {
933 _checkWindowsPathReservedCharacters(segments, false); 920 _checkWindowsPathReservedCharacters(segments, false);
934 } 921 }
935 var result = new StringBuffer(); 922 var result = new StringBuffer();
936 if (_isPathAbsolute && !hasDriveLetter) result.write("\\"); 923 if (_isPathAbsolute && !hasDriveLetter) result.write("\\");
937 if (host != "") { 924 if (host != "") {
938 result.write("\\"); 925 result.write("\\");
939 result.write(host); 926 result.write(host);
940 result.write("\\"); 927 result.write("\\");
941 } 928 }
942 result.writeAll(segments, "\\"); 929 result.writeAll(segments, "\\");
943 if (hasDriveLetter && segments.length == 1) result.write("\\"); 930 if (hasDriveLetter && segments.length == 1) result.write("\\");
944 return result.toString(); 931 return result.toString();
945 } 932 }
946 bool get _isPathAbsolute { 933 bool get _isPathAbsolute {
947 if (path == null || path.isEmpty) return false; 934 if (path == null || path.isEmpty) return false;
948 return path.startsWith('/'); 935 return path.startsWith('/');
949 } 936 }
950 void _writeAuthority(StringSink ss) { 937 void _writeAuthority(StringSink ss) {
951 if (_userInfo.isNotEmpty) { 938 if (_userInfo.isNotEmpty) {
952 ss.write(_userInfo); 939 ss.write(_userInfo);
953 ss.write("@"); 940 ss.write("@");
954 } 941 }
955 if (_host != null) ss.write(_host); 942 if (_host != null) ss.write(_host);
956 if (_port != null) { 943 if (_port != null) {
957 ss.write(":"); 944 ss.write(":");
958 ss.write(_port); 945 ss.write(_port);
959 } 946 }
960 } 947 }
961 String toString() { 948 String toString() {
962 StringBuffer sb = new StringBuffer(); 949 StringBuffer sb = new StringBuffer();
963 _addIfNonEmpty(sb, scheme, scheme, ':'); 950 _addIfNonEmpty(sb, scheme, scheme, ':');
964 if (hasAuthority || path.startsWith("//") || (scheme == "file")) { 951 if (hasAuthority || path.startsWith("//") || (scheme == "file")) {
965 sb.write("//"); 952 sb.write("//");
966 _writeAuthority(sb); 953 _writeAuthority(sb);
967 } 954 }
968 sb.write(path); 955 sb.write(path);
969 if (_query != null) { 956 if (_query != null) {
970 sb..write("?")..write(_query); 957 sb..write("?")..write(_query);
971 } 958 }
972 if (_fragment != null) { 959 if (_fragment != null) {
973 sb..write("#")..write(_fragment); 960 sb..write("#")..write(_fragment);
974 } 961 }
975 return sb.toString(); 962 return sb.toString();
976 } 963 }
977 bool operator ==(other) { 964 bool operator ==(other) {
978 if (other is! Uri) return false; 965 if (other is! Uri) return false;
979 Uri uri = DDC$RT.cast(other, dynamic, Uri, "CastGeneral", """line 1698, column 15 of dart:core/uri.dart: """, other is Uri, true); 966 Uri uri = DDC$RT.cast(other, dynamic, Uri, "CastGeneral", """line 1698, colum n 15 of dart:core/uri.dart: """, other is Uri, true);
980 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; 967 return scheme == uri.scheme && hasAuthority == uri.hasAuthority && userInfo = = uri.userInfo && host == uri.host && port == uri.port && path == uri.path && ha sQuery == uri.hasQuery && query == uri.query && hasFragment == uri.hasFragment & & fragment == uri.fragment;
981 } 968 }
982 int get hashCode { 969 int get hashCode {
983 int combine(part, current) { 970 int combine(part, current) {
984 return ((__x23) => DDC$RT.cast(__x23, dynamic, int, "CastGeneral", """line 171 4, column 14 of dart:core/uri.dart: """, __x23 is int, true))((current * 31 + pa rt.hashCode) & 0x3FFFFFFF); 971 return ((__x23) => DDC$RT.cast(__x23, dynamic, int, "CastGeneral", """line 1 714, column 14 of dart:core/uri.dart: """, __x23 is int, true))((current * 31 + part.hashCode) & 0x3FFFFFFF);
985 } 972 }
986 return combine(scheme, combine(userInfo, combine(host, combine(port, combine(pa th, combine(query, combine(fragment, 1))))))); 973 return combine(scheme, combine(userInfo, combine(host, combine(port, combine( path, combine(query, combine(fragment, 1)))))));
987 } 974 }
988 static void _addIfNonEmpty(StringBuffer sb, String test, String first, String s econd) { 975 static void _addIfNonEmpty(StringBuffer sb, String test, String first, String s econd) {
989 if ("" != test) { 976 if ("" != test) {
990 sb.write(first); 977 sb.write(first);
991 sb.write(second); 978 sb.write(second);
992 } 979 }
993 } 980 }
994 static String encodeComponent(String component) { 981 static String encodeComponent(String component) {
995 return _uriEncode(DDC$RT.cast(_unreserved2396Table, dynamic, DDC$RT.type((List<i nt> _) { 982 return _uriEncode(DDC$RT.cast(_unreserved2396Table, dynamic, DDC$RT.type((List <int> _) {
996 } 983 }
997 ), "CastGeneral", """line 1749, column 23 of dart:core/uri.dart: """, _unreserve d2396Table is List<int>, false), component); 984 ), "CastGeneral", """line 1749, column 23 of dart:core/uri.dart: """, _unreser ved2396Table is List<int>, false), component);
998 } 985 }
999 static String encodeQueryComponent(String component, { 986 static String encodeQueryComponent(String component, {
1000 Encoding encoding : UTF8} 987 Encoding encoding : UTF8}
1001 ) { 988 ) {
1002 return _uriEncode(DDC$RT.cast(_unreservedTable, dynamic, DDC$RT.type((List<int> _) { 989 return _uriEncode(DDC$RT.cast(_unreservedTable, dynamic, DDC$RT.type((List<int > _) {
1003 } 990 }
1004 ), "CastGeneral", """line 1788, column 9 of dart:core/uri.dart: """, _unreserved Table is List<int>, false), component, encoding: encoding, spaceToPlus: true); 991 ), "CastGeneral", """line 1788, column 9 of dart:core/uri.dart: """, _unreserv edTable is List<int>, false), component, encoding: encoding, spaceToPlus: true);
1005 } 992 }
1006 static String decodeComponent(String encodedComponent) { 993 static String decodeComponent(String encodedComponent) {
1007 return _uriDecode(encodedComponent); 994 return _uriDecode(encodedComponent);
1008 } 995 }
1009 static String decodeQueryComponent(String encodedComponent, { 996 static String decodeQueryComponent(String encodedComponent, {
1010 Encoding encoding : UTF8} 997 Encoding encoding : UTF8}
1011 ) { 998 ) {
1012 return _uriDecode(encodedComponent, plusToSpace: true, encoding: encoding); 999 return _uriDecode(encodedComponent, plusToSpace: true, encoding: encoding);
1013 } 1000 }
1014 static String encodeFull(String uri) { 1001 static String encodeFull(String uri) {
1015 return _uriEncode(DDC$RT.cast(_encodeFullTable, dynamic, DDC$RT.type((List<int> _) { 1002 return _uriEncode(DDC$RT.cast(_encodeFullTable, dynamic, DDC$RT.type((List<int > _) {
1016 } 1003 }
1017 ), "CastGeneral", """line 1832, column 23 of dart:core/uri.dart: """, _encodeFul lTable is List<int>, false), uri); 1004 ), "CastGeneral", """line 1832, column 23 of dart:core/uri.dart: """, _encodeF ullTable is List<int>, false), uri);
1018 } 1005 }
1019 static String decodeFull(String uri) { 1006 static String decodeFull(String uri) {
1020 return _uriDecode(uri); 1007 return _uriDecode(uri);
1021 } 1008 }
1022 static Map<String, String> splitQueryString(String query, { 1009 static Map<String, String> splitQueryString(String query, {
1023 Encoding encoding : UTF8} 1010 Encoding encoding : UTF8}
1024 ) { 1011 ) {
1025 return ((__x24) => DDC$RT.cast(__x24, dynamic, DDC$RT.type((Map<String, String> _) { 1012 return ((__x24) => DDC$RT.cast(__x24, dynamic, DDC$RT.type((Map<String, String > _) {
1026 } 1013 }
1027 ), "CastGeneral", """line 1864, column 12 of dart:core/uri.dart: """, __x24 is M ap<String, String>, false))(query.split("&").fold({ 1014 ), "CastGeneral", """line 1864, column 12 of dart:core/uri.dart: """, __x24 is Map<String, String>, false))(query.split("&").fold({
1028 } 1015 }
1029 , (map, element) { 1016 , (map, element) {
1030 int index = ((__x25) => DDC$RT.cast(__x25, dynamic, int, "CastGeneral", """lin e 1865, column 19 of dart:core/uri.dart: """, __x25 is int, true))(element.index Of("=")); 1017 int index = ((__x25) => DDC$RT.cast(__x25, dynamic, int, "CastGeneral", """l ine 1865, column 19 of dart:core/uri.dart: """, __x25 is int, true))(element.ind exOf("="));
1031 if (index == -1) { 1018 if (index == -1) {
1032 if (element != "") { 1019 if (element != "") {
1033 map[decodeQueryComponent(DDC$RT.cast(element, dynamic, String, "CastGenera l", """line 1868, column 36 of dart:core/uri.dart: """, element is String, true) , encoding: encoding)] = ""; 1020 map[decodeQueryComponent(DDC$RT.cast(element, dynamic, String, "CastGene ral", """line 1868, column 36 of dart:core/uri.dart: """, element is String, tru e), encoding: encoding)] = "";
1034 } 1021 }
1035 } 1022 }
1036 else if (index != 0) { 1023 else if (index != 0) {
1037 var key = element.substring(0, index); 1024 var key = element.substring(0, index);
1038 var value = element.substring(index + 1); 1025 var value = element.substring(index + 1);
1039 map[Uri.decodeQueryComponent(DDC$RT.cast(key, dynamic, String, "CastGeneral ", """line 1873, column 38 of dart:core/uri.dart: """, key is String, true), enc oding: encoding)] = decodeQueryComponent(DDC$RT.cast(value, dynamic, String, "Ca stGeneral", """line 1874, column 34 of dart:core/uri.dart: """, value is String, true), encoding: encoding); 1026 map[Uri.decodeQueryComponent(DDC$RT.cast(key, dynamic, String, "CastGener al", """line 1873, column 38 of dart:core/uri.dart: """, key is String, true), e ncoding: encoding)] = decodeQueryComponent(DDC$RT.cast(value, dynamic, String, " CastGeneral", """line 1874, column 34 of dart:core/uri.dart: """, value is Strin g, true), encoding: encoding);
1040 } 1027 }
1041 return map; 1028 return map;
1042 } 1029 }
1043 )); 1030 ));
1044 } 1031 }
1045 static List<int> parseIPv4Address(String host) { 1032 static List<int> parseIPv4Address(String host) {
1046 void error(String msg) { 1033 void error(String msg) {
1047 throw new FormatException('Illegal IPv4 address, $msg'); 1034 throw new FormatException('Illegal IPv4 address, $msg');
1048 } 1035 }
1049 var bytes = host.split('.'); 1036 var bytes = host.split('.');
1050 if (bytes.length != 4) { 1037 if (bytes.length != 4) {
1051 error('IPv4 address should contain exactly 4 parts'); 1038 error('IPv4 address should contain exactly 4 parts');
1052 } 1039 }
1053 return ((__x26) => DDC$RT.cast(__x26, DDC$RT.type((List<dynamic> _) { 1040 return ((__x26) => DDC$RT.cast(__x26, DDC$RT.type((List<dynamic> _) {
1054 } 1041 }
1055 ), DDC$RT.type((List<int> _) { 1042 ), DDC$RT.type((List<int> _) {
1056 } 1043 }
1057 ), "CastDynamic", """line 1896, column 12 of dart:core/uri.dart: """, __x26 is L ist<int>, false))(bytes.map((byteString) { 1044 ), "CastDynamic", """line 1896, column 12 of dart:core/uri.dart: """, __x26 is List<int>, false))(bytes.map((byteString) {
1058 int byte = int.parse(DDC$RT.cast(byteString, dynamic, String, "CastGeneral", " ""line 1898, column 32 of dart:core/uri.dart: """, byteString is String, true)); 1045 int byte = int.parse(DDC$RT.cast(byteString, dynamic, String, "CastGeneral", """line 1898, column 32 of dart:core/uri.dart: """, byteString is String, true) );
1059 if (byte < 0 || byte > 255) { 1046 if (byte < 0 || byte > 255) {
1060 error('each part must be in the range of `0..255`'); 1047 error('each part must be in the range of `0..255`');
1061 } 1048 }
1062 return byte; 1049 return byte;
1063 } 1050 }
1064 ).toList()); 1051 ).toList());
1065 } 1052 }
1066 static List<int> parseIPv6Address(String host, [int start = 0, int end]) { 1053 static List<int> parseIPv6Address(String host, [int start = 0, int end]) {
1067 if (end == null) end = host.length; 1054 if (end == null) end = host.length;
1068 void error(String msg, [position]) { 1055 void error(String msg, [position]) {
1069 throw new FormatException('Illegal IPv6 address, $msg', host, position); 1056 throw new FormatException('Illegal IPv6 address, $msg', host, position);
1070 } 1057 }
1071 int parseHex(int start, int end) { 1058 int parseHex(int start, int end) {
1072 if (end - start > 4) { 1059 if (end - start > 4) {
1073 error('an IPv6 part can only contain a maximum of 4 hex digits', start); 1060 error('an IPv6 part can only contain a maximum of 4 hex digits', start);
1074 } 1061 }
1075 int value = int.parse(host.substring(start, end), radix: 16); 1062 int value = int.parse(host.substring(start, end), radix: 16);
1076 if (value < 0 || value > (1 << 16) - 1) { 1063 if (value < 0 || value > (1 << 16) - 1) {
1077 error('each part must be in the range of `0x0..0xFFFF`', start); 1064 error('each part must be in the range of `0x0..0xFFFF`', start);
1078 } 1065 }
1079 return value; 1066 return value;
1080 } 1067 }
1081 if (host.length < 2) error('address is too short'); 1068 if (host.length < 2) error('address is too short');
1082 List<int> parts = ((__x27) => DDC$RT.cast(__x27, DDC$RT.type((List<dynamic> _) { 1069 List<int> parts = ((__x27) => DDC$RT.cast(__x27, DDC$RT.type((List<dynamic> _ ) {
1083 } 1070 }
1084 ), DDC$RT.type((List<int> _) { 1071 ), DDC$RT.type((List<int> _) {
1085 } 1072 }
1086 ), "CastLiteral", """line 1946, column 23 of dart:core/uri.dart: """, __x27 is L ist<int>, false))([]); 1073 ), "CastLiteral", """line 1946, column 23 of dart:core/uri.dart: """, __x27 is List<int>, false))([]);
1087 bool wildcardSeen = false; 1074 bool wildcardSeen = false;
1088 int partStart = start; 1075 int partStart = start;
1089 for (int i = start; 1076 for (int i = start; i < end; i++) {
1090 i < end; 1077 if (host.codeUnitAt(i) == _COLON) {
1091 i++) { 1078 if (i == start) {
1092 if (host.codeUnitAt(i) == _COLON) { 1079 i++;
1093 if (i == start) { 1080 if (host.codeUnitAt(i) != _COLON) {
1094 i++; 1081 error('invalid start colon.', i);
1095 if (host.codeUnitAt(i) != _COLON) { 1082 }
1096 error('invalid start colon.', i); 1083 partStart = i;
1097 } 1084 }
1098 partStart = i; 1085 if (i == partStart) {
1099 } 1086 if (wildcardSeen) {
1100 if (i == partStart) { 1087 error('only one wildcard `::` is allowed', i);
1101 if (wildcardSeen) { 1088 }
1102 error('only one wildcard `::` is allowed', i); 1089 wildcardSeen = true;
1103 } 1090 parts.add(-1);
1104 wildcardSeen = true; 1091 }
1105 parts.add(-1); 1092 else {
1093 parts.add(parseHex(partStart, i));
1094 }
1095 partStart = i + 1;
1096 }
1097 }
1098 if (parts.length == 0) error('too few parts');
1099 bool atEnd = (partStart == end);
1100 bool isLastWildcard = (parts.last == -1);
1101 if (atEnd && !isLastWildcard) {
1102 error('expected a part after last `:`', end);
1103 }
1104 if (!atEnd) {
1105 try {
1106 parts.add(parseHex(partStart, end));
1107 }
1108 catch (e) {
1109 try {
1110 List<int> last = parseIPv4Address(host.substring(partStart, end));
1111 parts.add(last[0] << 8 | last[1]);
1112 parts.add(last[2] << 8 | last[3]);
1113 }
1114 catch (e) {
1115 error('invalid end of IPv6 address.', partStart);
1116 }
1117 }
1118 }
1119 if (wildcardSeen) {
1120 if (parts.length > 7) {
1121 error('an address with a wildcard must have less than 7 parts');
1122 }
1123 }
1124 else if (parts.length != 8) {
1125 error('an address without a wildcard must contain exactly 8 parts');
1126 }
1127 List bytes = new List<int>(16);
1128 for (int i = 0, index = 0; i < parts.length; i++) {
1129 int value = parts[i];
1130 if (value == -1) {
1131 int wildCardLength = 9 - parts.length;
1132 for (int j = 0; j < wildCardLength; j++) {
1133 bytes[index] = 0;
1134 bytes[index + 1] = 0;
1135 index += 2;
1136 }
1106 } 1137 }
1107 else { 1138 else {
1108 parts.add(parseHex(partStart, i)); 1139 bytes[index] = value >> 8;
1109 } 1140 bytes[index + 1] = value & 0xff;
1110 partStart = i + 1;
1111 }
1112 }
1113 if (parts.length == 0) error('too few parts');
1114 bool atEnd = (partStart == end);
1115 bool isLastWildcard = (parts.last == -1);
1116 if (atEnd && !isLastWildcard) {
1117 error('expected a part after last `:`', end);
1118 }
1119 if (!atEnd) {
1120 try {
1121 parts.add(parseHex(partStart, end));
1122 }
1123 catch (e) {
1124 try {
1125 List<int> last = parseIPv4Address(host.substring(partStart, end));
1126 parts.add(last[0] << 8 | last[1]);
1127 parts.add(last[2] << 8 | last[3]);
1128 }
1129 catch (e) {
1130 error('invalid end of IPv6 address.', partStart);
1131 }
1132 }
1133 }
1134 if (wildcardSeen) {
1135 if (parts.length > 7) {
1136 error('an address with a wildcard must have less than 7 parts');
1137 }
1138 }
1139 else if (parts.length != 8) {
1140 error('an address without a wildcard must contain exactly 8 parts');
1141 }
1142 List bytes = new List<int>(16);
1143 for (int i = 0, index = 0;
1144 i < parts.length;
1145 i++) {
1146 int value = parts[i];
1147 if (value == -1) {
1148 int wildCardLength = 9 - parts.length;
1149 for (int j = 0;
1150 j < wildCardLength;
1151 j++) {
1152 bytes[index] = 0;
1153 bytes[index + 1] = 0;
1154 index += 2; 1141 index += 2;
1155 } 1142 }
1156 } 1143 }
1157 else { 1144 return DDC$RT.cast(bytes, DDC$RT.type((List<dynamic> _) {
1158 bytes[index] = value >> 8; 1145 }
1159 bytes[index + 1] = value & 0xff; 1146 ), DDC$RT.type((List<int> _) {
1160 index += 2; 1147 }
1161 } 1148 ), "CastDynamic", """line 2018, column 12 of dart:core/uri.dart: """, bytes is List<int>, false);
1162 } 1149 }
1163 return DDC$RT.cast(bytes, DDC$RT.type((List<dynamic> _) {
1164 }
1165 ), DDC$RT.type((List<int> _) {
1166 }
1167 ), "CastDynamic", """line 2018, column 12 of dart:core/uri.dart: """, bytes is L ist<int>, false);
1168 }
1169 static const int _SPACE = 0x20; 1150 static const int _SPACE = 0x20;
1170 static const int _DOUBLE_QUOTE = 0x22; 1151 static const int _DOUBLE_QUOTE = 0x22;
1171 static const int _NUMBER_SIGN = 0x23; 1152 static const int _NUMBER_SIGN = 0x23;
1172 static const int _PERCENT = 0x25; 1153 static const int _PERCENT = 0x25;
1173 static const int _ASTERISK = 0x2A; 1154 static const int _ASTERISK = 0x2A;
1174 static const int _PLUS = 0x2B; 1155 static const int _PLUS = 0x2B;
1175 static const int _DOT = 0x2E; 1156 static const int _DOT = 0x2E;
1176 static const int _SLASH = 0x2F; 1157 static const int _SLASH = 0x2F;
1177 static const int _ZERO = 0x30; 1158 static const int _ZERO = 0x30;
1178 static const int _NINE = 0x39; 1159 static const int _NINE = 0x39;
1179 static const int _COLON = 0x3A; 1160 static const int _COLON = 0x3A;
1180 static const int _LESS = 0x3C; 1161 static const int _LESS = 0x3C;
1181 static const int _GREATER = 0x3E; 1162 static const int _GREATER = 0x3E;
1182 static const int _QUESTION = 0x3F; 1163 static const int _QUESTION = 0x3F;
1183 static const int _AT_SIGN = 0x40; 1164 static const int _AT_SIGN = 0x40;
1184 static const int _UPPER_CASE_A = 0x41; 1165 static const int _UPPER_CASE_A = 0x41;
1185 static const int _UPPER_CASE_F = 0x46; 1166 static const int _UPPER_CASE_F = 0x46;
1186 static const int _UPPER_CASE_Z = 0x5A; 1167 static const int _UPPER_CASE_Z = 0x5A;
1187 static const int _LEFT_BRACKET = 0x5B; 1168 static const int _LEFT_BRACKET = 0x5B;
1188 static const int _BACKSLASH = 0x5C; 1169 static const int _BACKSLASH = 0x5C;
1189 static const int _RIGHT_BRACKET = 0x5D; 1170 static const int _RIGHT_BRACKET = 0x5D;
1190 static const int _LOWER_CASE_A = 0x61; 1171 static const int _LOWER_CASE_A = 0x61;
1191 static const int _LOWER_CASE_F = 0x66; 1172 static const int _LOWER_CASE_F = 0x66;
1192 static const int _LOWER_CASE_Z = 0x7A; 1173 static const int _LOWER_CASE_Z = 0x7A;
1193 static const int _BAR = 0x7C; 1174 static const int _BAR = 0x7C;
1194 static String _uriEncode(List<int> canonicalTable, String text, { 1175 static String _uriEncode(List<int> canonicalTable, String text, {
1195 Encoding encoding : UTF8, bool spaceToPlus : false} 1176 Encoding encoding : UTF8, bool spaceToPlus : false}
1196 ) { 1177 ) {
1197 byteToHex(byte, buffer) { 1178 byteToHex(byte, buffer) {
1198 const String hex = '0123456789ABCDEF'; 1179 const String hex = '0123456789ABCDEF';
1199 buffer.writeCharCode(hex.codeUnitAt(((__x28) => DDC$RT.cast(__x28, dynamic, i nt, "CastGeneral", """line 2059, column 43 of dart:core/uri.dart: """, __x28 is int, true))(byte >> 4))); 1180 buffer.writeCharCode(hex.codeUnitAt(((__x28) => DDC$RT.cast(__x28, dynamic, int, "CastGeneral", """line 2059, column 43 of dart:core/uri.dart: """, __x28 i s int, true))(byte >> 4)));
1200 buffer.writeCharCode(hex.codeUnitAt(((__x29) => DDC$RT.cast(__x29, dynamic, i nt, "CastGeneral", """line 2060, column 43 of dart:core/uri.dart: """, __x29 is int, true))(byte & 0x0f))); 1181 buffer.writeCharCode(hex.codeUnitAt(((__x29) => DDC$RT.cast(__x29, dynamic, int, "CastGeneral", """line 2060, column 43 of dart:core/uri.dart: """, __x29 i s int, true))(byte & 0x0f)));
1182 }
1183 StringBuffer result = new StringBuffer();
1184 var bytes = encoding.encode(text);
1185 for (int i = 0; i < bytes.length; i++) {
1186 int byte = bytes[i];
1187 if (byte < 128 && ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0) ) {
1188 result.writeCharCode(byte);
1189 }
1190 else if (spaceToPlus && byte == _SPACE) {
1191 result.writeCharCode(_PLUS);
1192 }
1193 else {
1194 result.writeCharCode(_PERCENT);
1195 byteToHex(byte, result);
1196 }
1197 }
1198 return result.toString();
1201 } 1199 }
1202 StringBuffer result = new StringBuffer(); 1200 static int _hexCharPairToByte(String s, int pos) {
1203 var bytes = encoding.encode(text); 1201 int byte = 0;
1204 for (int i = 0; 1202 for (int i = 0; i < 2; i++) {
1205 i < bytes.length; 1203 var charCode = s.codeUnitAt(pos + i);
1206 i++) { 1204 if (0x30 <= charCode && charCode <= 0x39) {
1207 int byte = bytes[i]; 1205 byte = byte * 16 + charCode - 0x30;
1208 if (byte < 128 && ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { 1206 }
1209 result.writeCharCode(byte); 1207 else {
1208 charCode |= 0x20;
1209 if (0x61 <= charCode && charCode <= 0x66) {
1210 byte = byte * 16 + charCode - 0x57;
1211 }
1212 else {
1213 throw new ArgumentError("Invalid URL encoding");
1214 }
1215 }
1210 } 1216 }
1211 else if (spaceToPlus && byte == _SPACE) { 1217 return byte;
1212 result.writeCharCode(_PLUS); 1218 }
1219 static String _uriDecode(String text, {
1220 bool plusToSpace : false, Encoding encoding : UTF8}
1221 ) {
1222 bool simple = true;
1223 for (int i = 0; i < text.length && simple; i++) {
1224 var codeUnit = text.codeUnitAt(i);
1225 simple = codeUnit != _PERCENT && codeUnit != _PLUS;
1226 }
1227 List<int> bytes;
1228 if (simple) {
1229 if (encoding == UTF8 || encoding == LATIN1) {
1230 return text;
1231 }
1232 else {
1233 bytes = text.codeUnits;
1234 }
1213 } 1235 }
1214 else { 1236 else {
1215 result.writeCharCode(_PERCENT); 1237 bytes = ((__x30) => DDC$RT.cast(__x30, DDC$RT.type((List<dynamic> _) {
1216 byteToHex(byte, result);
1217 }
1218 }
1219 return result.toString();
1220 }
1221 static int _hexCharPairToByte(String s, int pos) {
1222 int byte = 0;
1223 for (int i = 0;
1224 i < 2;
1225 i++) {
1226 var charCode = s.codeUnitAt(pos + i);
1227 if (0x30 <= charCode && charCode <= 0x39) {
1228 byte = byte * 16 + charCode - 0x30;
1229 }
1230 else {
1231 charCode |= 0x20;
1232 if (0x61 <= charCode && charCode <= 0x66) {
1233 byte = byte * 16 + charCode - 0x57;
1234 } 1238 }
1235 else { 1239 ), DDC$RT.type((List<int> _) {
1236 throw new ArgumentError("Invalid URL encoding"); 1240 }
1241 ), "CastExact", """line 2134, column 15 of dart:core/uri.dart: """, __x30 is List<int>, false))(new List());
1242 for (int i = 0; i < text.length; i++) {
1243 var codeUnit = text.codeUnitAt(i);
1244 if (codeUnit > 127) {
1245 throw new ArgumentError("Illegal percent encoding in URI");
1246 }
1247 if (codeUnit == _PERCENT) {
1248 if (i + 3 > text.length) {
1249 throw new ArgumentError('Truncated URI');
1250 }
1251 bytes.add(_hexCharPairToByte(text, i + 1));
1252 i += 2;
1253 }
1254 else if (plusToSpace && codeUnit == _PLUS) {
1255 bytes.add(_SPACE);
1256 }
1257 else {
1258 bytes.add(codeUnit);
1259 }
1237 } 1260 }
1238 } 1261 }
1262 return encoding.decode(bytes);
1239 } 1263 }
1240 return byte;
1241 }
1242 static String _uriDecode(String text, {
1243 bool plusToSpace : false, Encoding encoding : UTF8}
1244 ) {
1245 bool simple = true;
1246 for (int i = 0;
1247 i < text.length && simple;
1248 i++) {
1249 var codeUnit = text.codeUnitAt(i);
1250 simple = codeUnit != _PERCENT && codeUnit != _PLUS;
1251 }
1252 List<int> bytes;
1253 if (simple) {
1254 if (encoding == UTF8 || encoding == LATIN1) {
1255 return text;
1256 }
1257 else {
1258 bytes = text.codeUnits;
1259 }
1260 }
1261 else {
1262 bytes = ((__x30) => DDC$RT.cast(__x30, DDC$RT.type((List<dynamic> _) {
1263 }
1264 ), DDC$RT.type((List<int> _) {
1265 }
1266 ), "CastExact", """line 2134, column 15 of dart:core/uri.dart: """, __x30 is L ist<int>, false))(new List());
1267 for (int i = 0;
1268 i < text.length;
1269 i++) {
1270 var codeUnit = text.codeUnitAt(i);
1271 if (codeUnit > 127) {
1272 throw new ArgumentError("Illegal percent encoding in URI");
1273 }
1274 if (codeUnit == _PERCENT) {
1275 if (i + 3 > text.length) {
1276 throw new ArgumentError('Truncated URI');
1277 }
1278 bytes.add(_hexCharPairToByte(text, i + 1));
1279 i += 2;
1280 }
1281 else if (plusToSpace && codeUnit == _PLUS) {
1282 bytes.add(_SPACE);
1283 }
1284 else {
1285 bytes.add(codeUnit);
1286 }
1287 }
1288 }
1289 return encoding.decode(bytes);
1290 }
1291 static bool _isAlphabeticCharacter(int codeUnit) => (codeUnit >= _LOWER_CASE_A && codeUnit <= _LOWER_CASE_Z) || (codeUnit >= _UPPER_CASE_A && codeUnit <= _UPPE R_CASE_Z); 1264 static bool _isAlphabeticCharacter(int codeUnit) => (codeUnit >= _LOWER_CASE_A && codeUnit <= _LOWER_CASE_Z) || (codeUnit >= _UPPER_CASE_A && codeUnit <= _UPPE R_CASE_Z);
1292 static const _unreservedTable = const [0x0000, 0x0000, 0x6000, 0x03ff, 0xfffe, 0x87ff, 0xfffe, 0x47ff]; 1265 static const _unreservedTable = const [0x0000, 0x0000, 0x6000, 0x03ff, 0xfffe, 0x87ff, 0xfffe, 0x47ff];
1293 static const _unreserved2396Table = const [0x0000, 0x0000, 0x6782, 0x03ff, 0xff fe, 0x87ff, 0xfffe, 0x47ff]; 1266 static const _unreserved2396Table = const [0x0000, 0x0000, 0x6782, 0x03ff, 0xff fe, 0x87ff, 0xfffe, 0x47ff];
1294 static const _encodeFullTable = const [0x0000, 0x0000, 0xffda, 0xafff, 0xffff, 0x87ff, 0xfffe, 0x47ff]; 1267 static const _encodeFullTable = const [0x0000, 0x0000, 0xffda, 0xafff, 0xffff, 0x87ff, 0xfffe, 0x47ff];
1295 static const _schemeTable = const [0x0000, 0x0000, 0x6800, 0x03ff, 0xfffe, 0x07 ff, 0xfffe, 0x07ff]; 1268 static const _schemeTable = const [0x0000, 0x0000, 0x6800, 0x03ff, 0xfffe, 0x07 ff, 0xfffe, 0x07ff];
1296 static const _schemeLowerTable = const [0x0000, 0x0000, 0x6800, 0x03ff, 0x0000, 0x0000, 0xfffe, 0x07ff]; 1269 static const _schemeLowerTable = const [0x0000, 0x0000, 0x6800, 0x03ff, 0x0000, 0x0000, 0xfffe, 0x07ff];
1297 static const _subDelimitersTable = const [0x0000, 0x0000, 0x7fd2, 0x2bff, 0xfff e, 0x87ff, 0xfffe, 0x47ff]; 1270 static const _subDelimitersTable = const [0x0000, 0x0000, 0x7fd2, 0x2bff, 0xfff e, 0x87ff, 0xfffe, 0x47ff];
1298 static const _genDelimitersTable = const [0x0000, 0x0000, 0x8008, 0x8400, 0x000 1, 0x2800, 0x0000, 0x0000]; 1271 static const _genDelimitersTable = const [0x0000, 0x0000, 0x8008, 0x8400, 0x000 1, 0x2800, 0x0000, 0x0000];
1299 static const _userinfoTable = const [0x0000, 0x0000, 0x7fd2, 0x2fff, 0xfffe, 0x 87ff, 0xfffe, 0x47ff]; 1272 static const _userinfoTable = const [0x0000, 0x0000, 0x7fd2, 0x2fff, 0xfffe, 0x 87ff, 0xfffe, 0x47ff];
1300 static const _regNameTable = const [0x0000, 0x0000, 0x7ff2, 0x2bff, 0xfffe, 0x8 7ff, 0xfffe, 0x47ff]; 1273 static const _regNameTable = const [0x0000, 0x0000, 0x7ff2, 0x2bff, 0xfffe, 0x8 7ff, 0xfffe, 0x47ff];
1301 static const _pathCharTable = const [0x0000, 0x0000, 0x7fd2, 0x2fff, 0xffff, 0x 87ff, 0xfffe, 0x47ff]; 1274 static const _pathCharTable = const [0x0000, 0x0000, 0x7fd2, 0x2fff, 0xffff, 0x 87ff, 0xfffe, 0x47ff];
1302 static const _pathCharOrSlashTable = const [0x0000, 0x0000, 0xffd2, 0x2fff, 0xf fff, 0x87ff, 0xfffe, 0x47ff]; 1275 static const _pathCharOrSlashTable = const [0x0000, 0x0000, 0xffd2, 0x2fff, 0xf fff, 0x87ff, 0xfffe, 0x47ff];
1303 static const _queryCharTable = const [0x0000, 0x0000, 0xffd2, 0xafff, 0xffff, 0 x87ff, 0xfffe, 0x47ff]; 1276 static const _queryCharTable = const [0x0000, 0x0000, 0xffd2, 0xafff, 0xffff, 0 x87ff, 0xfffe, 0x47ff];
1304 } 1277 }
OLDNEW
« no previous file with comments | « test/dart_codegen/expect/core/list.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698