| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 char = uri.codeUnitAt(index); | 364 char = uri.codeUnitAt(index); |
| 365 if (char == _QUESTION || char == _NUMBER_SIGN) { | 365 if (char == _QUESTION || char == _NUMBER_SIGN) { |
| 366 break; | 366 break; |
| 367 } | 367 } |
| 368 char = EOI; | 368 char = EOI; |
| 369 } | 369 } |
| 370 state = NOT_IN_PATH; | 370 state = NOT_IN_PATH; |
| 371 } | 371 } |
| 372 | 372 |
| 373 assert(state == NOT_IN_PATH); | 373 assert(state == NOT_IN_PATH); |
| 374 bool ensureLeadingSlash = (host != null || scheme == "file"); | 374 bool isFile = (scheme == "file"); |
| 375 path = _makePath(uri, pathStart, index, null, ensureLeadingSlash); | 375 bool ensureLeadingSlash = host != null; |
| 376 path = _makePath(uri, pathStart, index, null, ensureLeadingSlash, isFile); |
| 376 | 377 |
| 377 if (char == _QUESTION) { | 378 if (char == _QUESTION) { |
| 378 int numberSignIndex = uri.indexOf('#', index + 1); | 379 int numberSignIndex = uri.indexOf('#', index + 1); |
| 379 if (numberSignIndex < 0) { | 380 if (numberSignIndex < 0) { |
| 380 query = _makeQuery(uri, index + 1, uri.length, null); | 381 query = _makeQuery(uri, index + 1, uri.length, null); |
| 381 } else { | 382 } else { |
| 382 query = _makeQuery(uri, index + 1, numberSignIndex, null); | 383 query = _makeQuery(uri, index + 1, numberSignIndex, null); |
| 383 fragment = _makeFragment(uri, numberSignIndex + 1, uri.length); | 384 fragment = _makeFragment(uri, numberSignIndex + 1, uri.length); |
| 384 } | 385 } |
| 385 } else if (char == _NUMBER_SIGN) { | 386 } else if (char == _NUMBER_SIGN) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // Special case this constructor for backwards compatibility. | 488 // Special case this constructor for backwards compatibility. |
| 488 if (query == "") query = null; | 489 if (query == "") query = null; |
| 489 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters); | 490 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters); |
| 490 fragment = _makeFragment(fragment, 0, _stringOrNullLength(fragment)); | 491 fragment = _makeFragment(fragment, 0, _stringOrNullLength(fragment)); |
| 491 port = _makePort(port, scheme); | 492 port = _makePort(port, scheme); |
| 492 bool isFile = (scheme == "file"); | 493 bool isFile = (scheme == "file"); |
| 493 if (host == null && | 494 if (host == null && |
| 494 (userInfo.isNotEmpty || port != null || isFile)) { | 495 (userInfo.isNotEmpty || port != null || isFile)) { |
| 495 host = ""; | 496 host = ""; |
| 496 } | 497 } |
| 497 bool ensureLeadingSlash = (host != null || isFile); | 498 bool ensureLeadingSlash = host != null; |
| 498 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, | 499 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, |
| 499 ensureLeadingSlash); | 500 ensureLeadingSlash, isFile); |
| 500 | |
| 501 return new Uri._internal(scheme, userInfo, host, port, | 501 return new Uri._internal(scheme, userInfo, host, port, |
| 502 path, query, fragment); | 502 path, query, fragment); |
| 503 } | 503 } |
| 504 | 504 |
| 505 /** | 505 /** |
| 506 * Creates a new `http` URI from authority, path and query. | 506 * Creates a new `http` URI from authority, path and query. |
| 507 * | 507 * |
| 508 * Examples: | 508 * Examples: |
| 509 * | 509 * |
| 510 * ``` | 510 * ``` |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 return scheme; | 1011 return scheme; |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 static String _makeUserInfo(String userInfo, int start, int end) { | 1014 static String _makeUserInfo(String userInfo, int start, int end) { |
| 1015 if (userInfo == null) return ""; | 1015 if (userInfo == null) return ""; |
| 1016 return _normalize(userInfo, start, end, _userinfoTable); | 1016 return _normalize(userInfo, start, end, _userinfoTable); |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 static String _makePath(String path, int start, int end, | 1019 static String _makePath(String path, int start, int end, |
| 1020 Iterable<String> pathSegments, | 1020 Iterable<String> pathSegments, |
| 1021 bool ensureLeadingSlash) { | 1021 bool ensureLeadingSlash, |
| 1022 if (path == null && pathSegments == null) return ""; | 1022 bool isFile) { |
| 1023 if (path == null && pathSegments == null) return isFile ? "/" : ""; |
| 1023 if (path != null && pathSegments != null) { | 1024 if (path != null && pathSegments != null) { |
| 1024 throw new ArgumentError('Both path and pathSegments specified'); | 1025 throw new ArgumentError('Both path and pathSegments specified'); |
| 1025 } | 1026 } |
| 1026 var result; | 1027 var result; |
| 1027 if (path != null) { | 1028 if (path != null) { |
| 1028 result = _normalize(path, start, end, _pathCharOrSlashTable); | 1029 result = _normalize(path, start, end, _pathCharOrSlashTable); |
| 1029 } else { | 1030 } else { |
| 1030 result = pathSegments.map((s) => _uriEncode(_pathCharTable, s)).join("/"); | 1031 result = pathSegments.map((s) => _uriEncode(_pathCharTable, s)).join("/"); |
| 1031 } | 1032 } |
| 1032 if (ensureLeadingSlash && result.isNotEmpty && !result.startsWith("/")) { | 1033 if (result.isEmpty) { |
| 1034 if (isFile) return "/"; |
| 1035 } else if ((isFile || ensureLeadingSlash) && |
| 1036 result.codeUnitAt(0) != _SLASH) { |
| 1033 return "/$result"; | 1037 return "/$result"; |
| 1034 } | 1038 } |
| 1035 return result; | 1039 return result; |
| 1036 } | 1040 } |
| 1037 | 1041 |
| 1038 static String _makeQuery(String query, int start, int end, | 1042 static String _makeQuery(String query, int start, int end, |
| 1039 Map<String, String> queryParameters) { | 1043 Map<String, String> queryParameters) { |
| 1040 if (query == null && queryParameters == null) return null; | 1044 if (query == null && queryParameters == null) return null; |
| 1041 if (query != null && queryParameters != null) { | 1045 if (query != null && queryParameters != null) { |
| 1042 throw new ArgumentError('Both query and queryParameters specified'); | 1046 throw new ArgumentError('Both query and queryParameters specified'); |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2254 0xafff, // 0x30 - 0x3f 1111111111110101 | 2258 0xafff, // 0x30 - 0x3f 1111111111110101 |
| 2255 // @ABCDEFGHIJKLMNO | 2259 // @ABCDEFGHIJKLMNO |
| 2256 0xffff, // 0x40 - 0x4f 1111111111111111 | 2260 0xffff, // 0x40 - 0x4f 1111111111111111 |
| 2257 // PQRSTUVWXYZ _ | 2261 // PQRSTUVWXYZ _ |
| 2258 0x87ff, // 0x50 - 0x5f 1111111111100001 | 2262 0x87ff, // 0x50 - 0x5f 1111111111100001 |
| 2259 // abcdefghijklmno | 2263 // abcdefghijklmno |
| 2260 0xfffe, // 0x60 - 0x6f 0111111111111111 | 2264 0xfffe, // 0x60 - 0x6f 0111111111111111 |
| 2261 // pqrstuvwxyz ~ | 2265 // pqrstuvwxyz ~ |
| 2262 0x47ff]; // 0x70 - 0x7f 1111111111100010 | 2266 0x47ff]; // 0x70 - 0x7f 1111111111100010 |
| 2263 } | 2267 } |
| OLD | NEW |