pub fn parse_dynamic(&mut self) -> Result<Option<DynamicValue>> {
        let pos = self.pos();

        if self.parse_is_missing() {
            return Ok(None);
        }

        // if it is quoted, it is certainly a string
        match self.current_char {
            b'\'' | b'\"' => {
                let s = self.parse_quoted_string()?;
                return Ok(Some(DynamicValue::String(s)));
            }
            _ => {}
        }

        // try to parse as integer

        self.buffer.clear();

        let negative = match self.current_char {
            b'-' => {
                self.buffer.push(self.current_char);
                self.advance();
                true
            }
            b'+' => {
                self.buffer.push(self.current_char);
                self.advance();
                false
            }
            _ => false,
        };

        let mut value = 0u64;
        loop {
            match self.current_char {
                ch @ b'0'...b'9' => {
                    value = value
                        .checked_mul(10)
                        .ok_or(Error::NumericOverflow(pos))?
                        .checked_add((ch - b'0') as u64)
                        .ok_or(Error::NumericOverflow(pos))?;
                }
                0 | b' ' | b'\t' | b'\n' | b',' => match (negative, value) {
                    (false, 0...255) => return Ok(Some(DynamicValue::U8(value as u8))),
                    (true, 0...128) => return Ok(Some(DynamicValue::I8((-(value as i64)) as i8))),
                    (false, 0...U16_MAX) => return Ok(Some(DynamicValue::U16(value as u16))),
                    (true, 0...I16_MINABS) => {
                        return Ok(Some(DynamicValue::I16((-(value as i64)) as i16)))
                    }
                    (false, 0...U32_MAX) => return Ok(Some(DynamicValue::U32(value as u32))),
                    (true, 0...I32_MINABS) => {
                        return Ok(Some(DynamicValue::I32((-(value as i64)) as i32)))
                    }
                    (false, _) => return Ok(Some(DynamicValue::U64(value))),
                    (true, I64_MINABS) => return Ok(Some(DynamicValue::I64(i64::MIN))),
                    (true, 0...I64_MINABS) => return Ok(Some(DynamicValue::I64(-(value as i64)))),
                    _ => break,
                },
                _ => break,
            }
            self.buffer.push(self.current_char);
            self.advance();
        }

        // not an integer => collect remaining characters
        loop {
            match self.current_char {
                0 | b' ' | b'\t' | b'\n' | b',' => break,
                _ => {
                    self.buffer.push(self.current_char);
                    self.advance();
                }
            }
        }

        let s = String::from_utf8(self.buffer.drain(..).collect()).unwrap();

        // either float or string
        match s.parse::<f64>() {
            Ok(value) => Ok(Some(DynamicValue::F64(value))),
            Err(_) => Ok(Some(DynamicValue::String(s))),
        }
    }
/// Try to parse value in most compact representation.
/// u8 > i8 > u16 > ... > f64 > String
Try to parse value in most compact representation.
Try to parse value in most compact representation .
pub fn parse_dynamic(&mut self) -> Result<Option<DynamicValue>> {
        let pos = self.pos();
        if self.parse_is_missing() {
            return Ok(None);
        }
        // if it is quoted, it is certainly a string
        match self.current_char {
            b'\'' | b'\"' => {
                let s = self.parse_quoted_string()?;
                return Ok(Some(DynamicValue::String(s)));
            }
            _ => {}
        }
        // try to parse as integer
        self.buffer.clear();
        let negative = match self.current_char {
            b'-' => {
                self.buffer.push(self.current_char);
                self.advance();
                true
            }
            b'+' => {
                self.buffer.push(self.current_char);
                self.advance();
                false
            }
            _ => false,
        };
        let mut value = 0u64;
        loop {
            match self.current_char {
                ch @ b'0'...b'9' => {
                    value = value
                        .checked_mul(10)
                        .ok_or(Error::NumericOverflow(pos))?
                        .checked_add((ch - b'0') as u64)
                        .ok_or(Error::NumericOverflow(pos))?;
                }
                0 | b' ' | b'\t' | b'\n' | b',' => match (negative, value) {
                    (false, 0...255) => return Ok(Some(DynamicValue::U8(value as u8))),
                    (true, 0...128) => return Ok(Some(DynamicValue::I8((-(value as i64)) as i8))),
                    (false, 0...U16_MAX) => return Ok(Some(DynamicValue::U16(value as u16))),
                    (true, 0...I16_MINABS) => {
                        return Ok(Some(DynamicValue::I16((-(value as i64)) as i16)))
                    }
                    (false, 0...U32_MAX) => return Ok(Some(DynamicValue::U32(value as u32))),
                    (true, 0...I32_MINABS) => {
                        return Ok(Some(DynamicValue::I32((-(value as i64)) as i32)))
                    }
                    (false, _) => return Ok(Some(DynamicValue::U64(value))),
                    (true, I64_MINABS) => return Ok(Some(DynamicValue::I64(i64::MIN))),
                    (true, 0...I64_MINABS) => return Ok(Some(DynamicValue::I64(-(value as i64)))),
                    _ => break,
                },
                _ => break,
            }
            self.buffer.push(self.current_char);
            self.advance();
        }
        // not an integer => collect remaining characters
        loop {
            match self.current_char {
                0 | b' ' | b'\t' | b'\n' | b',' => break,
                _ => {
                    self.buffer.push(self.current_char);
                    self.advance();
                }
            }
        }
        let s = String::from_utf8(self.buffer.drain(..).collect()).unwrap();
        // either float or string
        match s.parse::<f64>() {
            Ok(value) => Ok(Some(DynamicValue::F64(value))),
            Err(_) => Ok(Some(DynamicValue::String(s))),
        }
    }
pub fn parse_dynamic ( & mut self ) -> Result < Option < DynamicValue > > { let pos = self . pos ( ) ; if self . parse_is_missing ( ) { return Ok ( None ) ; } // if it is quoted, it is certainly a string match self . current_char { b'\'' | b'\"' => { let s = self . parse_quoted_string ( ) ? ; return Ok ( Some ( DynamicValue :: String ( s ) ) ) ; } _ => { } } // try to parse as integer self . buffer . clear ( ) ; let negative = match self . current_char { b'-' => { self . buffer . push ( self . current_char ) ; self . advance ( ) ; true } b'+' => { self . buffer . push ( self . current_char ) ; self . advance ( ) ; false } _ => false , } ; let mut value = 0u64 ; loop { match self . current_char { ch @ b'0' ... b'9' => { value = value . checked_mul ( 10 ) . ok_or ( Error :: NumericOverflow ( pos ) ) ? . checked_add ( ( ch - b'0' ) as u64 ) . ok_or ( Error :: NumericOverflow ( pos ) ) ? ; } 0 | b' ' | b'\t' | b'\n' | b',' => match ( negative , value ) { ( false , 0 ... 255 ) => return Ok ( Some ( DynamicValue :: U8 ( value as u8 ) ) ) , ( true , 0 ... 128 ) => return Ok ( Some ( DynamicValue :: I8 ( ( - ( value as i64 ) ) as i8 ) ) ) , ( false , 0 ... U16_MAX ) => return Ok ( Some ( DynamicValue :: U16 ( value as u16 ) ) ) , ( true , 0 ... I16_MINABS ) => { return Ok ( Some ( DynamicValue :: I16 ( ( - ( value as i64 ) ) as i16 ) ) ) } ( false , 0 ... U32_MAX ) => return Ok ( Some ( DynamicValue :: U32 ( value as u32 ) ) ) , ( true , 0 ... I32_MINABS ) => { return Ok ( Some ( DynamicValue :: I32 ( ( - ( value as i64 ) ) as i32 ) ) ) } ( false , _ ) => return Ok ( Some ( DynamicValue :: U64 ( value ) ) ) , ( true , I64_MINABS ) => return Ok ( Some ( DynamicValue :: I64 ( i64 :: MIN ) ) ) , ( true , 0 ... I64_MINABS ) => return Ok ( Some ( DynamicValue :: I64 ( - ( value as i64 ) ) ) ) , _ => break , } , _ => break , } self . buffer . push ( self . current_char ) ; self . advance ( ) ; } // not an integer => collect remaining characters loop { match self . current_char { 0 | b' ' | b'\t' | b'\n' | b',' => break , _ => { self . buffer . push ( self . current_char ) ; self . advance ( ) ; } } } let s = String :: from_utf8 ( self . buffer . drain ( .. ) . collect ( ) ) . unwrap ( ) ; // either float or string match s . parse :: < f64 > ( ) { Ok ( value ) => Ok ( Some ( DynamicValue :: F64 ( value ) ) ) , Err ( _ ) => Ok ( Some ( DynamicValue :: String ( s ) ) ) , } }
Try to parse value in most compact representation.
Try to parse value in most compact representation .
&mut self
&mut self