@@ -357,7 +357,6 @@ fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> {
357
357
}
358
358
359
359
// returns userinfo, host, port, and unparsed part, or an error
360
- // currently doesn't handle IPv6 addresses.
361
360
fn get_authority ( rawurl : ~str ) ->
362
361
result:: result < ( option < userinfo > , ~str , option < ~str > , ~str ) , @~str > {
363
362
if !str:: starts_with ( rawurl, ~"//") {
@@ -387,15 +386,9 @@ fn get_authority(rawurl: ~str) ->
387
386
let mut port : option:: option < ~str > = option:: none;
388
387
389
388
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;
398
390
391
+ for str:: each_chari( rawurl) |i, c| {
399
392
if i < 2 { again; } // ignore the leading //
400
393
401
394
// deal with input class first
@@ -487,41 +480,43 @@ fn get_authority(rawurl: ~str) ->
487
480
}
488
481
489
482
'?' | '#' | '/' {
483
+ end = i;
490
484
break ;
491
485
}
492
486
_ { }
493
487
}
488
+ end = i;
494
489
}
495
490
496
491
// finish up
497
492
alt st {
498
493
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 ) ;
501
496
} else {
502
- host = str:: slice ( rawurl, begin, i ) ;
497
+ host = str:: slice ( rawurl, begin, end ) ;
503
498
}
504
499
}
505
500
pass_host_port | ip6_port {
506
501
if in != digit {
507
502
return result:: err ( @~"Non -digit characters in port. ") ;
508
503
}
509
504
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 ) ) ;
511
506
}
512
507
ip6_host | in_host {
513
- host = str:: slice ( rawurl, begin, i ) ;
508
+ host = str:: slice ( rawurl, begin, end ) ;
514
509
}
515
510
in_port {
516
511
if in != digit {
517
512
return result:: err ( @~"Non -digit characters in port. ") ;
518
513
}
519
- port = option:: some ( str:: slice ( rawurl, pos+1 , i ) ) ;
514
+ port = option:: some ( str:: slice ( rawurl, pos+1 , end ) ) ;
520
515
}
521
516
}
522
517
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) } ;
525
520
return result:: ok ( ( userinfo, host, port, rest) ) ;
526
521
}
527
522
0 commit comments