MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse_quantity

Function parse_quantity

crates/common/src/cformat.rs:644–672  ·  view source on GitHub ↗
(iter: &mut ParseIter<I>)

Source from the content-addressed store, hash-verified

642}
643
644fn parse_quantity<C, I>(iter: &mut ParseIter<I>) -> Result<Option<CFormatQuantity>, ParsingError>
645where
646 C: FormatChar,
647 I: Iterator<Item = C>,
648{
649 if let Some(&(_, c)) = iter.peek() {
650 if c.eq_char('*') {
651 iter.next().unwrap();
652 return Ok(Some(CFormatQuantity::FromValuesTuple));
653 }
654 if let Some(i) = c.to_char_lossy().to_digit(10) {
655 let mut num = i as i32;
656 iter.next().unwrap();
657 while let Some(&(index, c)) = iter.peek() {
658 if let Some(i) = c.to_char_lossy().to_digit(10) {
659 num = num
660 .checked_mul(10)
661 .and_then(|num| num.checked_add(i as i32))
662 .ok_or((CFormatErrorType::IntTooBig, index))?;
663 iter.next().unwrap();
664 } else {
665 break;
666 }
667 }
668 return Ok(Some(CFormatQuantity::Amount(num.unsigned_abs() as usize)));
669 }
670 }
671 Ok(None)
672}
673
674fn parse_precision<C, I>(iter: &mut ParseIter<I>) -> Result<Option<CFormatPrecision>, ParsingError>
675where

Callers 2

parseMethod · 0.85
parse_precisionFunction · 0.85

Calls 6

eq_charMethod · 0.80
SomeClass · 0.50
peekMethod · 0.45
unwrapMethod · 0.45
nextMethod · 0.45
to_char_lossyMethod · 0.45

Tested by

no test coverage detected