@@ -114,8 +114,13 @@ fn clean_int_str(mut s: &str) -> Option<Cow<str>> {
114
114
// strip leading and trailing whitespace
115
115
s = s. trim ( ) ;
116
116
117
- // strip leading unary plus
118
- s = s. strip_prefix ( '+' ) . unwrap_or ( s) ;
117
+ // Check for and remove a leading unary plus and ensure the next character is not a unary minus. e.g.: '+-1'.
118
+ if let Some ( suffix) = s. strip_prefix ( '+' ) {
119
+ if suffix. starts_with ( '-' ) {
120
+ return None ;
121
+ }
122
+ s = suffix;
123
+ }
119
124
120
125
// strip loading zeros
121
126
s = strip_leading_zeros ( s) ?;
@@ -149,17 +154,17 @@ fn strip_leading_zeros(s: &str) -> Option<&str> {
149
154
match char_iter. next ( ) {
150
155
// if we get a leading zero we continue
151
156
Some ( ( _, '0' ) ) => ( ) ,
152
- // if we get another digit we return the whole string
153
- Some ( ( _, c) ) if ( '1' ..='9' ) . contains ( & c) => return Some ( s) ,
157
+ // if we get another digit or unary minus we return the whole string
158
+ Some ( ( _, c) ) if ( '1' ..='9' ) . contains ( & c) || c == '-' => return Some ( s) ,
154
159
// anything else is invalid, we return None
155
160
_ => return None ,
156
161
} ;
157
162
for ( i, c) in char_iter {
158
163
match c {
159
164
// continue on more leading zeros or if we get an underscore we continue - we're "within the number"
160
165
'0' | '_' => ( ) ,
161
- // any other digit we return the rest of the string
162
- '1' ..='9' => return Some ( & s[ i..] ) ,
166
+ // any other digit or unary minus we return the rest of the string
167
+ '1' ..='9' | '-' => return Some ( & s[ i..] ) ,
163
168
// if we get a dot we return the rest of the string but include the last zero
164
169
'.' => return Some ( & s[ ( i - 1 ) ..] ) ,
165
170
// anything else is invalid, we return None
0 commit comments