@@ -386,9 +386,7 @@ fn cooked_string(input: Cursor) -> Result<Cursor, Reject> {
386
386
} ,
387
387
'\\' => match chars. next ( ) {
388
388
Some ( ( _, 'x' ) ) => {
389
- if !backslash_x_char ( & mut chars) {
390
- break ;
391
- }
389
+ backslash_x_char ( & mut chars) ?;
392
390
}
393
391
Some ( ( _, 'n' ) ) | Some ( ( _, 'r' ) ) | Some ( ( _, 't' ) ) | Some ( ( _, '\\' ) )
394
392
| Some ( ( _, '\'' ) ) | Some ( ( _, '"' ) ) | Some ( ( _, '0' ) ) => { }
@@ -462,9 +460,7 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
462
460
} ,
463
461
b'\\' => match bytes. next ( ) {
464
462
Some ( ( _, b'x' ) ) => {
465
- if !backslash_x_byte ( & mut bytes) {
466
- break ;
467
- }
463
+ backslash_x_byte ( & mut bytes) ?;
468
464
}
469
465
Some ( ( _, b'n' ) ) | Some ( ( _, b'r' ) ) | Some ( ( _, b't' ) ) | Some ( ( _, b'\\' ) )
470
466
| Some ( ( _, b'0' ) ) | Some ( ( _, b'\'' ) ) | Some ( ( _, b'"' ) ) => { }
@@ -586,9 +582,7 @@ fn cooked_c_string(input: Cursor) -> Result<Cursor, Reject> {
586
582
} ,
587
583
'\\' => match chars. next ( ) {
588
584
Some ( ( _, 'x' ) ) => {
589
- if !backslash_x_nonzero ( & mut chars) {
590
- break ;
591
- }
585
+ backslash_x_nonzero ( & mut chars) ?;
592
586
}
593
587
Some ( ( _, 'n' ) ) | Some ( ( _, 'r' ) ) | Some ( ( _, 't' ) ) | Some ( ( _, '\\' ) )
594
588
| Some ( ( _, '\'' ) ) | Some ( ( _, '"' ) ) => { }
@@ -627,7 +621,7 @@ fn byte(input: Cursor) -> Result<Cursor, Reject> {
627
621
let mut bytes = input. bytes ( ) . enumerate ( ) ;
628
622
let ok = match bytes. next ( ) . map ( |( _, b) | b) {
629
623
Some ( b'\\' ) => match bytes. next ( ) . map ( |( _, b) | b) {
630
- Some ( b'x' ) => backslash_x_byte ( & mut bytes) ,
624
+ Some ( b'x' ) => backslash_x_byte ( & mut bytes) . is_ok ( ) ,
631
625
Some ( b'n' ) | Some ( b'r' ) | Some ( b't' ) | Some ( b'\\' ) | Some ( b'0' ) | Some ( b'\'' )
632
626
| Some ( b'"' ) => true ,
633
627
_ => false ,
@@ -650,7 +644,7 @@ fn character(input: Cursor) -> Result<Cursor, Reject> {
650
644
let mut chars = input. char_indices ( ) ;
651
645
let ok = match chars. next ( ) . map ( |( _, ch) | ch) {
652
646
Some ( '\\' ) => match chars. next ( ) . map ( |( _, ch) | ch) {
653
- Some ( 'x' ) => backslash_x_char ( & mut chars) ,
647
+ Some ( 'x' ) => backslash_x_char ( & mut chars) . is_ok ( ) ,
654
648
Some ( 'u' ) => backslash_u ( & mut chars) . is_ok ( ) ,
655
649
Some ( 'n' ) | Some ( 'r' ) | Some ( 't' ) | Some ( '\\' ) | Some ( '0' ) | Some ( '\'' ) | Some ( '"' ) => {
656
650
true
@@ -672,48 +666,49 @@ macro_rules! next_ch {
672
666
match $chars. next( ) {
673
667
Some ( ( _, ch) ) => match ch {
674
668
$pat $( | $rest) * => ch,
675
- _ => return false ,
669
+ _ => return Err ( Reject ) ,
676
670
} ,
677
- None => return false ,
671
+ None => return Err ( Reject ) ,
678
672
}
679
673
} ;
680
674
}
681
675
682
- fn backslash_x_char < I > ( chars : & mut I ) -> bool
676
+ fn backslash_x_char < I > ( chars : & mut I ) -> Result < ( ) , Reject >
683
677
where
684
678
I : Iterator < Item = ( usize , char ) > ,
685
679
{
686
680
next_ch ! ( chars @ '0' ..='7' ) ;
687
681
next_ch ! ( chars @ '0' ..='9' | 'a' ..='f' | 'A' ..='F' ) ;
688
- true
682
+ Ok ( ( ) )
689
683
}
690
684
691
- fn backslash_x_byte < I > ( chars : & mut I ) -> bool
685
+ fn backslash_x_byte < I > ( chars : & mut I ) -> Result < ( ) , Reject >
692
686
where
693
687
I : Iterator < Item = ( usize , u8 ) > ,
694
688
{
695
689
next_ch ! ( chars @ b'0' ..=b'9' | b'a' ..=b'f' | b'A' ..=b'F' ) ;
696
690
next_ch ! ( chars @ b'0' ..=b'9' | b'a' ..=b'f' | b'A' ..=b'F' ) ;
697
- true
691
+ Ok ( ( ) )
698
692
}
699
693
700
- fn backslash_x_nonzero < I > ( chars : & mut I ) -> bool
694
+ fn backslash_x_nonzero < I > ( chars : & mut I ) -> Result < ( ) , Reject >
701
695
where
702
696
I : Iterator < Item = ( usize , char ) > ,
703
697
{
704
698
let first = next_ch ! ( chars @ '0' ..='9' | 'a' ..='f' | 'A' ..='F' ) ;
705
699
let second = next_ch ! ( chars @ '0' ..='9' | 'a' ..='f' | 'A' ..='F' ) ;
706
- !( first == '0' && second == '0' )
700
+ if first == '0' && second == '0' {
701
+ Err ( Reject )
702
+ } else {
703
+ Ok ( ( ) )
704
+ }
707
705
}
708
706
709
707
fn backslash_u < I > ( chars : & mut I ) -> Result < char , Reject >
710
708
where
711
709
I : Iterator < Item = ( usize , char ) > ,
712
710
{
713
- match chars. next ( ) {
714
- Some ( ( _, '{' ) ) => { }
715
- _ => return Err ( Reject ) ,
716
- }
711
+ next_ch ! ( chars @ '{' ) ;
717
712
let mut value = 0 ;
718
713
let mut len = 0 ;
719
714
for ( _, ch) in chars {
0 commit comments