use crate::options::Options;
use crate::unicode_data::is_decimal_digit;
fn is_all_digits(word: &str) -> bool {
!word.is_empty() && word.chars().all(is_decimal_digit)
}
#[must_use]
pub fn fixation_length(word: &str, graphemes: usize, options: &Options) -> usize {
if let Some(custom) = options.get_fixation_length() {
return custom(word, graphemes, options).min(graphemes);
}
if graphemes < 1 {
return 0;
}
if is_all_digits(word) && !options.get_emphasize_numbers() {
return 0;
}
if graphemes < options.get_min_word_length() {
return 0;
}
if graphemes == 1 {
return usize::from(options.get_fixation() >= 3);
}
let raw = graphemes
.checked_mul(options.percent())
.map_or(graphemes, |scaled| (scaled + 50) / 100);
raw.clamp(1, graphemes)
}