@@ -15,23 +15,23 @@ impl &[u8]: ToBase64 {
15
15
unsafe {
16
16
let len = self . len ( ) ;
17
17
str:: reserve ( & mut s, ( ( len + 3 u) / 4 u) * 3 u) ;
18
-
18
+
19
19
let mut i = 0 u;
20
-
20
+
21
21
while i < len - ( len % 3 u) {
22
22
let n = ( self [ i] as uint ) << 16 u |
23
23
( self [ i + 1 u] as uint ) << 8 u |
24
24
( self [ i + 2 u] as uint ) ;
25
-
25
+
26
26
// This 24-bit number gets separated into four 6-bit numbers.
27
27
str:: push_char ( & mut s, chars[ ( n >> 18 u) & 63 u] ) ;
28
28
str:: push_char ( & mut s, chars[ ( n >> 12 u) & 63 u] ) ;
29
29
str:: push_char ( & mut s, chars[ ( n >> 6 u) & 63 u] ) ;
30
30
str:: push_char ( & mut s, chars[ n & 63 u] ) ;
31
-
31
+
32
32
i += 3 u;
33
33
}
34
-
34
+
35
35
// Heh, would be cool if we knew this was exhaustive
36
36
// (the dream of bounded integer types)
37
37
match len % 3 {
@@ -44,7 +44,8 @@ impl &[u8]: ToBase64 {
44
44
str:: push_char ( & mut s, '=' ) ;
45
45
}
46
46
2 => {
47
- let n = ( self [ i] as uint ) << 16 u | ( self [ i + 1 u] as uint ) << 8 u;
47
+ let n = ( self [ i] as uint ) << 16 u |
48
+ ( self [ i + 1 u] as uint ) << 8 u;
48
49
str:: push_char ( & mut s, chars[ ( n >> 18 u) & 63 u] ) ;
49
50
str:: push_char ( & mut s, chars[ ( n >> 12 u) & 63 u] ) ;
50
51
str:: push_char ( & mut s, chars[ ( n >> 6 u) & 63 u] ) ;
@@ -85,11 +86,11 @@ impl ~[u8]: FromBase64 {
85
86
let mut i = 0 u;
86
87
while i < len {
87
88
let mut n = 0 u;
88
-
89
+
89
90
for iter:: repeat( 4 u) {
90
91
let ch = self [ i] as char ;
91
92
n <<= 6 u;
92
-
93
+
93
94
if ch >= 'A' && ch <= 'Z' {
94
95
n |= ( ch as uint ) - 0x41 u;
95
96
} else if ch >= 'a' && ch <= 'z' {
@@ -116,10 +117,10 @@ impl ~[u8]: FromBase64 {
116
117
} else {
117
118
fail ~"invalid base64 character";
118
119
}
119
-
120
+
120
121
i += 1 u;
121
122
} ;
122
-
123
+
123
124
r. push ( ( ( n >> 16 u) & 0xFF u) as u8 ) ;
124
125
r. push ( ( ( n >> 8 u ) & 0xFF u) as u8 ) ;
125
126
r. push ( ( ( n ) & 0xFF u) as u8 ) ;
0 commit comments