一個好用的字符過濾,差異匹配補丁的擴展庫,各語言版本
阿新 • • 發佈:2018-03-05
system cleanup http ups linked 默認 javascrip lai python
diff-match-patchgithub地址
支持c,java,javascript,lua,object-c,python
https://github.com/google/diff-match-patch/wiki/API
該庫有多種語言版本。不管使用什麽語言,使用它的界面都是一樣的。該頁面描述了公共功能的API。更多實例在上方地址。
Diff Match Patch的每個語言端口都使用相同的API
java版本
import java.util.LinkedList; import name.fraser.neil.plaintext.diff_match_patch; public classhello { public static void main(String args[]) { diff_match_patch dmp = new diff_match_patch(); LinkedList<diff_match_patch.Diff> diff = dmp.diff_main("Hello World.", "Goodbye World."); // Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")] dmp.diff_cleanupSemantic(diff);// Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")] System.out.println(diff); } }
lua版本,不過bug是免不了的因為lua字符串不像更高級的語言會在初始化時默認設置編碼規則,所有的字節規則需要自己定義,所以這個版本的lua需要自己造輪子
local dmp = require ‘diff_match_patch‘ diff = dmp.diff_main(‘Hello World.‘, ‘Goodbye World.‘) -- Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")]dmp.diff_cleanupSemantic(diff) -- Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")] for i,tuple in ipairs(diff) do print(‘(‘ .. tuple[1] .. ‘, ‘ .. tuple[2] .. ‘)‘) end
一個好用的字符過濾,差異匹配補丁的擴展庫,各語言版本