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

Method _parse

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

Source from the content-addressed store, hash-verified

308 }
309
310 fn _parse(text: &Wtf8) -> Result<Self, FormatSpecError> {
311 // get_integer in CPython
312 let (conversion, text) = FormatConversion::parse(text);
313 let (mut fill, mut align, text) = parse_fill_and_align(text);
314 let (sign, text) = FormatSign::parse(text);
315 let (alternate_form, text) = parse_alternate_form(text);
316 let (zero, text) = parse_zero(text);
317 let (width, text) = parse_number(text)?;
318 let (grouping_option, text) = FormatGrouping::parse(text);
319 if let Some(grouping) = &grouping_option {
320 Self::validate_separator(grouping, text)?;
321 }
322 let (precision, text) = parse_precision(text)?;
323 let (format_type, text) = FormatType::parse(text);
324 if !text.is_empty() {
325 return Err(FormatSpecError::InvalidFormatSpecifier);
326 }
327
328 if zero && fill.is_none() {
329 fill.replace('0'.into());
330 align = align.or(Some(FormatAlign::AfterSign));
331 }
332
333 Ok(Self {
334 conversion,
335 fill,
336 align,
337 sign,
338 alternate_form,
339 width,
340 grouping_option,
341 precision,
342 format_type,
343 })
344 }
345
346 fn validate_separator(grouping: &FormatGrouping, text: &Wtf8) -> Result<(), FormatSpecError> {
347 let mut chars = text.code_points().peekable();

Callers

nothing calls this directly

Calls 11

parse_fill_and_alignFunction · 0.85
parse_alternate_formFunction · 0.85
parse_zeroFunction · 0.85
parse_numberFunction · 0.85
parse_precisionFunction · 0.70
parseFunction · 0.50
ErrClass · 0.50
SomeClass · 0.50
is_emptyMethod · 0.45
is_noneMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected