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.
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
Subversion includes a library
libsvn_diff
.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":
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.
Also pretty much unfindable in Google, it turns out that Gnulib has a diff module. This one seems sufficient for what I wanted a diff library for. It doesn't seem to have a patch module, though.
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!
There is one that is part of Mercurial. It exists as some C code that's designed as a Python extension, but it could probably be extracted pretty easily. I believe it can also do binary diffs.
The relevant .c files are mercurial/bdiff.c, mercurial/mpatch.c and possibly mercurial/diffhelpers.c.