systemprompt_models/
text.rs1pub fn truncate_with_ellipsis(text: &str, max_len: usize) -> String {
2 if text.len() <= max_len {
3 return text.to_string();
4 }
5
6 let truncated_len = max_len.saturating_sub(3);
7 let boundary = find_char_boundary(text, truncated_len);
8 format!("{}...", &text[..boundary])
9}
10
11fn find_char_boundary(s: &str, target: usize) -> usize {
12 if target >= s.len() {
13 return s.len();
14 }
15
16 let mut boundary = target;
17 while boundary > 0 && !s.is_char_boundary(boundary) {
18 boundary -= 1;
19 }
20 boundary
21}