Make the various from_str functions return options
So that they can be used with user input without causing task failures. Closes #1335
This commit is contained in:
@@ -49,10 +49,13 @@ Failure:
|
||||
String must be a valid IPv4 address
|
||||
*/
|
||||
fn parse_addr(ip: str) -> ip_addr {
|
||||
let parts = vec::map(str::split_byte(ip, "."[0]),
|
||||
{|s| uint::from_str(s) });
|
||||
let parts = vec::map(str::split_byte(ip, "."[0]), {|s|
|
||||
alt uint::from_str(s) {
|
||||
some(n) if n <= 255u { n }
|
||||
_ { fail "Invalid IP Address part." }
|
||||
}
|
||||
});
|
||||
if vec::len(parts) != 4u { fail "Too many dots in IP address"; }
|
||||
for i in parts { if i > 255u { fail "Invalid IP Address part."; } }
|
||||
ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user