Skip to main content

diff_lines

Function diff_lines 

Source
pub fn diff_lines(saved: &[u8], current: &[u8]) -> LineDiff
Expand description

Compare two byte slices line by line and return which lines in current differ from saved.

This uses the classic LCS (Longest Common Subsequence) algorithm which is the foundation of most diff tools including Unix diff. The algorithm:

  1. Find the longest common subsequence of lines between saved and current
  2. Lines in current not in the LCS are insertions/modifications
  3. Lines in saved not in the LCS represent deletions (marked at deletion point)

This correctly handles insertions, deletions, and modifications without incorrectly marking shifted lines as changed.