Skip to content

Commit 3f54ca1

Browse files
dhodderalexcrichton
authored andcommitted
Add function doc comments for extra::url::*
1 parent a289587 commit 3f54ca1

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

src/libextra/url.rs

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -139,10 +139,19 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
139139
}
140140

141141
/**
142-
* Encodes a URI by replacing reserved characters with percent encoded
142+
* Encodes a URI by replacing reserved characters with percent-encoded
143143
* character sequences.
144144
*
145145
* 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+
* ```
146155
*/
147156
pub fn encode(s: &str) -> ~str {
148157
encode_inner(s, true)
@@ -206,9 +215,18 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
206215
}
207216

208217
/**
209-
* Decode a string encoded with percent encoding.
218+
* Decodes a percent-encoded string representing a URI.
210219
*
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+
* ```
212230
*/
213231
pub fn decode(s: &str) -> ~str {
214232
decode_inner(s, true)
@@ -410,7 +428,23 @@ pub fn query_to_str(query: &Query) -> ~str {
410428
return strvec.connect("&");
411429
}
412430

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+
*/
414448
pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> {
415449
for (i,c) in rawurl.chars().enumerate() {
416450
match c {
@@ -654,18 +688,16 @@ fn get_query_fragment(rawurl: &str) ->
654688
}
655689

656690
/**
657-
* Parse a `str` to a `url`
691+
* Parses a URL, converting it from a string to `Url` representation.
658692
*
659693
* # Arguments
660694
*
661-
* `rawurl` - a string representing a full url, including scheme.
695+
* `rawurl` - a string representing the full URL, including scheme.
662696
*
663697
* # Returns
664698
*
665-
* a `url` that contains the parsed representation of the url.
666-
*
699+
* A `Url` struct type representing the URL.
667700
*/
668-
669701
pub fn from_str(rawurl: &str) -> Result<Url, ~str> {
670702
// scheme
671703
let (scheme, rest) = match get_scheme(rawurl) {
@@ -705,19 +737,18 @@ impl FromStr for Url {
705737
}
706738

707739
/**
708-
* Format a `url` as a string
740+
* Converts a URL from `Url` to string representation.
709741
*
710742
* # Arguments
711743
*
712-
* `url` - a url.
744+
* `url` - a URL.
713745
*
714746
* # Returns
715747
*
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;
718750
* for example, "http://somehost.com?", when parsed and formatted, will
719751
* result in just "http://somehost.com".
720-
*
721752
*/
722753
pub fn to_str(url: &Url) -> ~str {
723754
let user = match url.user {

0 commit comments

Comments
 (0)