File tree 6 files changed +41
-11
lines changed
6 files changed +41
-11
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 4739942e7415d89425453d25427c51f96328c52b
2
+ refs/heads/master: 80c926c5e253d6db299698cfd4932dbcb61cd1bd
Original file line number Diff line number Diff line change @@ -93,3 +93,12 @@ pure fn is_whitespace(c: char) -> bool {
93
93
true
94
94
} else if c == ch_no_break_space { true } else { false }
95
95
}
96
+
97
+ pure fn to_digit ( c : char ) -> u8 {
98
+ alt c {
99
+ '0' to ' 9 ' { c as u8 - ( '0' as u8 ) }
100
+ 'a' to 'z' { c as u8 + 10u8 - ( 'a' as u8 ) }
101
+ 'A' to 'Z' { c as u8 + 10u8 - ( 'A' as u8 ) }
102
+ _ { fail; }
103
+ }
104
+ }
Original file line number Diff line number Diff line change @@ -112,11 +112,7 @@ fn parse_buf(buf: [u8], radix: uint) -> int {
112
112
}
113
113
let n = 0 ;
114
114
while true {
115
- let digit = alt buf[ i] as char {
116
- '0' to '9' { buf[ i] - ( '0' as u8 ) }
117
- 'a' to 'z' { 10u8 + buf[ i] - ( 'a' as u8 ) }
118
- 'A' to 'Z' { 10u8 + buf[ i] - ( 'A' as u8 ) }
119
- } ;
115
+ let digit = char:: to_digit ( buf[ i] as char ) ;
120
116
if ( digit as uint ) >= radix {
121
117
fail;
122
118
}
Original file line number Diff line number Diff line change @@ -100,11 +100,7 @@ fn parse_buf(buf: [u8], radix: uint) -> uint {
100
100
let power = 1 u;
101
101
let n = 0 u;
102
102
while true {
103
- let digit = alt buf[ i] as char {
104
- '0' to '9' { buf[ i] - ( '0' as u8 ) }
105
- 'a' to 'z' { 10u8 + buf[ i] - ( 'a' as u8 ) }
106
- 'A' to 'Z' { 10u8 + buf[ i] - ( 'A' as u8 ) }
107
- } ;
103
+ let digit = char:: to_digit ( buf[ i] as char ) ;
108
104
if ( digit as uint ) >= radix {
109
105
fail;
110
106
}
Original file line number Diff line number Diff line change
1
+ use std;
2
+ import std:: char;
3
+
4
+ #[ test]
5
+ fn test_is_whitespace ( ) {
6
+ assert char:: is_whitespace ( ' ' ) ;
7
+ assert char:: is_whitespace ( '\u2007' ) ;
8
+ assert char:: is_whitespace ( '\t' ) ;
9
+ assert char:: is_whitespace ( '\n' ) ;
10
+
11
+ assert !char:: is_whitespace ( 'a' ) ;
12
+ assert !char:: is_whitespace ( '_' ) ;
13
+ assert !char:: is_whitespace ( '\u0000' ) ;
14
+ }
15
+
16
+ #[ test]
17
+ fn test_to_digit ( ) {
18
+ assert ( char:: to_digit ( '0' ) == 0u8 ) ;
19
+ assert ( char:: to_digit ( '1' ) == 1u8 ) ;
20
+ assert ( char:: to_digit ( '2' ) == 2u8 ) ;
21
+ assert ( char:: to_digit ( '9' ) == 9u8 ) ;
22
+ assert ( char:: to_digit ( 'a' ) == 10u8 ) ;
23
+ assert ( char:: to_digit ( 'A' ) == 10u8 ) ;
24
+ assert ( char:: to_digit ( 'b' ) == 11u8 ) ;
25
+ assert ( char:: to_digit ( 'B' ) == 11u8 ) ;
26
+ assert ( char:: to_digit ( 'z' ) == 35u8 ) ;
27
+ assert ( char:: to_digit ( 'Z' ) == 35u8 ) ;
28
+ }
Original file line number Diff line number Diff line change 2
2
3
3
mod bitv;
4
4
mod box;
5
+ mod char;
5
6
mod comm;
6
7
mod deque;
7
8
mod either;
You can’t perform that action at this time.
0 commit comments