@@ -451,102 +451,6 @@ impl<R> Reader<R> {
451451 }
452452}
453453
454- /// Private sync reading methods
455- impl < R > Reader < R > {
456- /// Read text into the given buffer, and return an event that borrows from
457- /// either that buffer or from the input itself, based on the type of the
458- /// reader.
459- fn read_event_impl < ' i , B > ( & mut self , buf : B ) -> Result < Event < ' i > >
460- where
461- R : XmlSource < ' i , B > ,
462- {
463- let event = match self . tag_state {
464- TagState :: Init => self . read_until_open ( buf, true ) ,
465- TagState :: Closed => self . read_until_open ( buf, false ) ,
466- TagState :: Opened => self . read_until_close ( buf) ,
467- TagState :: Empty => self . close_expanded_empty ( ) ,
468- TagState :: Exit => return Ok ( Event :: Eof ) ,
469- } ;
470- match event {
471- Err ( _) | Ok ( Event :: Eof ) => self . tag_state = TagState :: Exit ,
472- _ => { }
473- }
474- event
475- }
476-
477- /// Read until '<' is found and moves reader to an `Opened` state.
478- ///
479- /// Return a `StartText` event if `first` is `true` and a `Text` event otherwise
480- fn read_until_open < ' i , B > ( & mut self , buf : B , first : bool ) -> Result < Event < ' i > >
481- where
482- R : XmlSource < ' i , B > ,
483- {
484- self . tag_state = TagState :: Opened ;
485-
486- if self . trim_text_start {
487- self . reader . skip_whitespace ( & mut self . buf_position ) ?;
488- }
489-
490- // If we already at the `<` symbol, do not try to return an empty Text event
491- if self . reader . skip_one ( b'<' , & mut self . buf_position ) ? {
492- return self . read_event_impl ( buf) ;
493- }
494-
495- match self
496- . reader
497- . read_bytes_until ( b'<' , buf, & mut self . buf_position )
498- {
499- Ok ( Some ( bytes) ) => self . read_text ( bytes, first) ,
500- Ok ( None ) => Ok ( Event :: Eof ) ,
501- Err ( e) => Err ( e) ,
502- }
503- }
504-
505- /// Private function to read until `>` is found. This function expects that
506- /// it was called just after encounter a `<` symbol.
507- fn read_until_close < ' i , B > ( & mut self , buf : B ) -> Result < Event < ' i > >
508- where
509- R : XmlSource < ' i , B > ,
510- {
511- self . tag_state = TagState :: Closed ;
512-
513- match self . reader . peek_one ( ) {
514- // `<!` - comment, CDATA or DOCTYPE declaration
515- Ok ( Some ( b'!' ) ) => match self . reader . read_bang_element ( buf, & mut self . buf_position ) {
516- Ok ( None ) => Ok ( Event :: Eof ) ,
517- Ok ( Some ( ( bang_type, bytes) ) ) => self . read_bang ( bang_type, bytes) ,
518- Err ( e) => Err ( e) ,
519- } ,
520- // `</` - closing tag
521- Ok ( Some ( b'/' ) ) => match self
522- . reader
523- . read_bytes_until ( b'>' , buf, & mut self . buf_position )
524- {
525- Ok ( None ) => Ok ( Event :: Eof ) ,
526- Ok ( Some ( bytes) ) => self . read_end ( bytes) ,
527- Err ( e) => Err ( e) ,
528- } ,
529- // `<?` - processing instruction
530- Ok ( Some ( b'?' ) ) => match self
531- . reader
532- . read_bytes_until ( b'>' , buf, & mut self . buf_position )
533- {
534- Ok ( None ) => Ok ( Event :: Eof ) ,
535- Ok ( Some ( bytes) ) => self . read_question_mark ( bytes) ,
536- Err ( e) => Err ( e) ,
537- } ,
538- // `<...` - opening or self-closed tag
539- Ok ( Some ( _) ) => match self . reader . read_element ( buf, & mut self . buf_position ) {
540- Ok ( None ) => Ok ( Event :: Eof ) ,
541- Ok ( Some ( bytes) ) => self . read_start ( bytes) ,
542- Err ( e) => Err ( e) ,
543- } ,
544- Ok ( None ) => Ok ( Event :: Eof ) ,
545- Err ( e) => Err ( e) ,
546- }
547- }
548- }
549-
550454/// Parse methods, independent from a way of reading data
551455impl < R > Reader < R > {
552456 /// Trims whitespaces from `bytes`, if required, and returns a [`StartText`]
@@ -731,6 +635,102 @@ impl<R> Reader<R> {
731635 }
732636}
733637
638+ /// Private sync reading methods
639+ impl < R > Reader < R > {
640+ /// Read text into the given buffer, and return an event that borrows from
641+ /// either that buffer or from the input itself, based on the type of the
642+ /// reader.
643+ fn read_event_impl < ' i , B > ( & mut self , buf : B ) -> Result < Event < ' i > >
644+ where
645+ R : XmlSource < ' i , B > ,
646+ {
647+ let event = match self . tag_state {
648+ TagState :: Init => self . read_until_open ( buf, true ) ,
649+ TagState :: Closed => self . read_until_open ( buf, false ) ,
650+ TagState :: Opened => self . read_until_close ( buf) ,
651+ TagState :: Empty => self . close_expanded_empty ( ) ,
652+ TagState :: Exit => return Ok ( Event :: Eof ) ,
653+ } ;
654+ match event {
655+ Err ( _) | Ok ( Event :: Eof ) => self . tag_state = TagState :: Exit ,
656+ _ => { }
657+ }
658+ event
659+ }
660+
661+ /// Read until '<' is found and moves reader to an `Opened` state.
662+ ///
663+ /// Return a `StartText` event if `first` is `true` and a `Text` event otherwise
664+ fn read_until_open < ' i , B > ( & mut self , buf : B , first : bool ) -> Result < Event < ' i > >
665+ where
666+ R : XmlSource < ' i , B > ,
667+ {
668+ self . tag_state = TagState :: Opened ;
669+
670+ if self . trim_text_start {
671+ self . reader . skip_whitespace ( & mut self . buf_position ) ?;
672+ }
673+
674+ // If we already at the `<` symbol, do not try to return an empty Text event
675+ if self . reader . skip_one ( b'<' , & mut self . buf_position ) ? {
676+ return self . read_event_impl ( buf) ;
677+ }
678+
679+ match self
680+ . reader
681+ . read_bytes_until ( b'<' , buf, & mut self . buf_position )
682+ {
683+ Ok ( Some ( bytes) ) => self . read_text ( bytes, first) ,
684+ Ok ( None ) => Ok ( Event :: Eof ) ,
685+ Err ( e) => Err ( e) ,
686+ }
687+ }
688+
689+ /// Private function to read until `>` is found. This function expects that
690+ /// it was called just after encounter a `<` symbol.
691+ fn read_until_close < ' i , B > ( & mut self , buf : B ) -> Result < Event < ' i > >
692+ where
693+ R : XmlSource < ' i , B > ,
694+ {
695+ self . tag_state = TagState :: Closed ;
696+
697+ match self . reader . peek_one ( ) {
698+ // `<!` - comment, CDATA or DOCTYPE declaration
699+ Ok ( Some ( b'!' ) ) => match self . reader . read_bang_element ( buf, & mut self . buf_position ) {
700+ Ok ( None ) => Ok ( Event :: Eof ) ,
701+ Ok ( Some ( ( bang_type, bytes) ) ) => self . read_bang ( bang_type, bytes) ,
702+ Err ( e) => Err ( e) ,
703+ } ,
704+ // `</` - closing tag
705+ Ok ( Some ( b'/' ) ) => match self
706+ . reader
707+ . read_bytes_until ( b'>' , buf, & mut self . buf_position )
708+ {
709+ Ok ( None ) => Ok ( Event :: Eof ) ,
710+ Ok ( Some ( bytes) ) => self . read_end ( bytes) ,
711+ Err ( e) => Err ( e) ,
712+ } ,
713+ // `<?` - processing instruction
714+ Ok ( Some ( b'?' ) ) => match self
715+ . reader
716+ . read_bytes_until ( b'>' , buf, & mut self . buf_position )
717+ {
718+ Ok ( None ) => Ok ( Event :: Eof ) ,
719+ Ok ( Some ( bytes) ) => self . read_question_mark ( bytes) ,
720+ Err ( e) => Err ( e) ,
721+ } ,
722+ // `<...` - opening or self-closed tag
723+ Ok ( Some ( _) ) => match self . reader . read_element ( buf, & mut self . buf_position ) {
724+ Ok ( None ) => Ok ( Event :: Eof ) ,
725+ Ok ( Some ( bytes) ) => self . read_start ( bytes) ,
726+ Err ( e) => Err ( e) ,
727+ } ,
728+ Ok ( None ) => Ok ( Event :: Eof ) ,
729+ Err ( e) => Err ( e) ,
730+ }
731+ }
732+ }
733+
734734////////////////////////////////////////////////////////////////////////////////////////////////////
735735
736736/// Represents an input for a reader that can return borrowed data.
0 commit comments