fn scan_int(&mut self, c: char) -> u32 {
        // TODO: Handle other radices
        let radix: u32 = 10;

        // TODO: Can I just unwrap here? If there is a
        // guarantee that the char contains a valid char
        // of this radix? Returning 0 by default now.
        let mut res = c.to_digit(radix).unwrap_or(0);

        loop {
            match self.next_char() {
                Some(c) => match c {
                    '0'..='9' => {
                        // Safe to unwrap as we already identified that chars
                        // are within the radix
                        res = res * radix + c.to_digit(radix).unwrap();
                    }
                    _ => {
                        self.putback_char(c);
                        break;
                    }
                },
                None => break,
            };
        }

        res
    }
// To be called when current char is the first char
// of an integer literal
To be called when current char is the first char
of an integer literal
To be called when current char is the first char of an integer literal
fn scan_int(&mut self, c: char) -> u32 {
        // TODO: Handle other radices
        let radix: u32 = 10;
        // TODO: Can I just unwrap here? If there is a
        // guarantee that the char contains a valid char
        // of this radix? Returning 0 by default now.
        let mut res = c.to_digit(radix).unwrap_or(0);
        loop {
            match self.next_char() {
                Some(c) => match c {
                    '0'..='9' => {
                        // Safe to unwrap as we already identified that chars
                        // are within the radix
                        res = res * radix + c.to_digit(radix).unwrap();
                    }
                    _ => {
                        self.putback_char(c);
                        break;
                    }
                },
                None => break,
            };
        }
        res
    }
fn scan_int ( & mut self , c : char ) -> u32 { // TODO: Handle other radices let radix : u32 = 10 ; // TODO: Can I just unwrap here? If there is a // guarantee that the char contains a valid char // of this radix? Returning 0 by default now. let mut res = c . to_digit ( radix ) . unwrap_or ( 0 ) ; loop { match self . next_char ( ) { Some ( c ) => match c { '0' ..= '9' => { // Safe to unwrap as we already identified that chars // are within the radix res = res * radix + c . to_digit ( radix ) . unwrap ( ) ; } _ => { self . putback_char ( c ) ; break ; } } , None => break , } ; } res }
To be called when current char is the first char
of an integer literal
To be called when current char is the first char of an integer literal
&mut self
c
char