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 class hello { 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
原文地址:https://www.cnblogs.com/dmeck/p/8510603.html
时间: 2024-10-19 15:03:46