How to implement diff function?

How can I implement a diff function, such as a history of revising a stack question.

+1
source share
5 answers

You have an example javascript implementation of a diff algorithm.

Based:

P. Heckel, Method for Isolating Differences between Comm Files . ACM, 21, (4), 264-268 (1978).

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

diffString( String oldFile, String newFile )

This method takes two lines and calculates the differences in each. The end result is a "newFile" marked with HTML (for designation and deletion from oldFile and additions to newFile).

+3
source

diff FreeBSD . , .

+2

LCS: . . , , .

+1

, - , 2 . - :


void diff(String first,String second) {
   int biggest = (first.length() > second.length()) ? first.length() : second.length();
   for(int i = 0;i &lt biggest;i++) {
      //compare each char from the longest string with each char from the shorter
      // do something with them if they're not equal
   }
}

, . , .

0

, , diff. . , - , RCS. git.

diff diff. . - wdiff. diff. git diff --color-words , . , , -, -.

0
source

Source: https://habr.com/ru/post/1698681/


All Articles