(spec: &FormatSpec, fmt_type: &FormatType)
| 460 | } |
| 461 | |
| 462 | fn build_numeric_core_pattern(spec: &FormatSpec, fmt_type: &FormatType) -> (String, usize) { |
| 463 | match fmt_type { |
| 464 | FormatType::Decimal => { |
| 465 | if let Some(grouping) = spec.grouping { |
| 466 | let grouped = match grouping { |
| 467 | ',' => r"\d{1,3}(?:,\d{3})*".to_string(), |
| 468 | '_' => r"\d{1,3}(?:_\d{3})*".to_string(), |
| 469 | _ => r"\d+".to_string(), |
| 470 | }; |
| 471 | ( |
| 472 | format!( |
| 473 | "(?:{grouped}|0[xX][0-9a-fA-F]+|0[bB][01]+|0[oO][0-7]+)", |
| 474 | grouped = grouped |
| 475 | ), |
| 476 | 0, |
| 477 | ) |
| 478 | } else { |
| 479 | let width_pattern = if let Some(width) = spec.width { |
| 480 | format!("{{1,{}}}", width) |
| 481 | } else { |
| 482 | "+".to_string() |
| 483 | }; |
| 484 | |
| 485 | ( |
| 486 | format!( |
| 487 | "(?:[0-9]{w}|0[xX][0-9a-fA-F]+|0[bB][01]+|0[oO][0-7]+)", |
| 488 | w = width_pattern |
| 489 | ), |
| 490 | 0, |
| 491 | ) |
| 492 | } |
| 493 | } |
| 494 | _ => fmt_type.regex_pattern(), |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | fn build_field_pattern( |
| 499 | spec: &FormatSpec, |
no test coverage detected