| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A parsed URI, such as a URL. | 8 * A parsed URI, such as a URL. |
| 9 * | 9 * |
| 10 * **See also:** | 10 * **See also:** |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 if (argumentError) { | 746 if (argumentError) { |
| 747 throw new ArgumentError("Illegal drive letter " + | 747 throw new ArgumentError("Illegal drive letter " + |
| 748 new String.fromCharCode(charCode)); | 748 new String.fromCharCode(charCode)); |
| 749 } else { | 749 } else { |
| 750 throw new UnsupportedError("Illegal drive letter " + | 750 throw new UnsupportedError("Illegal drive letter " + |
| 751 new String.fromCharCode(charCode)); | 751 new String.fromCharCode(charCode)); |
| 752 } | 752 } |
| 753 } | 753 } |
| 754 | 754 |
| 755 static _makeFileUri(String path) { | 755 static _makeFileUri(String path) { |
| 756 String sep = "/"; | 756 const String sep = "/"; |
| 757 if (path.startsWith(sep)) { | 757 if (path.startsWith(sep)) { |
| 758 // Absolute file:// URI. | 758 // Absolute file:// URI. |
| 759 return new Uri(scheme: "file", pathSegments: path.split(sep)); | 759 return new Uri(scheme: "file", pathSegments: path.split(sep)); |
| 760 } else { | 760 } else { |
| 761 // Relative URI. | 761 // Relative URI. |
| 762 return new Uri(pathSegments: path.split(sep)); | 762 return new Uri(pathSegments: path.split(sep)); |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 | 765 |
| 766 static _makeWindowsFileUrl(String path) { | 766 static _makeWindowsFileUrl(String path) { |
| 767 if (path.startsWith("\\\\?\\")) { | 767 if (path.startsWith(r"\\?\")) { |
| 768 if (path.startsWith("\\\\?\\UNC\\")) { | 768 if (path.startsWith(r"UNC\", 4)) { |
| 769 path = "\\${path.substring(7)}"; | 769 path = path.replaceRange(0, 7, r'\'); |
| 770 } else { | 770 } else { |
| 771 path = path.substring(4); | 771 path = path.substring(4); |
| 772 if (path.length < 3 || | 772 if (path.length < 3 || |
| 773 path.codeUnitAt(1) != _COLON || | 773 path.codeUnitAt(1) != _COLON || |
| 774 path.codeUnitAt(2) != _BACKSLASH) { | 774 path.codeUnitAt(2) != _BACKSLASH) { |
| 775 throw new ArgumentError( | 775 throw new ArgumentError( |
| 776 "Windows paths with \\\\?\\ prefix must be absolute"); | 776 r"Windows paths with \\?\ prefix must be absolute"); |
| 777 } | 777 } |
| 778 } | 778 } |
| 779 } else { | 779 } else { |
| 780 path = path.replaceAll("/", "\\"); | 780 path = path.replaceAll("/", r'\'); |
| 781 } | 781 } |
| 782 String sep = "\\"; | 782 const String sep = r'\'; |
| 783 if (path.length > 1 && path[1] == ":") { | 783 if (path.length > 1 && path.codeUnitAt(1) == _COLON) { |
| 784 _checkWindowsDriveLetter(path.codeUnitAt(0), true); | 784 _checkWindowsDriveLetter(path.codeUnitAt(0), true); |
| 785 if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) { | 785 if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) { |
| 786 throw new ArgumentError( | 786 throw new ArgumentError( |
| 787 "Windows paths with drive letter must be absolute"); | 787 "Windows paths with drive letter must be absolute"); |
| 788 } | 788 } |
| 789 // Absolute file://C:/ URI. | 789 // Absolute file://C:/ URI. |
| 790 var pathSegments = path.split(sep); | 790 var pathSegments = path.split(sep); |
| 791 _checkWindowsPathReservedCharacters(pathSegments, true, 1); | 791 _checkWindowsPathReservedCharacters(pathSegments, true, 1); |
| 792 return new Uri(scheme: "file", pathSegments: pathSegments); | 792 return new Uri(scheme: "file", pathSegments: pathSegments); |
| 793 } | 793 } |
| 794 | 794 |
| 795 if (path.length > 0 && path[0] == sep) { | 795 if (path.startsWith(sep)) { |
| 796 if (path.length > 1 && path[1] == sep) { | 796 if (path.startsWith(sep, 1)) { |
| 797 // Absolute file:// URI with host. | 797 // Absolute file:// URI with host. |
| 798 int pathStart = path.indexOf("\\", 2); | 798 int pathStart = path.indexOf(r'\', 2); |
| 799 String hostPart = | 799 String hostPart = |
| 800 pathStart == -1 ? path.substring(2) : path.substring(2, pathStart); | 800 (pathStart < 0) ? path.substring(2) : path.substring(2, pathStart); |
| 801 String pathPart = | 801 String pathPart = |
| 802 pathStart == -1 ? "" : path.substring(pathStart + 1); | 802 (pathStart < 0) ? "" : path.substring(pathStart + 1); |
| 803 var pathSegments = pathPart.split(sep); | 803 var pathSegments = pathPart.split(sep); |
| 804 _checkWindowsPathReservedCharacters(pathSegments, true); | 804 _checkWindowsPathReservedCharacters(pathSegments, true); |
| 805 return new Uri( | 805 return new Uri( |
| 806 scheme: "file", host: hostPart, pathSegments: pathSegments); | 806 scheme: "file", host: hostPart, pathSegments: pathSegments); |
| 807 } else { | 807 } else { |
| 808 // Absolute file:// URI. | 808 // Absolute file:// URI. |
| 809 var pathSegments = path.split(sep); | 809 var pathSegments = path.split(sep); |
| 810 _checkWindowsPathReservedCharacters(pathSegments, true); | 810 _checkWindowsPathReservedCharacters(pathSegments, true); |
| 811 return new Uri(scheme: "file", pathSegments: pathSegments); | 811 return new Uri(scheme: "file", pathSegments: pathSegments); |
| 812 } | 812 } |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 // If we see a "." or ".." segment in base, stop here and let | 1380 // If we see a "." or ".." segment in base, stop here and let |
| 1381 // _removeDotSegments handle it. | 1381 // _removeDotSegments handle it. |
| 1382 if ((delta == 2 || delta == 3) && | 1382 if ((delta == 2 || delta == 3) && |
| 1383 base.codeUnitAt(newEnd + 1) == _DOT && | 1383 base.codeUnitAt(newEnd + 1) == _DOT && |
| 1384 (delta == 2 || base.codeUnitAt(newEnd + 2) == _DOT)) { | 1384 (delta == 2 || base.codeUnitAt(newEnd + 2) == _DOT)) { |
| 1385 break; | 1385 break; |
| 1386 } | 1386 } |
| 1387 baseEnd = newEnd; | 1387 baseEnd = newEnd; |
| 1388 backCount--; | 1388 backCount--; |
| 1389 } | 1389 } |
| 1390 return base.substring(0, baseEnd + 1) + | 1390 return base.replaceRange(baseEnd + 1, null, |
| 1391 reference.substring(refStart - 3 * backCount); | 1391 reference.substring(refStart - 3 * backCount)); |
| 1392 } | 1392 } |
| 1393 | 1393 |
| 1394 bool _hasDotSegments(String path) { | 1394 bool _hasDotSegments(String path) { |
| 1395 if (path.length > 0 && path.codeUnitAt(0) == _DOT) return true; | 1395 if (path.length > 0 && path.codeUnitAt(0) == _DOT) return true; |
| 1396 int index = path.indexOf("/."); | 1396 int index = path.indexOf("/."); |
| 1397 return index != -1; | 1397 return index != -1; |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 String _removeDotSegments(String path) { | 1400 String _removeDotSegments(String path) { |
| 1401 if (!_hasDotSegments(path)) return path; | 1401 if (!_hasDotSegments(path)) return path; |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2398 0xafff, // 0x30 - 0x3f 1111111111110101 | 2398 0xafff, // 0x30 - 0x3f 1111111111110101 |
| 2399 // @ABCDEFGHIJKLMNO | 2399 // @ABCDEFGHIJKLMNO |
| 2400 0xffff, // 0x40 - 0x4f 1111111111111111 | 2400 0xffff, // 0x40 - 0x4f 1111111111111111 |
| 2401 // PQRSTUVWXYZ _ | 2401 // PQRSTUVWXYZ _ |
| 2402 0x87ff, // 0x50 - 0x5f 1111111111100001 | 2402 0x87ff, // 0x50 - 0x5f 1111111111100001 |
| 2403 // abcdefghijklmno | 2403 // abcdefghijklmno |
| 2404 0xfffe, // 0x60 - 0x6f 0111111111111111 | 2404 0xfffe, // 0x60 - 0x6f 0111111111111111 |
| 2405 // pqrstuvwxyz ~ | 2405 // pqrstuvwxyz ~ |
| 2406 0x47ff]; // 0x70 - 0x7f 1111111111100010 | 2406 0x47ff]; // 0x70 - 0x7f 1111111111100010 |
| 2407 } | 2407 } |
| OLD | NEW |