[][src]Function unicode_linebreak::split_at_safe

pub fn split_at_safe(s: &str) -> (&str, &str)

Divides the string at the last index where further breaks do not depend on prior context.

The trivial index at eot is excluded.

A common optimization is to determine only the nearest line break opportunity before the first character that would cause the line to become overfull, requiring backward traversal, of which there are two approaches:

Examples

use unicode_linebreak::{linebreaks, split_at_safe};
let s = "Not allowed to break within em dashes: — —";
let (prev, safe) = split_at_safe(s);
let n = prev.len();
assert!(linebreaks(safe).eq(linebreaks(s).filter_map(|(i, x)| i.checked_sub(n).map(|i| (i, x)))));