MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / truncate_bytes

Function truncate_bytes

atomic-cli/src/output/mod.rs:78–87  ·  view source on GitHub ↗

Truncate `s` to at most `max` bytes, appending "..." when it was cut. The cut point walks back to a UTF-8 character boundary: slicing at an arbitrary byte offset panics when the index lands inside a multi-byte character, and recorded text (change messages, provenance commands, file lines) routinely contains em-dashes or other non-ASCII content. Use [`Table::truncate`] instead when the limit is a

(s: &str, max: usize)

Source from the content-addressed store, hash-verified

76/// lines) routinely contains em-dashes or other non-ASCII content. Use
77/// [`Table::truncate`] instead when the limit is a display width, not bytes.
78pub fn truncate_bytes(s: &str, max: usize) -> String {
79 if s.len() <= max {
80 return s.to_string();
81 }
82 let mut end = max.saturating_sub(3);
83 while end > 0 && !s.is_char_boundary(end) {
84 end -= 1;
85 }
86 format!("{}...", &s[..end])
87}
88
89// Convenience Print Functions
90

Callers 4

run_promote_to_parentFunction · 0.85
run_previewFunction · 0.85
format_node_detailFunction · 0.85

Calls 1

lenMethod · 0.45