diff options
Diffstat (limited to 'src/diff.rs')
| -rw-r--r-- | src/diff.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/diff.rs b/src/diff.rs new file mode 100644 index 0000000..0d11400 --- /dev/null +++ b/src/diff.rs @@ -0,0 +1,26 @@ +use std::ops::Range; + +use imara_diff::{Algorithm, Diff, Hunk, InternedInput}; + +pub enum DiffSpan { + Insertion(Range<u32>), + Deletion(Range<u32>), +} + +pub fn diff(before: &[u8], after: &[u8]) -> Vec<DiffSpan> { + let input = InternedInput::new(before, after); + let diff = Diff::compute(Algorithm::Histogram, &input); + + let hunks: Vec<Hunk> = diff.hunks().collect(); + let mut spans = Vec::with_capacity(hunks.len()); + for hunk in hunks { + if !hunk.before.is_empty() { + spans.push(DiffSpan::Deletion(hunk.before)); + } + if !hunk.after.is_empty() { + spans.push(DiffSpan::Insertion(hunk.after)); + } + } + + spans +} |
