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

Side by Side Diff: sdk/lib/core/uri.dart

Issue 2679933002: Update URI related documentation and examples. (Closed)
Patch Set: Don't escape backslashes in code-quotes. Created 3 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 | « no previous file | tests/corelib/uri_example_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Frequently used character codes. 7 // Frequently used character codes.
8 const int _SPACE = 0x20; 8 const int _SPACE = 0x20;
9 const int _PERCENT = 0x25; 9 const int _PERCENT = 0x25;
10 const int _PLUS = 0x2B; 10 const int _PLUS = 0x2B;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 Map<String, dynamic/*String|Iterable<String>*/> queryParameters, 126 Map<String, dynamic/*String|Iterable<String>*/> queryParameters,
127 String fragment}) = _Uri; 127 String fragment}) = _Uri;
128 128
129 /** 129 /**
130 * Creates a new `http` URI from authority, path and query. 130 * Creates a new `http` URI from authority, path and query.
131 * 131 *
132 * Examples: 132 * Examples:
133 * 133 *
134 * ``` 134 * ```
135 * // http://example.org/path?q=dart. 135 * // http://example.org/path?q=dart.
136 * new Uri.http("google.com", "/search", { "q" : "dart" }); 136 * new Uri.http("example.org", "/path", { "q" : "dart" });
137 * 137 *
138 * // http://user:pass@localhost:8080 138 * // http://user:pass@localhost:8080
139 * new Uri.http("user:pass@localhost:8080", ""); 139 * new Uri.http("user:pass@localhost:8080", "");
140 * 140 *
141 * // http://example.org/a%20b 141 * // http://example.org/a%20b
142 * new Uri.http("example.org", "a b"); 142 * new Uri.http("example.org", "a b");
143 * 143 *
144 * // http://example.org/a%252F 144 * // http://example.org/a%252F
145 * new Uri.http("example.org", "/a%2F"); 145 * new Uri.http("example.org", "/a%2F");
146 * ``` 146 * ```
(...skipping 27 matching lines...) Expand all
174 [Map<String, String> queryParameters]) = _Uri.https; 174 [Map<String, String> queryParameters]) = _Uri.https;
175 175
176 /** 176 /**
177 * Creates a new file URI from an absolute or relative file path. 177 * Creates a new file URI from an absolute or relative file path.
178 * 178 *
179 * The file path is passed in [path]. 179 * The file path is passed in [path].
180 * 180 *
181 * This path is interpreted using either Windows or non-Windows 181 * This path is interpreted using either Windows or non-Windows
182 * semantics. 182 * semantics.
183 * 183 *
184 * With non-Windows semantics the slash ("/") is used to separate 184 * With non-Windows semantics the slash (`/`) is used to separate
185 * path segments. 185 * path segments in the input [path].
186 * 186 *
187 * With Windows semantics, backslash ("\\") and forward-slash ("/") 187 * With Windows semantics, backslash (`\`) and forward-slash (`/`)
188 * are used to separate path segments, except if the path starts 188 * are used to separate path segments in the input [path],
189 * with "\\\\?\\" in which case, only backslash ("\\") separates path 189 * except if the path starts with `\\?\` in which case
190 * segments. 190 * only backslash (`\`) separates path segments in [path].
191 * 191 *
192 * If the path starts with a path separator an absolute URI is 192 * If the path starts with a path separator, an absolute URI (with the
193 * created. Otherwise a relative URI is created. One exception from 193 * `file` scheme and an empty authority) is created.
194 * this rule is that when Windows semantics is used and the path 194 * Otherwise a relative URI reference with no scheme or authority is created.
195 * starts with a drive letter followed by a colon (":") and a 195 * One exception from this rule is that when Windows semantics is used
196 * path separator then an absolute URI is created. 196 * and the path starts with a drive letter followed by a colon (":") and a
197 * path separator, then an absolute URI is created.
197 * 198 *
198 * The default for whether to use Windows or non-Windows semantics 199 * The default for whether to use Windows or non-Windows semantics
199 * determined from the platform Dart is running on. When running in 200 * determined from the platform Dart is running on. When running in
200 * the standalone VM this is detected by the VM based on the 201 * the standalone VM, this is detected by the VM based on the
201 * operating system. When running in a browser non-Windows semantics 202 * operating system. When running in a browser non-Windows semantics
202 * is always used. 203 * is always used.
203 * 204 *
204 * To override the automatic detection of which semantics to use pass 205 * To override the automatic detection of which semantics to use pass
205 * a value for [windows]. Passing `true` will use Windows 206 * a value for [windows]. Passing `true` will use Windows
206 * semantics and passing `false` will use non-Windows semantics. 207 * semantics and passing `false` will use non-Windows semantics.
207 * 208 *
208 * Examples using non-Windows semantics: 209 * Examples using non-Windows semantics:
209 * 210 *
210 * ``` 211 * ```
211 * // xxx/yyy 212 * // xxx/yyy
212 * new Uri.file("xxx/yyy", windows: false); 213 * new Uri.file("xxx/yyy", windows: false);
213 * 214 *
214 * // xxx/yyy/ 215 * // xxx/yyy/
215 * new Uri.file("xxx/yyy/", windows: false); 216 * new Uri.file("xxx/yyy/", windows: false);
216 * 217 *
217 * // file:///xxx/yyy 218 * // file:///xxx/yyy
218 * new Uri.file("/xxx/yyy", windows: false); 219 * new Uri.file("/xxx/yyy", windows: false);
219 * 220 *
220 * // file:///xxx/yyy/ 221 * // file:///xxx/yyy/
221 * new Uri.file("/xxx/yyy/", windows: false); 222 * new Uri.file("/xxx/yyy/", windows: false);
222 * 223 *
223 * // C: 224 * // C%3A
224 * new Uri.file("C:", windows: false); 225 * new Uri.file("C:", windows: false);
225 * ``` 226 * ```
226 * 227 *
227 * Examples using Windows semantics: 228 * Examples using Windows semantics:
228 * 229 *
229 * ``` 230 * ```
230 * // xxx/yyy 231 * // xxx/yyy
231 * new Uri.file(r"xxx\yyy", windows: true); 232 * new Uri.file(r"xxx\yyy", windows: true);
232 * 233 *
233 * // xxx/yyy/ 234 * // xxx/yyy/
234 * new Uri.file(r"xxx\yyy\", windows: true); 235 * new Uri.file(r"xxx\yyy\", windows: true);
235 * 236 *
236 * file:///xxx/yyy 237 * file:///xxx/yyy
237 * new Uri.file(r"\xxx\yyy", windows: true); 238 * new Uri.file(r"\xxx\yyy", windows: true);
238 * 239 *
239 * file:///xxx/yyy/ 240 * file:///xxx/yyy/
240 * new Uri.file(r"\xxx\yyy/", windows: true); 241 * new Uri.file(r"\xxx\yyy/", windows: true);
241 * 242 *
242 * // file:///C:/xxx/yyy 243 * // file:///C:/xxx/yyy
243 * new Uri.file(r"C:\xxx\yyy", windows: true); 244 * new Uri.file(r"C:\xxx\yyy", windows: true);
244 * 245 *
245 * // This throws an error. A path with a drive letter is not absolute. 246 * // This throws an error. A path with a drive letter, but no following
247 * // path, is not allowed.
246 * new Uri.file(r"C:", windows: true); 248 * new Uri.file(r"C:", windows: true);
247 * 249 *
248 * // This throws an error. A path with a drive letter is not absolute. 250 * // This throws an error. A path with a drive letter is not absolute.
249 * new Uri.file(r"C:xxx\yyy", windows: true); 251 * new Uri.file(r"C:xxx\yyy", windows: true);
250 * 252 *
251 * // file://server/share/file 253 * // file://server/share/file
252 * new Uri.file(r"\\server\share\file", windows: true); 254 * new Uri.file(r"\\server\share\file", windows: true);
253 * ``` 255 * ```
254 * 256 *
255 * If the path passed is not a legal file path [ArgumentError] is thrown. 257 * If the path passed is not a valid file path, an error is thrown.
256 */ 258 */
257 factory Uri.file(String path, {bool windows}) = _Uri.file; 259 factory Uri.file(String path, {bool windows}) = _Uri.file;
258 260
259 /** 261 /**
260 * Like [Uri.file] except that a non-empty URI path ends in a slash. 262 * Like [Uri.file] except that a non-empty URI path ends in a slash.
261 * 263 *
262 * If [path] is not empty, and it doesn't end in a directory separator, 264 * If [path] is not empty, and it doesn't end in a directory separator,
263 * then a slash is added to the returned URI's path. 265 * then a slash is added to the returned URI's path.
264 * In all other cases, the result is the same as returned by `Uri.file`. 266 * In all other cases, the result is the same as returned by `Uri.file`.
265 */ 267 */
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 * Uri.parse("file:///xxx/yyy"); // /xxx/yyy 573 * Uri.parse("file:///xxx/yyy"); // /xxx/yyy
572 * Uri.parse("file:///xxx/yyy/"); // /xxx/yyy/ 574 * Uri.parse("file:///xxx/yyy/"); // /xxx/yyy/
573 * Uri.parse("file:///C:"); // /C: 575 * Uri.parse("file:///C:"); // /C:
574 * Uri.parse("file:///C:a"); // /C:a 576 * Uri.parse("file:///C:a"); // /C:a
575 * 577 *
576 * Examples using Windows semantics (resulting URI in comment): 578 * Examples using Windows semantics (resulting URI in comment):
577 * 579 *
578 * Uri.parse("xxx/yyy"); // xxx\yyy 580 * Uri.parse("xxx/yyy"); // xxx\yyy
579 * Uri.parse("xxx/yyy/"); // xxx\yyy\ 581 * Uri.parse("xxx/yyy/"); // xxx\yyy\
580 * Uri.parse("file:///xxx/yyy"); // \xxx\yyy 582 * Uri.parse("file:///xxx/yyy"); // \xxx\yyy
581 * Uri.parse("file:///xxx/yyy/"); // \xxx\yyy/ 583 * Uri.parse("file:///xxx/yyy/"); // \xxx\yyy\
582 * Uri.parse("file:///C:/xxx/yyy"); // C:\xxx\yyy 584 * Uri.parse("file:///C:/xxx/yyy"); // C:\xxx\yyy
583 * Uri.parse("file:C:xxx/yyy"); // Throws as a path segment 585 * Uri.parse("file:C:xxx/yyy"); // Throws as a path segment
584 * // cannot contain colon on Windows. 586 * // cannot contain colon on Windows.
585 * Uri.parse("file://server/share/file"); // \\server\share\file 587 * Uri.parse("file://server/share/file"); // \\server\share\file
586 * 588 *
587 * If the URI is not a file URI calling this throws 589 * If the URI is not a file URI calling this throws
588 * [UnsupportedError]. 590 * [UnsupportedError].
589 * 591 *
590 * If the URI cannot be converted to a file path calling this throws 592 * If the URI cannot be converted to a file path calling this throws
591 * [UnsupportedError]. 593 * [UnsupportedError].
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 * value from this `Uri` instead. 630 * value from this `Uri` instead.
629 * 631 *
630 * This method is different from [Uri.resolve] which overrides in a 632 * This method is different from [Uri.resolve] which overrides in a
631 * hierarchical manner, 633 * hierarchical manner,
632 * and can instead replace each part of a `Uri` individually. 634 * and can instead replace each part of a `Uri` individually.
633 * 635 *
634 * Example: 636 * Example:
635 * 637 *
636 * Uri uri1 = Uri.parse("a://b@c:4/d/e?f#g"); 638 * Uri uri1 = Uri.parse("a://b@c:4/d/e?f#g");
637 * Uri uri2 = uri1.replace(scheme: "A", path: "D/E/E", fragment: "G"); 639 * Uri uri2 = uri1.replace(scheme: "A", path: "D/E/E", fragment: "G");
638 * print(uri2); // prints "A://b@c:4/D/E/E/?f#G" 640 * print(uri2); // prints "a://b@c:4/D/E/E?f#G"
639 * 641 *
640 * This method acts similarly to using the `new Uri` constructor with 642 * This method acts similarly to using the `new Uri` constructor with
641 * some of the arguments taken from this `Uri` . Example: 643 * some of the arguments taken from this `Uri`. Example:
642 * 644 *
643 * Uri uri3 = new Uri( 645 * Uri uri3 = new Uri(
644 * scheme: "A", 646 * scheme: "A",
645 * userInfo: uri1.userInfo, 647 * userInfo: uri1.userInfo,
646 * host: uri1.host, 648 * host: uri1.host,
647 * port: uri1.port, 649 * port: uri1.port,
648 * path: "D/E/E", 650 * path: "D/E/E",
649 * query: uri1.query, 651 * query: uri1.query,
650 * fragment: "G"); 652 * fragment: "G");
651 * print(uri3); // prints "A://b@c:4/D/E/E/?f#G" 653 * print(uri3); // prints "a://b@c:4/D/E/E?f#G"
652 * print(uri2 == uri3); // prints true. 654 * print(uri2 == uri3); // prints true.
653 * 655 *
654 * Using this method can be seen as a shorthand for the `Uri` constructor 656 * Using this method can be seen as a shorthand for the `Uri` constructor
655 * call above, but may also be slightly faster because the parts taken 657 * call above, but may also be slightly faster because the parts taken
656 * from this `Uri` need not be checked for validity again. 658 * from this `Uri` need not be checked for validity again.
657 */ 659 */
658 Uri replace({String scheme, 660 Uri replace({String scheme,
659 String userInfo, 661 String userInfo,
660 String host, 662 String host,
661 int port, 663 int port,
(...skipping 3904 matching lines...) Expand 10 before | Expand all | Expand 10 after
4566 int delta = (text.codeUnitAt(start + 4) ^ _COLON) * 3; 4568 int delta = (text.codeUnitAt(start + 4) ^ _COLON) * 3;
4567 delta |= text.codeUnitAt(start) ^ 0x64 /*d*/; 4569 delta |= text.codeUnitAt(start) ^ 0x64 /*d*/;
4568 delta |= text.codeUnitAt(start + 1) ^ 0x61 /*a*/; 4570 delta |= text.codeUnitAt(start + 1) ^ 0x61 /*a*/;
4569 delta |= text.codeUnitAt(start + 2) ^ 0x74 /*t*/; 4571 delta |= text.codeUnitAt(start + 2) ^ 0x74 /*t*/;
4570 delta |= text.codeUnitAt(start + 3) ^ 0x61 /*a*/; 4572 delta |= text.codeUnitAt(start + 3) ^ 0x61 /*a*/;
4571 return delta; 4573 return delta;
4572 } 4574 }
4573 4575
4574 /// Helper function returning the length of a string, or `0` for `null`. 4576 /// Helper function returning the length of a string, or `0` for `null`.
4575 int _stringOrNullLength(String s) => (s == null) ? 0 : s.length; 4577 int _stringOrNullLength(String s) => (s == null) ? 0 : s.length;
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/uri_example_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698