如何实现diff函数? [英] How to realize a diff function?

查看:133
本文介绍了如何实现diff函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现diff函数,例如Stack Overflow的问题修订历史记录?

How can I implement a diff function, such as Stack Overflow's question revision history?

推荐答案

您在这里有 diff算法实现的javascript示例.

基于:

P. Heckel,一种隔离文件之间差异的技术 通讯ACM,21,(4),264--268(1978).

P. Heckel, A technique for isolating differences between files Comm. ACM, 21, (4), 264--268 (1978).

该实现本身具有两个功能,建议使用其中之一:

The implementation, itself, has two functions, one of which is recommended for use:

diffString( String oldFile, String newFile )

此方法采用两个字符串并计算每个字符串之间的差异.最终结果是用HTML标记的"newFile"(既表示从oldFile中删除又表示对newFile的添加).

This method takes two strings and calculates the differences in each. The final result is the 'newFile' marked up with HTML (to signify both deletions from the oldFile and additions to the newFile).

这篇关于如何实现diff函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆