Skip to content

Commit 101d4bf

Browse files
committed
auto merge of #6332 : huonw/rust/std-base64-match, r=nikomatsakis
2 parents 3bbbb31 + ad5ee00 commit 101d4bf

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/libstd/base64.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,27 @@ impl FromBase64 for ~[u8] {
156156
let ch = self[i] as char;
157157
n <<= 6u;
158158
159-
if ch >= 'A' && ch <= 'Z' {
160-
n |= (ch as uint) - 0x41u;
161-
} else if ch >= 'a' && ch <= 'z' {
162-
n |= (ch as uint) - 0x47u;
163-
} else if ch >= '0' && ch <= '9' {
164-
n |= (ch as uint) + 0x04u;
165-
} else if ch == '+' {
166-
n |= 0x3Eu;
167-
} else if ch == '/' {
168-
n |= 0x3Fu;
169-
} else if ch == '=' {
170-
match len - i {
171-
1u => {
172-
r.push(((n >> 16u) & 0xFFu) as u8);
173-
r.push(((n >> 8u ) & 0xFFu) as u8);
174-
return copy r;
175-
}
176-
2u => {
177-
r.push(((n >> 10u) & 0xFFu) as u8);
178-
return copy r;
179-
}
180-
_ => fail!(~"invalid base64 padding")
159+
match ch {
160+
'A'..'Z' => n |= (ch as uint) - 0x41,
161+
'a'..'z' => n |= (ch as uint) - 0x47,
162+
'0'..'9' => n |= (ch as uint) + 0x04,
163+
'+' => n |= 0x3E,
164+
'/' => n |= 0x3F,
165+
'=' => {
166+
match len - i {
167+
1u => {
168+
r.push(((n >> 16u) & 0xFFu) as u8);
169+
r.push(((n >> 8u ) & 0xFFu) as u8);
170+
return copy r;
171+
}
172+
2u => {
173+
r.push(((n >> 10u) & 0xFFu) as u8);
174+
return copy r;
175+
}
176+
_ => fail!(~"invalid base64 padding")
177+
}
181178
}
182-
} else {
183-
fail!(~"invalid base64 character");
179+
_ => fail!(~"invalid base64 character")
184180
}
185181
186182
i += 1u;

0 commit comments

Comments
 (0)