9 lines
275 B
Rust
9 lines
275 B
Rust
|
|
pub(crate) fn safe_slice_to_pos(content: &str, pos: usize) -> &str {
|
||
|
|
let pos = pos.min(content.len());
|
||
|
|
let mut boundary_pos = pos;
|
||
|
|
while boundary_pos > 0 && !content.is_char_boundary(boundary_pos) {
|
||
|
|
boundary_pos -= 1;
|
||
|
|
}
|
||
|
|
&content[..boundary_pos]
|
||
|
|
}
|