Possible Duplicate:
Is there a way to diff files from C++?
I have long text strings that I wish to diff and patch. That is given strings a and b:
string a = ...;
string b = ...;
string a_diff_b = create_patch(a,b);
string a2 = apply_patch(a_diff_b, b);
assert(a == a2);
If a_diff_b
was human readable that would be a bonus.
One way to implement this would be to use system(3)
to call the diff
and patch
shell commands from diffutils
and pipe them the strings. Another way would be to implement the functions myself (I was thinking treat each line atomically and use the standard edit distance n^3 algorithm linewise with backtracking).
I was wondering if anyone knows of a good Linux C or C++ library that would do the job in-process?