@@ -151,22 +151,21 @@ fn strip_leading_zeros(s: &str) -> Option<&str> {
151151 // anything else is invalid, we return None
152152 _ => return None ,
153153 } ;
154- loop {
155- match char_iter. next ( ) {
156- // continue on more leading zeros
157- Some ( ( _, '0' ) ) => ( ) ,
158- // if we get an underscore we continue - we're "within the number"
159- Some ( ( _, '_' ) ) => ( ) ,
154+ for ( i, c) in char_iter {
155+ match c {
156+ // continue on more leading zeros or if we get an underscore we continue - we're "within the number"
157+ '0' | '_' => ( ) ,
160158 // any other digit we return the rest of the string
161- Some ( ( i , c ) ) if ( '1' ..='9' ) . contains ( & c ) => return Some ( & s[ i..] ) ,
159+ '1' ..='9' => return Some ( & s[ i..] ) ,
162160 // if we get a dot we return the rest of the string but include the last zero
163- Some ( ( i, '.' ) ) => return Some ( & s[ ( i - 1 ) ..] ) ,
164- // if the string is all zeros, we return a single zero
165- None => return Some ( "0" ) ,
161+ '.' => return Some ( & s[ ( i - 1 ) ..] ) ,
166162 // anything else is invalid, we return None
167163 _ => return None ,
168164 }
169165 }
166+ // if the string is all zeros (or underscores), we return the last character
167+ // generally this will be zero, but could be an underscore, which will fail
168+ Some ( & s[ s. len ( ) - 1 ..] )
170169}
171170
172171pub fn float_as_int < ' py > ( input : & ( impl Input < ' py > + ?Sized ) , float : f64 ) -> ValResult < EitherInt < ' py > > {
0 commit comments