|
1 |
| -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT |
| 1 | +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
2 | 2 | // file at the top-level directory of this distribution and at
|
3 | 3 | // http://rust-lang.org/COPYRIGHT.
|
4 | 4 | //
|
@@ -139,10 +139,19 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
|
139 | 139 | }
|
140 | 140 |
|
141 | 141 | /**
|
142 |
| - * Encodes a URI by replacing reserved characters with percent encoded |
| 142 | + * Encodes a URI by replacing reserved characters with percent-encoded |
143 | 143 | * character sequences.
|
144 | 144 | *
|
145 | 145 | * This function is compliant with RFC 3986.
|
| 146 | + * |
| 147 | + * # Example |
| 148 | + * |
| 149 | + * ```rust |
| 150 | + * use extra::url::encode; |
| 151 | + * |
| 152 | + * let url = encode(&"https://example.com/Rust (programming language)"); |
| 153 | + * println!("{}", url); // https://example.com/Rust%20(programming%20language) |
| 154 | + * ``` |
146 | 155 | */
|
147 | 156 | pub fn encode(s: &str) -> ~str {
|
148 | 157 | encode_inner(s, true)
|
@@ -206,9 +215,18 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
|
206 | 215 | }
|
207 | 216 |
|
208 | 217 | /**
|
209 |
| - * Decode a string encoded with percent encoding. |
| 218 | + * Decodes a percent-encoded string representing a URI. |
210 | 219 | *
|
211 |
| - * This will only decode escape sequences generated by encode. |
| 220 | + * This will only decode escape sequences generated by `encode`. |
| 221 | + * |
| 222 | + * # Example |
| 223 | + * |
| 224 | + * ```rust |
| 225 | + * use extra::url::decode; |
| 226 | + * |
| 227 | + * let url = decode(&"https://example.com/Rust%20(programming%20language)"); |
| 228 | + * println!("{}", url); // https://example.com/Rust (programming language) |
| 229 | + * ``` |
212 | 230 | */
|
213 | 231 | pub fn decode(s: &str) -> ~str {
|
214 | 232 | decode_inner(s, true)
|
@@ -410,7 +428,23 @@ pub fn query_to_str(query: &Query) -> ~str {
|
410 | 428 | return strvec.connect("&");
|
411 | 429 | }
|
412 | 430 |
|
413 |
| -// returns the scheme and the rest of the url, or a parsing error |
| 431 | +/** |
| 432 | + * Returns a tuple of the URI scheme and the rest of the URI, or a parsing error. |
| 433 | + * |
| 434 | + * Does not include the separating `:` character. |
| 435 | + * |
| 436 | + * # Example |
| 437 | + * |
| 438 | + * ```rust |
| 439 | + * use extra::url::get_scheme; |
| 440 | + * |
| 441 | + * let scheme = match get_scheme("https://example.com/") { |
| 442 | + * Ok((sch, _)) => sch, |
| 443 | + * Err(_) => ~"(None)", |
| 444 | + * }; |
| 445 | + * println!("Scheme in use: {}.", scheme); // Scheme in use: https. |
| 446 | + * ``` |
| 447 | + */ |
414 | 448 | pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> {
|
415 | 449 | for (i,c) in rawurl.chars().enumerate() {
|
416 | 450 | match c {
|
@@ -654,18 +688,16 @@ fn get_query_fragment(rawurl: &str) ->
|
654 | 688 | }
|
655 | 689 |
|
656 | 690 | /**
|
657 |
| - * Parse a `str` to a `url` |
| 691 | + * Parses a URL, converting it from a string to `Url` representation. |
658 | 692 | *
|
659 | 693 | * # Arguments
|
660 | 694 | *
|
661 |
| - * `rawurl` - a string representing a full url, including scheme. |
| 695 | + * `rawurl` - a string representing the full URL, including scheme. |
662 | 696 | *
|
663 | 697 | * # Returns
|
664 | 698 | *
|
665 |
| - * a `url` that contains the parsed representation of the url. |
666 |
| - * |
| 699 | + * A `Url` struct type representing the URL. |
667 | 700 | */
|
668 |
| - |
669 | 701 | pub fn from_str(rawurl: &str) -> Result<Url, ~str> {
|
670 | 702 | // scheme
|
671 | 703 | let (scheme, rest) = match get_scheme(rawurl) {
|
@@ -705,19 +737,18 @@ impl FromStr for Url {
|
705 | 737 | }
|
706 | 738 |
|
707 | 739 | /**
|
708 |
| - * Format a `url` as a string |
| 740 | + * Converts a URL from `Url` to string representation. |
709 | 741 | *
|
710 | 742 | * # Arguments
|
711 | 743 | *
|
712 |
| - * `url` - a url. |
| 744 | + * `url` - a URL. |
713 | 745 | *
|
714 | 746 | * # Returns
|
715 | 747 | *
|
716 |
| - * a `str` that contains the formatted url. Note that this will usually |
717 |
| - * be an inverse of `from_str` but might strip out unneeded separators. |
| 748 | + * A string that contains the formatted URL. Note that this will usually |
| 749 | + * be an inverse of `from_str` but might strip out unneeded separators; |
718 | 750 | * for example, "http://somehost.com?", when parsed and formatted, will
|
719 | 751 | * result in just "http://somehost.com".
|
720 |
| - * |
721 | 752 | */
|
722 | 753 | pub fn to_str(url: &Url) -> ~str {
|
723 | 754 | let user = match url.user {
|
|
0 commit comments