libstd: convert chained ifs to a match in base64.

This commit is contained in:
Huon Wilson
2013-05-08 23:50:15 +10:00
parent b6f9295654
commit ad5ee00c93

View File

@@ -156,17 +156,13 @@ impl FromBase64 for ~[u8] {
let ch = self[i] as char;
n <<= 6u;
if ch >= 'A' && ch <= 'Z' {
n |= (ch as uint) - 0x41u;
} else if ch >= 'a' && ch <= 'z' {
n |= (ch as uint) - 0x47u;
} else if ch >= '0' && ch <= '9' {
n |= (ch as uint) + 0x04u;
} else if ch == '+' {
n |= 0x3Eu;
} else if ch == '/' {
n |= 0x3Fu;
} else if ch == '=' {
match ch {
'A'..'Z' => n |= (ch as uint) - 0x41,
'a'..'z' => n |= (ch as uint) - 0x47,
'0'..'9' => n |= (ch as uint) + 0x04,
'+' => n |= 0x3E,
'/' => n |= 0x3F,
'=' => {
match len - i {
1u => {
r.push(((n >> 16u) & 0xFFu) as u8);
@@ -179,8 +175,8 @@ impl FromBase64 for ~[u8] {
}
_ => fail!(~"invalid base64 padding")
}
} else {
fail!(~"invalid base64 character");
}
_ => fail!(~"invalid base64 character")
}
i += 1u;