murali Krishna
murali Krishna

Reputation: 29

Ignore EOL Unix and Windows in Google Diff Match Patch while generating patches

I'm trying to compare two text files one is Windows(CR\LF) and the other is Unix(LF). Both the files when opened in comparer tools like Beyond Compare are showing same although the file size bytes are different. Is there a way to make Google DMP show the files are equal?

Any help is really appreciated. Thank You!

Upvotes: 0

Views: 122

Answers (1)

ronix
ronix

Reputation: 38

You can do it like this:

DiffMatchPatch dmp = new DiffMatchPatch();    
LinkedList<DiffMatchPatch.Diff> allDiff = dmp.diffMain(txt_1, txt_2);
allDiff.removeIf(diff ->
           (diff.operation == Operation.DELETE || diff.operation == Operation.INSERT) && 
            diff.text.matches("^(\\r\\n|\\r|\\n)+"));

Here is an answer that I used on how to match Windows, Linux, and MacOS line breaks: Match linebreaks - \n or \r\n?

Upvotes: 0

Related Questions