Chromium Code Reviews| 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, as specified by RFC-3986, http://tools.ietf.org/html/rfc3986. | 8 * A parsed URI, as specified by RFC-3986, http://tools.ietf.org/html/rfc3986. |
| 9 */ | 9 */ |
| 10 class Uri { | 10 class Uri { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 return _host.substring(1, _host.length - 1); | 56 return _host.substring(1, _host.length - 1); |
| 57 } | 57 } |
| 58 return _host; | 58 return _host; |
| 59 } | 59 } |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Returns the port part of the authority component. | 62 * Returns the port part of the authority component. |
| 63 * | 63 * |
| 64 * Returns 0 if there is no port in the authority component. | 64 * Returns 0 if there is no port in the authority component. |
| 65 */ | 65 */ |
| 66 int get port => _port; | 66 int get port { |
| 67 if (_port == 0) { | |
| 68 if (scheme == "http") return 80; | |
| 69 if (scheme == "https") return 443; | |
| 70 } | |
| 71 return _port; | |
| 72 } | |
| 67 | 73 |
| 68 /** | 74 /** |
| 69 * Returns the path component. | 75 * Returns the path component. |
| 70 * | 76 * |
| 71 * The returned path is encoded. To get direct access to the decoded | 77 * The returned path is encoded. To get direct access to the decoded |
| 72 * path use [pathSegments]. | 78 * path use [pathSegments]. |
| 73 * | 79 * |
| 74 * Returns the empty string if there is no path component. | 80 * Returns the empty string if there is no path component. |
| 75 */ | 81 */ |
| 76 String get path => _path; | 82 String get path => _path; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 100 * Cache the computed return value of [queryParameters]. | 106 * Cache the computed return value of [queryParameters]. |
| 101 */ | 107 */ |
| 102 Map<String, String> _queryParameters; | 108 Map<String, String> _queryParameters; |
| 103 | 109 |
| 104 /** | 110 /** |
| 105 * Creates a new URI object by parsing a URI string. | 111 * Creates a new URI object by parsing a URI string. |
| 106 */ | 112 */ |
| 107 static Uri parse(String uri) => new Uri._fromMatch(_splitRe.firstMatch(uri)); | 113 static Uri parse(String uri) => new Uri._fromMatch(_splitRe.firstMatch(uri)); |
| 108 | 114 |
| 109 Uri._fromMatch(Match m) : | 115 Uri._fromMatch(Match m) : |
| 110 this(scheme: _emptyIfNull(m[_COMPONENT_SCHEME]), | 116 this(scheme: _makeScheme(_emptyIfNull(m[_COMPONENT_SCHEME])), |
|
Søren Gjesse
2013/09/12 09:52:03
With this change the previous change to the RegExp
Anders Johnsen
2013/09/12 10:53:53
Done.
| |
| 111 userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]), | 117 userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]), |
| 112 host: _eitherOf( | 118 host: _eitherOf( |
| 113 m[_COMPONENT_HOST], m[_COMPONENT_HOST_IPV6]), | 119 m[_COMPONENT_HOST], m[_COMPONENT_HOST_IPV6]), |
| 114 port: _parseIntOrZero(m[_COMPONENT_PORT]), | 120 port: _parseIntOrZero(m[_COMPONENT_PORT]), |
| 115 path: _emptyIfNull(m[_COMPONENT_PATH]), | 121 path: _emptyIfNull(m[_COMPONENT_PATH]), |
| 116 query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]), | 122 query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]), |
| 117 fragment: _emptyIfNull(m[_COMPONENT_FRAGMENT])); | 123 fragment: _emptyIfNull(m[_COMPONENT_FRAGMENT])); |
| 118 | 124 |
| 119 /** | 125 /** |
| 120 * Creates a new URI from its components. | 126 * Creates a new URI from its components. |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 * See: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin | 874 * See: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin |
| 869 */ | 875 */ |
| 870 String get origin { | 876 String get origin { |
| 871 if (scheme == "" || _host == null || _host == "") { | 877 if (scheme == "" || _host == null || _host == "") { |
| 872 throw new StateError("Cannot use origin without a scheme: $this"); | 878 throw new StateError("Cannot use origin without a scheme: $this"); |
| 873 } | 879 } |
| 874 if (scheme != "http" && scheme != "https") { | 880 if (scheme != "http" && scheme != "https") { |
| 875 throw new StateError( | 881 throw new StateError( |
| 876 "Origin is only applicable schemes http and https: $this"); | 882 "Origin is only applicable schemes http and https: $this"); |
| 877 } | 883 } |
| 878 if (port == 0) return "$scheme://$_host"; | 884 if (_port == 0) return "$scheme://$_host"; |
| 879 return "$scheme://$_host:$port"; | 885 return "$scheme://$_host:$_port"; |
| 880 } | 886 } |
| 881 | 887 |
| 882 /** | 888 /** |
| 883 * Returns the file path from a file URI. | 889 * Returns the file path from a file URI. |
| 884 * | 890 * |
| 885 * The returned path has either Windows or non-Windows | 891 * The returned path has either Windows or non-Windows |
| 886 * semantics. | 892 * semantics. |
| 887 * | 893 * |
| 888 * For non-Windows semantics the slash ("/") is used to separate | 894 * For non-Windows semantics the slash ("/") is used to separate |
| 889 * path segments. | 895 * path segments. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 } | 1007 } |
| 1002 | 1008 |
| 1003 bool get _isPathAbsolute { | 1009 bool get _isPathAbsolute { |
| 1004 if (path == null || path.isEmpty) return false; | 1010 if (path == null || path.isEmpty) return false; |
| 1005 return path.startsWith('/'); | 1011 return path.startsWith('/'); |
| 1006 } | 1012 } |
| 1007 | 1013 |
| 1008 void _writeAuthority(StringSink ss) { | 1014 void _writeAuthority(StringSink ss) { |
| 1009 _addIfNonEmpty(ss, userInfo, userInfo, "@"); | 1015 _addIfNonEmpty(ss, userInfo, userInfo, "@"); |
| 1010 ss.write(_host == null ? "null" : _host); | 1016 ss.write(_host == null ? "null" : _host); |
| 1011 if (port != 0) { | 1017 if (_port != 0) { |
| 1012 ss.write(":"); | 1018 ss.write(":"); |
| 1013 ss.write(port.toString()); | 1019 ss.write(_port.toString()); |
| 1014 } | 1020 } |
| 1015 } | 1021 } |
| 1016 | 1022 |
| 1017 String toString() { | 1023 String toString() { |
| 1018 StringBuffer sb = new StringBuffer(); | 1024 StringBuffer sb = new StringBuffer(); |
| 1019 _addIfNonEmpty(sb, scheme, scheme, ':'); | 1025 _addIfNonEmpty(sb, scheme, scheme, ':'); |
| 1020 if (hasAuthority || (scheme == "file")) { | 1026 if (hasAuthority || (scheme == "file")) { |
| 1021 sb.write("//"); | 1027 sb.write("//"); |
| 1022 _writeAuthority(sb); | 1028 _writeAuthority(sb); |
| 1023 } | 1029 } |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 void clear() { | 1646 void clear() { |
| 1641 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 1647 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 1642 } | 1648 } |
| 1643 void forEach(void f(K key, V value)) => _map.forEach(f); | 1649 void forEach(void f(K key, V value)) => _map.forEach(f); |
| 1644 Iterable<K> get keys => _map.keys; | 1650 Iterable<K> get keys => _map.keys; |
| 1645 Iterable<V> get values => _map.values; | 1651 Iterable<V> get values => _map.values; |
| 1646 int get length => _map.length; | 1652 int get length => _map.length; |
| 1647 bool get isEmpty => _map.isEmpty; | 1653 bool get isEmpty => _map.isEmpty; |
| 1648 bool get isNotEmpty => _map.isNotEmpty; | 1654 bool get isNotEmpty => _map.isNotEmpty; |
| 1649 } | 1655 } |
| OLD | NEW |