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

Function parse_precision

crates/common/src/format.rs:287–303  ·  view source on GitHub ↗
(text: &Wtf8)

Source from the content-addressed store, hash-verified

285}
286
287fn parse_precision(text: &Wtf8) -> Result<(Option<usize>, &Wtf8), FormatSpecError> {
288 let mut chars = text.code_points();
289 Ok(match chars.next().and_then(CodePoint::to_char) {
290 Some('.') => {
291 let (size, remaining) = parse_number(chars.as_wtf8())?;
292 if let Some(size) = size {
293 if size > i32::MAX as usize {
294 return Err(FormatSpecError::PrecisionTooBig);
295 }
296 (Some(size), remaining)
297 } else {
298 (None, text)
299 }
300 }
301 _ => (None, text),
302 })
303}
304
305impl FormatSpec {
306 pub fn parse(text: impl AsRef<Wtf8>) -> Result<Self, FormatSpecError> {

Callers 1

_parseMethod · 0.70

Calls 6

parse_numberFunction · 0.85
code_pointsMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
nextMethod · 0.45
as_wtf8Method · 0.45

Tested by

no test coverage detected