I'm looking for a C or C++ diff library. I know I can use the Unix diff
tool in combination with system
or exec
, but I really want a library. It would be handy if the library could perform patches as well, like the Unix patch
tool.
Step 1: Open both the file with pointer at the starting. Step 2: Fetch data from file as characters one by one. Step 3: Compare the characters. If the characters are different then return the line and position of the error character.
Explanation: diff command is used for comparing files and displaying the differences between them.
I think I've found a good solution, finally:
The DTL - Diff Template Library --- Tutorial
It supports patch. I had to type "diff.cpp" into Google to find it. Hopefully it works!
It seems like the Google Diff, Match and Patch libraries are what you need.
This is an implementation of a "solution to SES/LCS with the Hirschberg linear space refinement as described in the following publication":
E. Myers, ``An O(ND) Difference Algorithm and Its Variations,'' Algorithmica 1, 2 (1986), 251-266. http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps
Found it on the Wikipedia page on diff.
That's only for finding a diff though, not applying it as a patch. I think that application of a patch is actually a harder problem; due to the risk of conflicts. It would need some form of user-controlling feedback mechanism, to resolve conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With