Is there any open source project or library, which has the ability to compare two strings in the way GNU diff does, but without launching an external process, and working with memory buffers instead of files?
That is, something looking like this hypothetical function:
comparison_result* diff(wchar_t *text1, wchar_t *text2);
I looked at GNU diffutils’ source code, hoping it would be using such a function internally, but unfortunately, it is reading the files block by block, instead of reading them into a memory buffer and comparing that. The code itself is rather convoluted, and I’m not able to understand it very well, let alone rewrite it.
Is there such a function in an open-source project?
The source code for the diffutils programs / functions is indeed a bit difficult to adapt for this purpose given that it uses a number of partial buffering of the files during the comparison algorithm.
However, the functionality implemented by diff isn’t really revolutionary or difficult to reproduce. And it has be reproduced in other libraries. For example, the google-diff-match-patch library from google-code, it’s API is a bit crude, but it seems to do the job.
Another possibility is to write your data into in-memory
FILE*buffers, and then use the diffutils functions, reading and writing to those in-memory buffers. You can create such buffers with fmemopen.