MCPcopy Create free account
hub / github.com/coooodeer/parse-rust / build_numeric_core_pattern

Function build_numeric_core_pattern

src/compiler.rs:462–496  ·  view source on GitHub ↗
(spec: &FormatSpec, fmt_type: &FormatType)

Source from the content-addressed store, hash-verified

460}
461
462fn 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
498fn build_field_pattern(
499 spec: &FormatSpec,

Callers 1

build_field_patternFunction · 0.85

Calls 1

regex_patternMethod · 0.80

Tested by

no test coverage detected