PicoBot/src/text.rs
ooodc 73dab09bfe Refactor code for improved readability and consistency
- Adjusted formatting and indentation in various files for better clarity.
- Consolidated multi-line statements into single lines where appropriate.
- Enhanced error handling messages for better debugging.
- Added a new InboundProcessor struct to handle inbound messages more effectively.
- Updated test cases to ensure they align with the new code structure.
2026-04-28 10:33:31 +08:00

21 lines
561 B
Rust

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))
}