Skip to content

Commit 64eb497

Browse files
Daniel Pattersonbrson
authored andcommitted
std::net::url - eliminate out of date comment and switch to str::each_chari instead of str_reader to make code cleaner
1 parent 8e3105b commit 64eb497

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/libstd/net_url.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> {
357357
}
358358

359359
// returns userinfo, host, port, and unparsed part, or an error
360-
// currently doesn't handle IPv6 addresses.
361360
fn get_authority(rawurl: ~str) ->
362361
result::result<(option<userinfo>, ~str, option<~str>, ~str), @~str> {
363362
if !str::starts_with(rawurl, ~"//") {
@@ -387,15 +386,9 @@ fn get_authority(rawurl: ~str) ->
387386
let mut port : option::option<~str> = option::none;
388387

389388
let mut colon_count = 0;
390-
let mut pos : uint = 0, begin : uint = 2;
391-
let mut i : uint = 0;
392-
393-
let rdr = io::str_reader(rawurl);
394-
let mut c : char;
395-
while !rdr.eof() {
396-
c = rdr.read_byte() as char;
397-
i = rdr.tell() - 1; // we want base 0
389+
let mut pos : uint = 0, begin : uint = 2, end : uint = len;
398390

391+
for str::each_chari(rawurl) |i,c| {
399392
if i < 2 { again; } // ignore the leading //
400393

401394
// deal with input class first
@@ -487,41 +480,43 @@ fn get_authority(rawurl: ~str) ->
487480
}
488481

489482
'?' | '#' | '/' {
483+
end = i;
490484
break;
491485
}
492486
_ { }
493487
}
488+
end = i;
494489
}
495490

496491
// finish up
497492
alt st {
498493
start {
499-
if i+1 == len {
500-
host = str::slice(rawurl, begin, i+1);
494+
if end+1 == len {
495+
host = str::slice(rawurl, begin, end+1);
501496
} else {
502-
host = str::slice(rawurl, begin, i);
497+
host = str::slice(rawurl, begin, end);
503498
}
504499
}
505500
pass_host_port | ip6_port {
506501
if in != digit {
507502
return result::err(@~"Non-digit characters in port.");
508503
}
509504
host = str::slice(rawurl, begin, pos);
510-
port = option::some(str::slice(rawurl, pos+1, i));
505+
port = option::some(str::slice(rawurl, pos+1, end));
511506
}
512507
ip6_host | in_host {
513-
host = str::slice(rawurl, begin, i);
508+
host = str::slice(rawurl, begin, end);
514509
}
515510
in_port {
516511
if in != digit {
517512
return result::err(@~"Non-digit characters in port.");
518513
}
519-
port = option::some(str::slice(rawurl, pos+1, i));
514+
port = option::some(str::slice(rawurl, pos+1, end));
520515
}
521516
}
522517

523-
let rest = if i+1 == len { ~"" }
524-
else { str::slice(rawurl, i, len) };
518+
let rest = if end+1 == len { ~"" }
519+
else { str::slice(rawurl, end, len) };
525520
return result::ok((userinfo, host, port, rest));
526521
}
527522

0 commit comments

Comments
 (0)