Get output similar to wdiff (*nix utility)
I'm trying to get word by word diff similar to wdiff utility in *nix. Is there any way to achieve output similar to wdiff?
For reference, this is the output format of wdiff:
➜ echo "ab xy" > /tmp/a.txt
➜ echo "bc xy" > /tmp/b.txt
➜ wdiff /tmp/a.txt /tmp/b.txt
[-ab-]{+bc+} xy
You would need to build it. I think the idea of diff formatters would be really nice to add to this library. I think my existing diff model should allow you to build that.
Would you be interested?
Sure, I'm interested in contributing back. I'm actually looking for API for word to word diff similar to following inline diff builder:
var d = new Differ();
var inlineBuilder = new InlineDiffBuilder(d);
var result = inlineBuilder.BuildDiffModel(OldText, NewText);
foreach (var line in result.Lines)
{
if (line.Type == ChangeType.Inserted)
Console.Write("+ ");
else if (line.Type == ChangeType.Deleted)
Console.Write("- ");
else
Console.Write(" ");
Console.WriteLine(line.Text);
}
Unfortunately, I couldn't find any similar API for word to word diff. I got the following code working so far.
var prev = "a";
var current = "abc";
var differ = new DiffPlex.Differ();
var result = differ.CreateWordDiffs(prev, current, false, new char[] { ' ', '\n'});
var diffCount = result.DiffBlocks.Count;
Console.WriteLine("Diff Block Count: {0}", diffCount);
foreach (var block in result.DiffBlocks)
{
Console.WriteLine(block.InsertStartB);
Console.WriteLine(block.InsertCountB);
Console.WriteLine(block.DeleteStartA);
Console.WriteLine(block.DeleteCountA);
}
However, the output is not very intuitive and hard to understand. Is it possible to get output like the inline diff builder?
The Differ is the core api. It tells you exactly which blocks are deleted/inserted. If you look at the code for Inline builder it shows how to interpret those blocks