Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/i-e-b/difftools
[Working] My own diff engine, plus Neil Fraser's diff-match-patch
https://github.com/i-e-b/difftools
c-sharp capture-groups diff patching regex-splitters
Last synced: about 1 month ago
JSON representation
[Working] My own diff engine, plus Neil Fraser's diff-match-patch
- Host: GitHub
- URL: https://github.com/i-e-b/difftools
- Owner: i-e-b
- License: bsd-3-clause
- Created: 2011-11-03T09:33:29.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2024-06-19T12:50:28.000Z (5 months ago)
- Last Synced: 2024-09-20T09:17:40.209Z (about 2 months ago)
- Topics: c-sharp, capture-groups, diff, patching, regex-splitters
- Language: C#
- Homepage:
- Size: 291 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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.```csharp
Changes = new Differences(oldVersion, newVersion, Differences.PerWord);foreach (var change in fragments)
{
Console.WriteLine($"{change.Type}: '{change.Content}'");
}
``````html
.i {color:black; background-color:#80FF80; padding:0; margin:0;}
.d {color:#FFa0a0; background-color:inherit; padding:0; margin:0;}
.u {color:#707070; background-color:inherit; padding:0; margin:0;}
@foreach (var change in Model.Changes)
{
@change.Content
}
```### 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.```csharp
var changes = new Differences(left, right, Differences.PerWord);var encodedChanges = DiffCode.StorageDiffCode(changes);
// Store 'encoded' and 'left'.
// We can then regenerate 'right':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.