Find the largest byte index ≤ `max_bytes` that falls on a UTF-8 char boundary. Prevents panics when truncating strings that contain multi-byte characters (e.g., emoji, CJK, accented chars).
(s: &str, max_bytes: usize)
| 25 | /// Prevents panics when truncating strings that contain multi-byte characters |
| 26 | /// (e.g., emoji, CJK, accented chars). |
| 27 | pub(crate) fn truncate_to_char_boundary(s: &str, max_bytes: usize) -> usize { |
| 28 | if max_bytes >= s.len() { |
| 29 | return s.len(); |
| 30 | } |
| 31 | let mut end = max_bytes; |
| 32 | while !s.is_char_boundary(end) { |
| 33 | end -= 1; |
| 34 | } |
| 35 | end |
| 36 | } |
| 37 | |
| 38 | pub use entity::{ |
| 39 | ChangeType, Confidence, Entity, EntityChange, EntityKind, FileSummary, Reference, |
no test coverage detected