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, such as a URL. | 8 * A parsed URI, such as a URL. |
| 9 * | 9 * |
| 10 * **See also:** | 10 * **See also:** |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 } | 779 } |
| 780 } else { | 780 } else { |
| 781 // Relative URI. | 781 // Relative URI. |
| 782 var pathSegments = path.split(sep); | 782 var pathSegments = path.split(sep); |
| 783 _checkWindowsPathReservedCharacters(pathSegments, true); | 783 _checkWindowsPathReservedCharacters(pathSegments, true); |
| 784 return new Uri(pathSegments: pathSegments); | 784 return new Uri(pathSegments: pathSegments); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 | 787 |
| 788 /** | 788 /** |
| 789 * Returns a new `Uri` based on this one, but with some parts replaced. | |
| 790 * | |
| 791 * This method takes the same parameters as the [new Uri] constructor, | |
| 792 * and they are handled in the same way. | |
| 793 * | |
| 794 * At most one of [path] and [pathSegments] must be provided. | |
| 795 * Likewise, at most one of [query] and [queryParameters] must be provided. | |
| 796 * | |
| 797 * Each part that is not provided will take its value from this `Uri` instead. | |
| 798 * | |
| 799 * This is different from [Uri.resolve] which overrides in a hierarchial | |
| 800 * manner. This method can replace any part | |
| 801 * | |
| 802 * Example: | |
| 803 * | |
| 804 * Uri uri1 = Uri.parse("a://b@c:4/d/e?f#g"); | |
| 805 * Uri uri2 = uri1.replace(scheme: "A", path: "D/E/E", fragment: "G"); | |
| 806 * print(uri2); // prints "A://b@c:4/D/E/E/?f#G" | |
| 807 * | |
| 808 * Using this method is similar to using the `new Uri` constructor with | |
|
Anders Johnsen
2014/07/29 07:13:33
This is the second paragraph mentioning it's simil
Lasse Reichstein Nielsen
2014/08/05 10:30:39
I think it's ok. It really is similar.
I've slight
| |
| 809 * some of the arguments taken from this `Uri` . Example: | |
| 810 * | |
| 811 * Uri uri3 = new Uri( | |
| 812 * scheme: "A", | |
| 813 * userInfo: uri1.userInfo, | |
| 814 * host: uri1.host, | |
| 815 * port: uri1.port, | |
| 816 * path: "D/E/E", | |
| 817 * query: uri1.query, | |
| 818 * fragment: "G"); | |
| 819 * print(uri3); // prints "A://b@c:4/D/E/E/?f#G" | |
| 820 * print(uri2 == uri3); // prints true. | |
| 821 * | |
| 822 * Using this method may be slightly faster than calling the [new Uri] | |
| 823 * constructor as above, because the parts take from this `Uri` do not | |
| 824 * need to be checked for validity again. | |
| 825 */ | |
| 826 Uri replace({String scheme, | |
|
floitsch
2014/06/24 09:15:53
I don't like "replace" it gives the impression tha
Lasse Reichstein Nielsen
2014/06/24 09:25:58
I picked "replace" because we already use it in th
floitsch
2014/06/24 09:32:27
Could we push to make `with` a pseudo-keyword?
But
kustermann
2014/06/25 00:54:38
The Uri class is only one example. I've argued wit
Lasse Reichstein Nielsen
2014/06/26 06:01:31
I like "change" even less than "replace", when it
Anders Johnsen
2014/06/26 08:20:35
What about
Uri.from(Uri uri, {...});
?
kustermann
2014/06/27 20:45:05
It's longer, not nice and will be special for Uri.
kustermann
2014/06/27 20:45:05
Why do you have so many concerns about replace/cha
| |
| 827 String userInfo, | |
| 828 String host, | |
| 829 int port, | |
| 830 String path, | |
| 831 Iterable<String> pathSegments, | |
| 832 String query, | |
| 833 Map<String, String> queryParameters, | |
| 834 String fragment}) { | |
| 835 if (scheme == null) { | |
| 836 scheme = this.scheme; | |
| 837 } else { | |
| 838 scheme = _makeScheme(scheme, scheme.length); | |
| 839 } | |
| 840 if (userInfo == null) { | |
| 841 userInfo = this.userInfo; | |
| 842 } else { | |
| 843 userInfo = _makeUserInfo(userInfo, 0, userInfo.length); | |
| 844 } | |
| 845 if (host == null) { | |
| 846 host = this.host; | |
| 847 } else { | |
| 848 host = _makeHost(host, 0, host.length, false); | |
| 849 } | |
| 850 if (port == null) { | |
| 851 port = this.port; | |
| 852 } | |
| 853 | |
| 854 bool ensureLeadingSlash = (host != "" || scheme == "file"); | |
| 855 if (path == null && pathSegments == null) { | |
| 856 path = this.path; | |
| 857 if (ensureLeadingSlash && !path.isEmpty && !path.startsWith('/')) { | |
| 858 path = "/$path"; | |
| 859 } | |
| 860 } else { | |
| 861 path = _makePath(path, 0, _stringOrNullLength(path), pathSegments, | |
| 862 ensureLeadingSlash); | |
| 863 } | |
| 864 | |
| 865 if (query == null && queryParameters == null) { | |
| 866 query = this.query; | |
| 867 } else { | |
| 868 query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters); | |
| 869 } | |
| 870 | |
| 871 if (fragment == null) { | |
| 872 fragment = this.fragment; | |
| 873 } else { | |
| 874 fragment = _makeFragment(fragment, 0, fragment.length); | |
| 875 } | |
| 876 | |
| 877 return new Uri._internal( | |
| 878 scheme, userInfo, host, port, path, query, fragment); | |
| 879 } | |
| 880 | |
| 881 /** | |
| 789 * Returns the URI path split into its segments. Each of the | 882 * Returns the URI path split into its segments. Each of the |
| 790 * segments in the returned list have been decoded. If the path is | 883 * segments in the returned list have been decoded. If the path is |
| 791 * empty the empty list will be returned. A leading slash `/` does | 884 * empty the empty list will be returned. A leading slash `/` does |
| 792 * not affect the segments returned. | 885 * not affect the segments returned. |
| 793 * | 886 * |
| 794 * The returned list is unmodifiable and will throw [UnsupportedError] on any | 887 * The returned list is unmodifiable and will throw [UnsupportedError] on any |
| 795 * calls that would mutate it. | 888 * calls that would mutate it. |
| 796 */ | 889 */ |
| 797 List<String> get pathSegments { | 890 List<String> get pathSegments { |
| 798 if (_pathSegments == null) { | 891 if (_pathSegments == null) { |
| (...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2195 0xafff, // 0x30 - 0x3f 1111111111110101 | 2288 0xafff, // 0x30 - 0x3f 1111111111110101 |
| 2196 // @ABCDEFGHIJKLMNO | 2289 // @ABCDEFGHIJKLMNO |
| 2197 0xffff, // 0x40 - 0x4f 1111111111111111 | 2290 0xffff, // 0x40 - 0x4f 1111111111111111 |
| 2198 // PQRSTUVWXYZ _ | 2291 // PQRSTUVWXYZ _ |
| 2199 0x87ff, // 0x50 - 0x5f 1111111111100001 | 2292 0x87ff, // 0x50 - 0x5f 1111111111100001 |
| 2200 // abcdefghijklmno | 2293 // abcdefghijklmno |
| 2201 0xfffe, // 0x60 - 0x6f 0111111111111111 | 2294 0xfffe, // 0x60 - 0x6f 0111111111111111 |
| 2202 // pqrstuvwxyz ~ | 2295 // pqrstuvwxyz ~ |
| 2203 0x47ff]; // 0x70 - 0x7f 1111111111100010 | 2296 0x47ff]; // 0x70 - 0x7f 1111111111100010 |
| 2204 } | 2297 } |
| OLD | NEW |