This changes the indexing syntax from .() to [], the vector syntax from ~[] to
[] and the extension syntax from #fmt() to #fmt[]
This commit is contained in:
Brian Anderson
2011-08-19 15:16:48 -07:00
parent 4aa165553b
commit 518dc52f85
642 changed files with 6755 additions and 7354 deletions

View File

@@ -2,29 +2,20 @@ import str;
import vec;
import uint;
tag ip_addr {
ipv4(u8, u8, u8, u8);
}
tag ip_addr { ipv4(u8, u8, u8, u8); }
fn format_addr(ip : ip_addr) -> str {
alt(ip) {
fn format_addr(ip: ip_addr) -> str {
alt ip {
ipv4(a, b, c, d) {
#fmt("%u.%u.%u.%u",
a as uint,
b as uint,
c as uint,
d as uint)
#fmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint]
}
_ { fail "Unsupported address type"; }
}
}
fn parse_addr(ip : str) -> ip_addr {
let parts = vec::map(uint::from_str, str::split(ip, ".".(0)));
fn parse_addr(ip: str) -> ip_addr {
let parts = vec::map(uint::from_str, str::split(ip, "."[0]));
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)
ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8)
}