pub fn next_token<B: Read>(&mut self, b: &mut B) -> Result {
        // Already reached end of buffer
        if self.eof_handled {
            return Ok(None);
        }

        if !self.inside_token {
            self.pos = self.head_pos;
            self.inside_token = true;
        }

        // Check if we have saved a char or two for ourselves
        while let Some(c) = self.char_queue.pop_front() {
            match try!(self.read_next_token(c)) {
                Some(t) => {
                    self.inside_token = false;
                    return Ok(Some(t));
                }
                None => {}  // continue
            }
        }

        loop {
            // TODO: this should handle multiple encodings
            let c = match try!(util::next_char_from(b)) {
                Some(c) => c,   // got next char
                None => break,  // nothing to read left
            };

            match try!(self.read_next_token(c)) {
                Some(t) => {
                    self.inside_token = false;
                    return Ok(Some(t));
                }
                None => {
                    // continue
                }
            }
        }

        // Handle end of stream
        self.eof_handled = true;
        self.pos = self.head_pos;
        match self.st {
            State::TagStarted | State::CommentOrCDataOrDoctypeStarted |
            State::CommentStarted | State::CDataStarted(_)| State::DoctypeStarted(_) |
            State::CommentClosing(ClosingSubstate::Second) |
            State::DoctypeFinishing(_) =>
                Err(self.error("Unexpected end of stream")),
            State::ProcessingInstructionClosing =>
                Ok(Some(Token::Character('?'))),
            State::EmptyTagClosing =>
                Ok(Some(Token::Character('/'))),
            State::CommentClosing(ClosingSubstate::First) =>
                Ok(Some(Token::Character('-'))),
            State::CDataClosing(ClosingSubstate::First) =>
                Ok(Some(Token::Character(']'))),
            State::CDataClosing(ClosingSubstate::Second) =>
                Ok(Some(Token::Chunk("]]"))),
            State::Normal =>
                Ok(None)
        }
    }
/// Tries to read the next token from the buffer.
///
/// It is possible to pass different instaces of `BufReader` each time
/// this method is called, but the resulting behavior is undefined in this case.
///
/// Return value:
/// * `Err(reason) where reason: reader::Error` - when an error occurs;
/// * `Ok(None)` - upon end of stream is reached;
/// * `Ok(Some(token)) where token: Token` - in case a complete-token has been read from the stream.
Tries to read the next token from the buffer.
It is possible to pass different instaces of `BufReader` each time
this method is called, but the resulting behavior is undefined in this case.


Tries to read the next token from the buffer . It is possible to pass different instaces of ` BufReader ` each time this method is called but the resulting behavior is undefined in this case .
pub fn next_token<B: Read>(&mut self, b: &mut B) -> Result {
        // Already reached end of buffer
        if self.eof_handled {
            return Ok(None);
        }
        if !self.inside_token {
            self.pos = self.head_pos;
            self.inside_token = true;
        }
        // Check if we have saved a char or two for ourselves
        while let Some(c) = self.char_queue.pop_front() {
            match try!(self.read_next_token(c)) {
                Some(t) => {
                    self.inside_token = false;
                    return Ok(Some(t));
                }
                None => {}  // continue
            }
        }
        loop {
            // TODO: this should handle multiple encodings
            let c = match try!(util::next_char_from(b)) {
                Some(c) => c,   // got next char
                None => break,  // nothing to read left
            };
            match try!(self.read_next_token(c)) {
                Some(t) => {
                    self.inside_token = false;
                    return Ok(Some(t));
                }
                None => {
                    // continue
                }
            }
        }
        // Handle end of stream
        self.eof_handled = true;
        self.pos = self.head_pos;
        match self.st {
            State::TagStarted | State::CommentOrCDataOrDoctypeStarted |
            State::CommentStarted | State::CDataStarted(_)| State::DoctypeStarted(_) |
            State::CommentClosing(ClosingSubstate::Second) |
            State::DoctypeFinishing(_) =>
                Err(self.error("Unexpected end of stream")),
            State::ProcessingInstructionClosing =>
                Ok(Some(Token::Character('?'))),
            State::EmptyTagClosing =>
                Ok(Some(Token::Character('/'))),
            State::CommentClosing(ClosingSubstate::First) =>
                Ok(Some(Token::Character('-'))),
            State::CDataClosing(ClosingSubstate::First) =>
                Ok(Some(Token::Character(']'))),
            State::CDataClosing(ClosingSubstate::Second) =>
                Ok(Some(Token::Chunk("]]"))),
            State::Normal =>
                Ok(None)
        }
    }
pub fn next_token < B : Read > ( & mut self , b : & mut B ) -> Result { // Already reached end of buffer if self . eof_handled { return Ok ( None ) ; } if ! self . inside_token { self . pos = self . head_pos ; self . inside_token = true ; } // Check if we have saved a char or two for ourselves while let Some ( c ) = self . char_queue . pop_front ( ) { match try ! ( self read_next_token ( c ) ) { Some ( t ) => { self . inside_token = false ; return Ok ( Some ( t ) ) ; } None => { } // continue } } loop { // TODO: this should handle multiple encodings let c = match try ! ( util next_char_from ( b ) ) { Some ( c ) => c , // got next char None => break , // nothing to read left } ; match try ! ( self read_next_token ( c ) ) { Some ( t ) => { self . inside_token = false ; return Ok ( Some ( t ) ) ; } None => { // continue } } } // Handle end of stream self . eof_handled = true ; self . pos = self . head_pos ; match self . st { State :: TagStarted | State :: CommentOrCDataOrDoctypeStarted | State :: CommentStarted | State :: CDataStarted ( _ ) | State :: DoctypeStarted ( _ ) | State :: CommentClosing ( ClosingSubstate :: Second ) | State :: DoctypeFinishing ( _ ) => Err ( self . error ( " " ) ) , State :: ProcessingInstructionClosing => Ok ( Some ( Token :: Character ( '?' ) ) ) , State :: EmptyTagClosing => Ok ( Some ( Token :: Character ( '/' ) ) ) , State :: CommentClosing ( ClosingSubstate :: First ) => Ok ( Some ( Token :: Character ( '-' ) ) ) , State :: CDataClosing ( ClosingSubstate :: First ) => Ok ( Some ( Token :: Character ( ']' ) ) ) , State :: CDataClosing ( ClosingSubstate :: Second ) => Ok ( Some ( Token :: Chunk ( " " ) ) ) , State :: Normal => Ok ( None ) } }
Tries to read the next token from the buffer.
Tries to read the next token from the buffer .
&mut self
b
&mut B
&mut self
b
&mut B