项目作者: i-e-b

项目描述 :
[Working, In Progress] My own diff engine, plus Neil Fraser's diff-match-patch
高级语言: C#
项目地址: git://github.com/i-e-b/DiffTools.git
创建时间: 2011-11-03T09:33:29Z
项目社区:https://github.com/i-e-b/DiffTools

开源协议:

下载


Doc Diff

Available on NuGet: https://www.nuget.org/packages/DocDiff

What is it?

A file difference/comparison class. Performs much the same function as the Diff programs used in version control.
Compares two strings in chunks as determined by a Regex splitter.

Differences

Differences takes two documents and emits a set of difference fragments.

Each fragment is either deleted, inserted, or unchanged between the two versions.
These fragments are more suited to visual display than change analysis.

There are a few splitters provided: Differences.PerSentence, Differences.PerLine, Differences.PerWord, Differences.PerCharacter.
Smaller splits result in more complex diffs, and use more memory and compute resource. PerWord or PerLine is probably best for most cases.

  1. Changes = new Differences(oldVersion, newVersion, Differences.PerWord);
  2. foreach (var change in fragments)
  3. {
  4. Console.WriteLine($"{change.Type}: '{change.Content}'");
  5. }
  1. <style>
  2. .i {color:black; background-color:#80FF80; padding:0; margin:0;}
  3. .d {color:#FFa0a0; background-color:inherit; padding:0; margin:0;}
  4. .u {color:#707070; background-color:inherit; padding:0; margin:0;}
  5. </style>
  6. <div class="text-center">
  7. @foreach (var change in Model.Changes)
  8. {
  9. <span class="@change.TypeString">@change.Content</span>
  10. }
  11. </div>

DiffCode

This is a basic patch/match tool.

The tools in DiffCode can be used to analyse differences, and store/retrieve various revisions of files.
The Decode/Encode methods have variants which are suitable for data transmission and database storage.

  1. var changes = new Differences(left, right, Differences.PerWord);
  2. var encodedChanges = DiffCode.StorageDiffCode(changes);
  3. // Store 'encoded' and 'left'.
  4. // We can then regenerate 'right':
  5. var right = DiffCode.BuildRevision(left, encodedChanges);

Please note

Regex splitters omit the matched parts unless they are in capturing groups. See that the examples in Default.aspx.cs (from the static ‘Diff’) are all in capturing groups.