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

116 views Asked by At

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!

1

There are 1 answers

0
ronix On

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?