Skip to content

Commit 84f0083

Browse files
committed
---
yaml --- r: 28270 b: refs/heads/try c: 0c2674f h: refs/heads/master v: v3
1 parent 61514df commit 84f0083

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: 5aedabf1a3308925fc6087a93c58f1002ef4c0fa
5+
refs/heads/try: 0c2674f9475d3f45964a4b59e1de39c1731d1cee
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/src/libstd/net_url.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import map;
55
import map::{hashmap, str_hash};
66
import io::{Reader, ReaderUtil};
77
import dvec::DVec;
8+
import from_str::FromStr;
9+
import result::{Err, Ok};
10+
import to_str::ToStr;
811

912
export Url, url, userinfo, query;
1013
export from_str, to_str;
@@ -338,7 +341,7 @@ fn query_to_str(query: Query) -> ~str {
338341
}
339342
340343
// returns the scheme and the rest of the url, or a parsing error
341-
fn get_scheme(rawurl: ~str) -> result::Result<(~str, ~str), @~str> {
344+
fn get_scheme(rawurl: &str) -> result::Result<(~str, ~str), @~str> {
342345
for str::each_chari(rawurl) |i,c| {
343346
match c {
344347
'A' .. 'Z' | 'a' .. 'z' => again,
@@ -384,11 +387,11 @@ impl Input: Eq {
384387
}
385388

386389
// returns userinfo, host, port, and unparsed part, or an error
387-
fn get_authority(rawurl: ~str) ->
390+
fn get_authority(rawurl: &str) ->
388391
result::Result<(Option<UserInfo>, ~str, Option<~str>, ~str), @~str> {
389392
if !str::starts_with(rawurl, ~"//") {
390393
// there is no authority.
391-
return result::Ok((option::None, ~"", option::None, copy rawurl));
394+
return result::Ok((option::None, ~"", option::None, rawurl.to_str()));
392395
}
393396

394397
enum State {
@@ -514,7 +517,7 @@ fn get_authority(rawurl: ~str) ->
514517

515518
let end = end; // make end immutable so it can be captured
516519

517-
let host_is_end_plus_one = || {
520+
let host_is_end_plus_one: &fn() -> bool = || {
518521
end+1 == len
519522
&& !['?', '#', '/'].contains(rawurl[end] as char)
520523
};
@@ -553,7 +556,7 @@ fn get_authority(rawurl: ~str) ->
553556

554557

555558
// returns the path and unparsed part of url, or an error
556-
fn get_path(rawurl: ~str, authority : bool) ->
559+
fn get_path(rawurl: &str, authority : bool) ->
557560
result::Result<(~str, ~str), @~str> {
558561
let len = str::len(rawurl);
559562
let mut end = len;
@@ -584,7 +587,7 @@ fn get_path(rawurl: ~str, authority : bool) ->
584587
}
585588

586589
// returns the parsed query and the fragment, if present
587-
fn get_query_fragment(rawurl: ~str) ->
590+
fn get_query_fragment(rawurl: &str) ->
588591
result::Result<(Query, Option<~str>), @~str> {
589592
if !str::starts_with(rawurl, ~"?") {
590593
if str::starts_with(rawurl, ~"#") {
@@ -616,7 +619,7 @@ fn get_query_fragment(rawurl: ~str) ->
616619
*
617620
*/
618621
619-
fn from_str(rawurl: ~str) -> result::Result<Url, ~str> {
622+
fn from_str(rawurl: &str) -> result::Result<Url, ~str> {
620623
// scheme
621624
let mut schm = get_scheme(rawurl);
622625
if result::is_err(schm) {
@@ -650,6 +653,15 @@ fn from_str(rawurl: ~str) -> result::Result<Url, ~str> {
650653
port, path, query, fragment));
651654
}
652655

656+
impl Url : FromStr {
657+
static fn from_str(s: &str) -> Option<Url> {
658+
match from_str(s) {
659+
Ok(url) => Some(url),
660+
Err(_) => None
661+
}
662+
}
663+
}
664+
653665
/**
654666
* Format a `url` as a string
655667
*

0 commit comments

Comments
 (0)