fn bump(&mut self) {
        self.last = self.curr;
        self.curr = self.peek;

        // If we already peeked once more to handle unicode escapes, use that
        // value instead of calling `next` already.
        self.peek = if let Some(un) = self.upeek {
            self.upeek = None;
            Some(un)
        } else {
            self.chs.next()
        };

        // update byte offsets
        self.last_pos = self.curr_pos;
        self.curr_pos = self.peek_pos;
        if let Some(c) = self.curr {
            // if peek was created from a unicode escape sequence, we add the
            // escape byte offset instead of the utf8 len
            self.peek_pos = self.peek_pos + if self.escaped_peek > 0 {
                BytePos(self.escaped_peek as SrcOffset)
            } else {
                BytePos(c.len_utf8() as SrcOffset)
            };
            self.escaped_peek = 0;
        }

        // Check if the current char is a line break (end) and add to line
        // break list.
        // Division into lines specified in section 3.4
        if self.curr == Some('\n')
            || (self.curr == Some('\r') && self.peek != Some('\n'))
        {
            self.fmap.add_line(self.peek_pos);
        }

        // Check for unicode escape. More information in section 3.3
        // Warning: Crazy code ahead
        if self.peek == Some('\\') && self.curr != Some('\\') {
            self.upeek = self.chs.next();
            if self.upeek == Some('u') {
                // First of all: We need `upeek` just for the case that the
                // char after '\' is not 'u'. So we reset it here.
                self.upeek = None;

                // we already read \ and u
                let mut pos_offset = 2;

                // We use a temporary peekable iterator here to check for
                // additional u's
                let mut peekiter = self.chs.by_ref().peekable();

                // After the first 'u' may follow arbitrarily many more 'u's...
                while let Some(&'u') = peekiter.peek() {
                    pos_offset += 1;
                    peekiter.next();
                }

                // At this point we expect 4 hexadecimal digits. Try to read
                // all four and convert them to int. We count the digits we
                // read in `num_digits`. If a non-hexadecimal char is found,
                // it'll be saved in `interrupt`.
                let mut value = 0;
                let mut num_digits = 0;
                let mut interrupt = None;
                for c in peekiter.by_ref().take(4) {
                    match c.to_digit(16) {
                        Some(v) => {
                            // converting: Shifting left by 12, 8, 4 and 0.
                            value += v << ((3-num_digits)*4);
                            num_digits += 1;
                        },
                        None => {
                            interrupt = Some(c);
                            break;
                        },
                    }
                }

                // check if all four digits were supplied
                if num_digits < 4 {
                    // report error ...
                    self.bump_err = Some(diag::Report::simple_error(
                        "Invalid unicode escape (less than 4 digits)",
                        Span {
                            lo: self.peek_pos,
                            hi: self.peek_pos +
                                    BytePos(pos_offset + num_digits),
                        }
                    ));
                    // ... but ignore the wrong unicode escape (POISON).
                    // If we couldn't read 4 digits because we reached EOF,
                    // interrupt will be None. If the reason was a non-hex
                    // char, it's saved in interrupt.
                    self.peek = interrupt;

                    // update position accordingly
                    self.peek_pos.0 += pos_offset + num_digits;
                } else {
                    // We read all 4 digits and converted them to int. Now use
                    // that value to create a new char and save it into peek.
                    self.peek = match ::std::char::from_u32(value) {
                        Some(c) => {
                            self.escaped_peek = 4 + pos_offset as u8;
                            Some(c)
                        },
                        None => {
                            self.bump_err = Some(diag::Report::simple_error(
                                "Invalid unicode escape (not a valid unicode \
                                    scalar value)",
                                Span {
                                    lo: self.peek_pos,
                                    hi: self.peek_pos + BytePos(pos_offset + 4),
                                }
                            ));
                            self.peek_pos.0 += pos_offset + 4;
                            peekiter.next()
                        }
                    };
                }
            }
        }

        // Check if peek is the SUB character to ignore it, if it is the last
        // character in the input stream (section 3.5)
        if self.peek == Some('\u{001a}') {
            self.upeek = self.chs.next();

            // If peek is the last char in the input stream, we ignore the
            // SUB character
            if self.upeek == None {
                self.peek = None
            }
        }
    }
/// Reads a new char from the iterator, updating last, curr and peek + pos.
/// Also handles line breaks and unicode escapes.
Reads a new char from the iterator, updating last, curr and peek + pos.
Also handles line breaks and unicode escapes.
Reads a new char from the iterator updating last curr and peek + pos . Also handles line breaks and unicode escapes .
fn bump(&mut self) {
        self.last = self.curr;
        self.curr = self.peek;
        // If we already peeked once more to handle unicode escapes, use that
        // value instead of calling `next` already.
        self.peek = if let Some(un) = self.upeek {
            self.upeek = None;
            Some(un)
        } else {
            self.chs.next()
        };
        // update byte offsets
        self.last_pos = self.curr_pos;
        self.curr_pos = self.peek_pos;
        if let Some(c) = self.curr {
            // if peek was created from a unicode escape sequence, we add the
            // escape byte offset instead of the utf8 len
            self.peek_pos = self.peek_pos + if self.escaped_peek > 0 {
                BytePos(self.escaped_peek as SrcOffset)
            } else {
                BytePos(c.len_utf8() as SrcOffset)
            };
            self.escaped_peek = 0;
        }
        // Check if the current char is a line break (end) and add to line
        // break list.
        // Division into lines specified in section 3.4
        if self.curr == Some('\n')
            || (self.curr == Some('\r') && self.peek != Some('\n'))
        {
            self.fmap.add_line(self.peek_pos);
        }
        // Check for unicode escape. More information in section 3.3
        // Warning: Crazy code ahead
        if self.peek == Some('\\') && self.curr != Some('\\') {
            self.upeek = self.chs.next();
            if self.upeek == Some('u') {
                // First of all: We need `upeek` just for the case that the
                // char after '\' is not 'u'. So we reset it here.
                self.upeek = None;
                // we already read \ and u
                let mut pos_offset = 2;
                // We use a temporary peekable iterator here to check for
                // additional u's
                let mut peekiter = self.chs.by_ref().peekable();
                // After the first 'u' may follow arbitrarily many more 'u's...
                while let Some(&'u') = peekiter.peek() {
                    pos_offset += 1;
                    peekiter.next();
                }
                // At this point we expect 4 hexadecimal digits. Try to read
                // all four and convert them to int. We count the digits we
                // read in `num_digits`. If a non-hexadecimal char is found,
                // it'll be saved in `interrupt`.
                let mut value = 0;
                let mut num_digits = 0;
                let mut interrupt = None;
                for c in peekiter.by_ref().take(4) {
                    match c.to_digit(16) {
                        Some(v) => {
                            // converting: Shifting left by 12, 8, 4 and 0.
                            value += v << ((3-num_digits)*4);
                            num_digits += 1;
                        },
                        None => {
                            interrupt = Some(c);
                            break;
                        },
                    }
                }
                // check if all four digits were supplied
                if num_digits < 4 {
                    // report error ...
                    self.bump_err = Some(diag::Report::simple_error(
                        "Invalid unicode escape (less than 4 digits)",
                        Span {
                            lo: self.peek_pos,
                            hi: self.peek_pos +
                                    BytePos(pos_offset + num_digits),
                        }
                    ));
                    // ... but ignore the wrong unicode escape (POISON).
                    // If we couldn't read 4 digits because we reached EOF,
                    // interrupt will be None. If the reason was a non-hex
                    // char, it's saved in interrupt.
                    self.peek = interrupt;
                    // update position accordingly
                    self.peek_pos.0 += pos_offset + num_digits;
                } else {
                    // We read all 4 digits and converted them to int. Now use
                    // that value to create a new char and save it into peek.
                    self.peek = match ::std::char::from_u32(value) {
                        Some(c) => {
                            self.escaped_peek = 4 + pos_offset as u8;
                            Some(c)
                        },
                        None => {
                            self.bump_err = Some(diag::Report::simple_error(
                                "Invalid unicode escape (not a valid unicode \
                                    scalar value)",
                                Span {
                                    lo: self.peek_pos,
                                    hi: self.peek_pos + BytePos(pos_offset + 4),
                                }
                            ));
                            self.peek_pos.0 += pos_offset + 4;
                            peekiter.next()
                        }
                    };
                }
            }
        }
        // Check if peek is the SUB character to ignore it, if it is the last
        // character in the input stream (section 3.5)
        if self.peek == Some('\u{001a}') {
            self.upeek = self.chs.next();
            // If peek is the last char in the input stream, we ignore the
            // SUB character
            if self.upeek == None {
                self.peek = None
            }
        }
    }
fn bump ( & mut self ) { self . last = self . curr ; self . curr = self . peek ; // If we already peeked once more to handle unicode escapes, use that // value instead of calling `next` already. self . peek = if let Some ( un ) = self . upeek { self . upeek = None ; Some ( un ) } else { self . chs . next ( ) } ; // update byte offsets self . last_pos = self . curr_pos ; self . curr_pos = self . peek_pos ; if let Some ( c ) = self . curr { // if peek was created from a unicode escape sequence, we add the // escape byte offset instead of the utf8 len self . peek_pos = self . peek_pos + if self . escaped_peek > 0 { BytePos ( self . escaped_peek as SrcOffset ) } else { BytePos ( c . len_utf8 ( ) as SrcOffset ) } ; self . escaped_peek = 0 ; } // Check if the current char is a line break (end) and add to line // break list. // Division into lines specified in section 3.4 if self . curr == Some ( '\n' ) || ( self . curr == Some ( '\r' ) && self . peek != Some ( '\n' ) ) { self . fmap . add_line ( self . peek_pos ) ; } // Check for unicode escape. More information in section 3.3 // Warning: Crazy code ahead if self . peek == Some ( '\\' ) && self . curr != Some ( '\\' ) { self . upeek = self . chs . next ( ) ; if self . upeek == Some ( 'u' ) { // First of all: We need `upeek` just for the case that the // char after '\' is not 'u'. So we reset it here. self . upeek = None ; // we already read \ and u let mut pos_offset = 2 ; // We use a temporary peekable iterator here to check for // additional u's let mut peekiter = self . chs . by_ref ( ) . peekable ( ) ; // After the first 'u' may follow arbitrarily many more 'u's... while let Some ( & 'u' ) = peekiter . peek ( ) { pos_offset += 1 ; peekiter . next ( ) ; } // At this point we expect 4 hexadecimal digits. Try to read // all four and convert them to int. We count the digits we // read in `num_digits`. If a non-hexadecimal char is found, // it'll be saved in `interrupt`. let mut value = 0 ; let mut num_digits = 0 ; let mut interrupt = None ; for c in peekiter . by_ref ( ) . take ( 4 ) { match c . to_digit ( 16 ) { Some ( v ) => { // converting: Shifting left by 12, 8, 4 and 0. value += v << ( ( 3 - num_digits ) * 4 ) ; num_digits += 1 ; } , None => { interrupt = Some ( c ) ; break ; } , } } // check if all four digits were supplied if num_digits < 4 { // report error ... self . bump_err = Some ( diag :: Report :: simple_error ( " " , Span { lo : self . peek_pos , hi : self . peek_pos + BytePos ( pos_offset + num_digits ) , } ) ) ; // ... but ignore the wrong unicode escape (POISON). // If we couldn't read 4 digits because we reached EOF, // interrupt will be None. If the reason was a non-hex // char, it's saved in interrupt. self . peek = interrupt ; // update position accordingly self . peek_pos . 0 += pos_offset + num_digits ; } else { // We read all 4 digits and converted them to int. Now use // that value to create a new char and save it into peek. self . peek = match :: std :: char :: from_u32 ( value ) { Some ( c ) => { self . escaped_peek = 4 + pos_offset as u8 ; Some ( c ) } , None => { self . bump_err = Some ( diag :: Report :: simple_error ( " \
 " , Span { lo : self . peek_pos , hi : self . peek_pos + BytePos ( pos_offset + 4 ) , } ) ) ; self . peek_pos . 0 += pos_offset + 4 ; peekiter . next ( ) } } ; } } } // Check if peek is the SUB character to ignore it, if it is the last // character in the input stream (section 3.5) if self . peek == Some ( '\u{001a}' ) { self . upeek = self . chs . next ( ) ; // If peek is the last char in the input stream, we ignore the // SUB character if self . upeek == None { self . peek = None } } }
Reads a new char from the iterator, updating last, curr and peek + pos.
Reads a new char from the iterator updating last curr and peek + pos .
&mut self
&mut self