scv_client/text.rs
1//! Byte-bounded text, for limits that count bytes on the wire or on disk.
2
3/// The longest prefix of `value` that fits in `max_bytes` without splitting
4/// a character.
5pub fn utf8_prefix(value: &str, max_bytes: usize) -> &str {
6 if value.len() <= max_bytes {
7 return value;
8 }
9 let mut end = max_bytes;
10 while !value.is_char_boundary(end) {
11 end -= 1;
12 }
13 &value[..end]
14}
15
16#[cfg(test)]
17mod tests;