@@ -25,19 +25,19 @@ mod read_string;
2525mod remainder;
2626mod suitable_seekable_buffered_bytes_stream;
2727mod suitable_seekable_buffered_text_stream;
28- mod suitable_unseekable_buffered_bytes_stream;
29- mod suitable_unseekable_buffered_text_stream;
3028mod suitable_stream;
3129mod suitable_unbuffered_bytes_stream;
3230mod suitable_unbuffered_text_stream;
31+ mod suitable_unseekable_buffered_bytes_stream;
32+ mod suitable_unseekable_buffered_text_stream;
3333mod utf8_char_source;
3434
3535mod char_or_eof;
3636use crate :: char_or_eof:: CharOrEof ;
3737use CharOrEof :: { Char , Eof } ;
3838
3939mod unicode_utils;
40- use crate :: unicode_utils:: { is_surrogate , decode_surrogate_pair , UnicodeError } ;
40+ use crate :: unicode_utils:: { decode_surrogate_pair , is_surrogate , UnicodeError } ;
4141
4242use crate :: suitable_stream:: BufferingMode ;
4343
@@ -123,7 +123,7 @@ impl IntoPy<PyObject> for TokenType {
123123}
124124
125125#[ derive( Error , Debug ) ]
126- pub enum ParsingError {
126+ pub enum ParsingError {
127127 #[ error( "{0}" ) ]
128128 InvalidJson ( String ) ,
129129 #[ error( "Error due to limitation: {0}" ) ]
@@ -372,7 +372,7 @@ impl RustTokenizer {
372372 "Invalid JSON character: {c:?}"
373373 ) ) ) ;
374374 }
375- } ,
375+ }
376376 Eof => ( ) ,
377377 } ,
378378 State :: Integer => match c {
@@ -721,41 +721,37 @@ impl RustTokenizer {
721721 }
722722 }
723723 }
724- State :: UnicodeSurrogateStart => {
725- match c {
726- Char ( '\\' ) => {
727- slf. next_state = State :: UnicodeSurrogateStringEscape ;
728- }
729- Char ( _) => {
730- return Err ( ParsingError :: InvalidJson ( format ! (
731- "Unpaired UTF-16 surrogate"
732- ) ) ) ;
733- }
734- Eof => {
735- return Err ( ParsingError :: InvalidJson ( format ! (
736- "Unpaired UTF-16 surrogate at end of file"
737- ) ) ) ;
738- }
724+ State :: UnicodeSurrogateStart => match c {
725+ Char ( '\\' ) => {
726+ slf. next_state = State :: UnicodeSurrogateStringEscape ;
739727 }
740- }
741- State :: UnicodeSurrogateStringEscape => {
742- match c {
743- Char ( 'u' ) => {
744- slf. unicode_buffer = CompactString :: with_capacity ( 4 ) ;
745- slf. next_state = State :: UnicodeSurrogate ;
746- }
747- Char ( _) => {
748- return Err ( ParsingError :: InvalidJson ( format ! (
749- "Unpaired UTF-16 surrogate"
750- ) ) ) ;
751- }
752- Eof => {
753- return Err ( ParsingError :: InvalidJson ( format ! (
754- "Unpaired UTF-16 surrogate at end of file"
755- ) ) ) ;
756- }
728+ Char ( _) => {
729+ return Err ( ParsingError :: InvalidJson ( format ! (
730+ "Unpaired UTF-16 surrogate"
731+ ) ) ) ;
757732 }
758- }
733+ Eof => {
734+ return Err ( ParsingError :: InvalidJson ( format ! (
735+ "Unpaired UTF-16 surrogate at end of file"
736+ ) ) ) ;
737+ }
738+ } ,
739+ State :: UnicodeSurrogateStringEscape => match c {
740+ Char ( 'u' ) => {
741+ slf. unicode_buffer = CompactString :: with_capacity ( 4 ) ;
742+ slf. next_state = State :: UnicodeSurrogate ;
743+ }
744+ Char ( _) => {
745+ return Err ( ParsingError :: InvalidJson ( format ! (
746+ "Unpaired UTF-16 surrogate"
747+ ) ) ) ;
748+ }
749+ Eof => {
750+ return Err ( ParsingError :: InvalidJson ( format ! (
751+ "Unpaired UTF-16 surrogate at end of file"
752+ ) ) ) ;
753+ }
754+ } ,
759755 State :: UnicodeSurrogate => {
760756 match c {
761757 Char ( c) => {
@@ -786,13 +782,12 @@ impl RustTokenizer {
786782 "This should never happen, please report it as a bug..."
787783 ) ) ) ;
788784 } ;
789- c = Char (
790- decode_surrogate_pair ( prev_charcode, charcode)
791- . map_err ( |_| ParsingError :: InvalidJson ( format ! (
785+ c = Char ( decode_surrogate_pair ( prev_charcode, charcode) . map_err ( |_| {
786+ ParsingError :: InvalidJson ( format ! (
792787 "Error decoding UTF-16 surrogate pair \
793788 \\ u{prev_charcode:x}\\ u{charcode:x}"
794- ) ) ) ?
795- ) ;
789+ ) )
790+ } ) ? ) ;
796791 slf. prev_charcode = None ;
797792 slf. next_state = State :: String_ ;
798793 add_char = true ;
0 commit comments