diff options
| author | Daniel Patterson <dbp@riseup.net> | 2012-08-01 17:19:43 -0400 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-03 11:28:19 -0700 |
| commit | 64eb497d344d7baab0c23753faca24a41590dab8 (patch) | |
| tree | b3f6d3795533287b218ae72ad4be2f5ff1e4d8c4 /src/libstd | |
| parent | 8e3105b6db6eb30a95061b56e78581dae0a98996 (diff) | |
| download | rust-64eb497d344d7baab0c23753faca24a41590dab8.tar.gz rust-64eb497d344d7baab0c23753faca24a41590dab8.zip | |
std::net::url - eliminate out of date comment and switch to str::each_chari instead of str_reader to make code cleaner
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net_url.rs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index d046dec5225..b3b27d66b1a 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -357,7 +357,6 @@ fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> { } // returns userinfo, host, port, and unparsed part, or an error -// currently doesn't handle IPv6 addresses. fn get_authority(rawurl: ~str) -> result::result<(option<userinfo>, ~str, option<~str>, ~str), @~str> { if !str::starts_with(rawurl, ~"//") { @@ -387,15 +386,9 @@ fn get_authority(rawurl: ~str) -> let mut port : option::option<~str> = option::none; let mut colon_count = 0; - let mut pos : uint = 0, begin : uint = 2; - let mut i : uint = 0; - - let rdr = io::str_reader(rawurl); - let mut c : char; - while !rdr.eof() { - c = rdr.read_byte() as char; - i = rdr.tell() - 1; // we want base 0 + let mut pos : uint = 0, begin : uint = 2, end : uint = len; + for str::each_chari(rawurl) |i,c| { if i < 2 { again; } // ignore the leading // // deal with input class first @@ -487,19 +480,21 @@ fn get_authority(rawurl: ~str) -> } '?' | '#' | '/' { + end = i; break; } _ { } } + end = i; } // finish up alt st { start { - if i+1 == len { - host = str::slice(rawurl, begin, i+1); + if end+1 == len { + host = str::slice(rawurl, begin, end+1); } else { - host = str::slice(rawurl, begin, i); + host = str::slice(rawurl, begin, end); } } pass_host_port | ip6_port { @@ -507,21 +502,21 @@ fn get_authority(rawurl: ~str) -> return result::err(@~"Non-digit characters in port."); } host = str::slice(rawurl, begin, pos); - port = option::some(str::slice(rawurl, pos+1, i)); + port = option::some(str::slice(rawurl, pos+1, end)); } ip6_host | in_host { - host = str::slice(rawurl, begin, i); + host = str::slice(rawurl, begin, end); } in_port { if in != digit { return result::err(@~"Non-digit characters in port."); } - port = option::some(str::slice(rawurl, pos+1, i)); + port = option::some(str::slice(rawurl, pos+1, end)); } } - let rest = if i+1 == len { ~"" } - else { str::slice(rawurl, i, len) }; + let rest = if end+1 == len { ~"" } + else { str::slice(rawurl, end, len) }; return result::ok((userinfo, host, port, rest)); } |
