Skip to main content

intraline

Function intraline 

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

Byte ranges (into each input) that differ between the two lines.

Word-level, not char-level: lines tokenize into unicode words, punctuation, and whitespace (UAX #29), so unrelated tokens can never share a stray letter (npm → bun is a whole-token swap, not an edit around a common n). A semantic-cleanup pass absorbs coincidental matches and snaps boundaries to word edges, mirroring what GitHub-class diff viewers ship.

Returns (old_emphasis, new_emphasis). Adjacent and near-adjacent ranges are merged.

use diffler_core::diff::intraline;

let (old, new) = intraline("if x < y:", "if x <= y:");
assert!(old.is_empty());
assert_eq!(new, vec![6..7]);