Skip to main content

word_diff

Function word_diff 

Source
pub fn word_diff(
    old: &str,
    new: &str,
) -> Option<(Vec<Range<usize>>, Vec<Range<usize>>)>
Expand description

The byte ranges that changed between old and new, word by word: (in old, in new). Adjacent changed tokens merge into one range. None when either line is too long, the lines are equal, or they share no word (emphasis would then cover everything and say nothing).

let (old, new) = ashlar_diff::word_diff("let x = 1;", "let y = 1;").unwrap();
assert_eq!(old, vec![4..5]);
assert_eq!(new, vec![4..5]);