File tree 1 file changed +20
-5
lines changed
1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -122,12 +122,27 @@ impl char {
122
122
#[ inline]
123
123
pub fn to_digit ( self , radix : u32 ) -> Option < u32 > {
124
124
assert ! ( radix <= 36 , "to_digit: radix is too high (maximum 36)" ) ;
125
- let val = match self {
126
- '0' ..= '9' => self as u32 - '0' as u32 ,
127
- 'a' ..= 'z' => self as u32 - 'a' as u32 + 10 ,
128
- 'A' ..= 'Z' => self as u32 - 'A' as u32 + 10 ,
129
- _ => return None ,
125
+ if radix == 10 {
126
+ return match self {
127
+ '0' ..= '9' => Some ( self as u32 - '0' as u32 ) ,
128
+ _ => None ,
129
+ } ;
130
+ }
131
+
132
+ let val = if radix < 10 {
133
+ match self {
134
+ '0' ..= '9' => self as u32 - '0' as u32 ,
135
+ _ => return None ,
136
+ }
137
+ } else {
138
+ match self {
139
+ '0' ..='9' => self as u32 - '0' as u32 ,
140
+ 'a' ..='z' => self as u32 - 'a' as u32 + 10 ,
141
+ 'A' ..='Z' => self as u32 - 'A' as u32 + 10 ,
142
+ _ => return None ,
143
+ }
130
144
} ;
145
+
131
146
if val < radix { Some ( val) }
132
147
else { None }
133
148
}
You can’t perform that action at this time.
0 commit comments