【问题标题】:Ignore EOL Unix and Windows in Google Diff Match Patch while generating patches在生成补丁时忽略 Google Diff Match Patch 中的 EOL Unix 和 Windows
【发布时间】:2021-05-08 15:30:24
【问题描述】:

我正在尝试比较两个文本文件,一个是 Windows(CR\LF),另一个是 Unix(LF)。尽管文件大小字节不同,但在 Beyond Compare 等比较器工具中打开的两个文件都显示相同。有没有办法让 Google DMP 显示文件相等?

非常感谢任何帮助。谢谢!

【问题讨论】:

    标签: google-diff-match-patch


    【解决方案1】:

    你可以这样做:

    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)+"));
    

    这是我用于如何匹配 Windows、Linux 和 MacOS 换行符的答案: Match linebreaks - \n or \r\n?

    【讨论】:

      猜你喜欢
      • 2012-09-16
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 2011-01-16
      相关资源
      最近更新 更多