@@ -483,10 +483,10 @@ impl<'a> Lexer<'a> {
483
483
}
484
484
485
485
fn number ( & self , src : & ' a str ) -> Option < Token < ' a > > {
486
- let ( sign, num) = if src. starts_with ( '+' ) {
487
- ( Some ( SignToken :: Plus ) , & src [ 1 .. ] )
488
- } else if src. starts_with ( '-' ) {
489
- ( Some ( SignToken :: Minus ) , & src [ 1 .. ] )
486
+ let ( sign, num) = if let Some ( stripped ) = src. strip_prefix ( '+' ) {
487
+ ( Some ( SignToken :: Plus ) , stripped )
488
+ } else if let Some ( stripped ) = src. strip_prefix ( '-' ) {
489
+ ( Some ( SignToken :: Minus ) , stripped )
490
490
} else {
491
491
( None , src)
492
492
} ;
@@ -507,8 +507,8 @@ impl<'a> Lexer<'a> {
507
507
negative,
508
508
} ,
509
509
} ) ) ) ) ;
510
- } else if num. starts_with ( "nan:0x" ) {
511
- let mut it = num [ 6 .. ] . chars ( ) ;
510
+ } else if let Some ( stripped ) = num. strip_prefix ( "nan:0x" ) {
511
+ let mut it = stripped . chars ( ) ;
512
512
let to_parse = skip_undescores ( & mut it, false , char:: is_ascii_hexdigit) ?;
513
513
if it. next ( ) . is_some ( ) {
514
514
return None ;
@@ -524,9 +524,9 @@ impl<'a> Lexer<'a> {
524
524
}
525
525
526
526
// Figure out if we're a hex number or not
527
- let ( mut it, hex, test_valid) = if num. starts_with ( "0x" ) {
527
+ let ( mut it, hex, test_valid) = if let Some ( stripped ) = num. strip_prefix ( "0x" ) {
528
528
(
529
- num [ 2 .. ] . chars ( ) ,
529
+ stripped . chars ( ) ,
530
530
true ,
531
531
char:: is_ascii_hexdigit as fn ( & char ) -> bool ,
532
532
)
0 commit comments