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