pub fn char_count(text: &str) -> usize {
    text.chars().count()
}

pub fn take_prefix_chars(text: &str, max_chars: usize) -> String {
    text.chars().take(max_chars).collect()
}

pub fn take_suffix_chars(text: &str, max_chars: usize) -> String {
    let count = char_count(text);
    text.chars().skip(count.saturating_sub(max_chars)).collect()
}

pub fn truncate_with_ellipsis(text: &str, max_chars: usize) -> String {
    if char_count(text) <= max_chars {
        return text.to_string();
    }

    format!("{}...", take_prefix_chars(text, max_chars))
}
