#[derive(Debug, Clone)]
pub struct FuzzyInfo {
pub fuzzy: bool,
pub strategy: String,
pub strategies_tried: u64,
pub similarity: Option<f64>,
pub diff_preview: Option<String>,
pub match_count: u64,
pub indent_adjusted: bool,
}
#[derive(Debug, Clone, Copy)]
pub struct MatchOpts {
pub mode: FuzzyMode,
pub threshold: Option<f64>,
pub thr_aggressive: f64,
pub thr_context: f64,
pub thr_jw: f64,
pub thr_auto: f64,
pub replace_all: bool,
}
impl Default for MatchOpts {
fn default() -> Self {
Self {
mode: FuzzyMode::Auto,
threshold: None,
thr_aggressive: crate::constants::FUZZY_THRESHOLD_AGGRESSIVE,
thr_context: crate::constants::FUZZY_THRESHOLD_CONTEXT,
thr_jw: crate::constants::FUZZY_THRESHOLD_JW,
thr_auto: crate::constants::FUZZY_THRESHOLD_AUTO,
replace_all: false,
}
}
}
pub fn match_opts_from_section(
mode: FuzzyMode,
cli_threshold: Option<f64>,
section: &crate::config::FuzzySection,
replace_all: bool,
) -> MatchOpts {
MatchOpts {
mode,
threshold: cli_threshold,
thr_aggressive: section.threshold_aggressive,
thr_context: section.threshold_context,
thr_jw: section.threshold_jw,
thr_auto: section.threshold,
replace_all,
}
}
pub fn adaptive_threshold(base: f64, pattern_len: usize) -> f64 {
if pattern_len > 0 && pattern_len < crate::constants::FUZZY_ADAPTIVE_SHORT_PATTERN_CHARS {
(base + crate::constants::FUZZY_ADAPTIVE_SHORT_BOOST).min(1.0)
} else {
base
}
}
const BEST_CANDIDATE_MIN: f64 = crate::constants::FUZZY_BEST_CANDIDATE_MIN;
const MAX_CANDIDATES: usize = crate::constants::FUZZY_MAX_CANDIDATES;