(text: &Wtf8)
| 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(); |
nothing calls this directly
no test coverage detected