@@ -137,46 +137,6 @@ impl ReaderState {
137137 Ok ( Event :: End ( BytesEnd :: wrap ( name. into ( ) ) ) )
138138 }
139139
140- /// `buf` contains data between `<` and `>` and the first byte is `?`.
141- /// `self.offset` already after the `>`
142- ///
143- /// Returns `Decl` or `PI` event
144- pub fn emit_question_mark < ' b > ( & mut self , buf : & ' b [ u8 ] ) -> Result < Event < ' b > > {
145- debug_assert ! ( buf. len( ) > 0 ) ;
146- debug_assert_eq ! ( buf[ 0 ] , b'?' ) ;
147-
148- let len = buf. len ( ) ;
149- // We accept at least <??>
150- // ~~ - len = 2
151- if len > 1 && buf[ len - 1 ] == b'?' {
152- // Cut of `?` and `?` from start and end
153- let content = & buf[ 1 ..len - 1 ] ;
154- let len = content. len ( ) ;
155-
156- if content. starts_with ( b"xml" ) && ( len == 3 || is_whitespace ( content[ 3 ] ) ) {
157- let event = BytesDecl :: from_start ( BytesStart :: wrap ( content, 3 ) ) ;
158-
159- // Try getting encoding from the declaration event
160- #[ cfg( feature = "encoding" ) ]
161- if self . encoding . can_be_refined ( ) {
162- if let Some ( encoding) = event. encoder ( ) {
163- self . encoding = EncodingRef :: XmlDetected ( encoding) ;
164- }
165- }
166-
167- Ok ( Event :: Decl ( event) )
168- } else {
169- Ok ( Event :: PI ( BytesText :: wrap ( content, self . decoder ( ) ) ) )
170- }
171- } else {
172- // <?....EOF
173- // ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
174- // so we move offset to it (-2 for `<` and `>`)
175- self . last_error_offset = self . offset - len - 2 ;
176- Err ( Error :: Syntax ( SyntaxError :: UnclosedPIOrXmlDecl ) )
177- }
178- }
179-
180140 /// Converts content of a tag to a `Start` or an `Empty` event
181141 ///
182142 /// # Parameters
@@ -404,7 +364,40 @@ impl ReaderState {
404364 debug_assert ! ( content. starts_with( b"<?" ) , "{:?}" , Bytes ( content) ) ;
405365 debug_assert ! ( content. ends_with( b"?>" ) , "{:?}" , Bytes ( content) ) ;
406366
407- self . emit_question_mark ( & content[ 1 ..content. len ( ) - 1 ] )
367+ let buf = & content[ 1 ..content. len ( ) - 1 ] ;
368+ debug_assert ! ( buf. len( ) > 0 ) ;
369+ debug_assert_eq ! ( buf[ 0 ] , b'?' ) ;
370+
371+ let len = buf. len ( ) ;
372+ // We accept at least <??>
373+ // ~~ - len = 2
374+ if len > 1 && buf[ len - 1 ] == b'?' {
375+ // Cut of `?` and `?` from start and end
376+ let content = & buf[ 1 ..len - 1 ] ;
377+ let len = content. len ( ) ;
378+
379+ if content. starts_with ( b"xml" ) && ( len == 3 || is_whitespace ( content[ 3 ] ) ) {
380+ let event = BytesDecl :: from_start ( BytesStart :: wrap ( content, 3 ) ) ;
381+
382+ // Try getting encoding from the declaration event
383+ #[ cfg( feature = "encoding" ) ]
384+ if self . encoding . can_be_refined ( ) {
385+ if let Some ( encoding) = event. encoder ( ) {
386+ self . encoding = EncodingRef :: XmlDetected ( encoding) ;
387+ }
388+ }
389+
390+ Ok ( Event :: Decl ( event) )
391+ } else {
392+ Ok ( Event :: PI ( BytesText :: wrap ( content, self . decoder ( ) ) ) )
393+ }
394+ } else {
395+ // <?....EOF
396+ // ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
397+ // so we move offset to it (-2 for `<` and `>`)
398+ self . last_error_offset = self . offset - len - 2 ;
399+ Err ( Error :: Syntax ( SyntaxError :: UnclosedPIOrXmlDecl ) )
400+ }
408401 }
409402 FeedResult :: EmitEmptyTag ( _) => {
410403 debug_assert ! ( content. starts_with( b"<" ) , "{:?}" , Bytes ( content) ) ;
0 commit comments