Coder Social home page Coder Social logo

mmanela / diffplex Goto Github PK

View Code? Open in Web Editor NEW
928.0 928.0 174.0 9.41 MB

DiffPlex is Netstandard 1.0+ C# library to generate textual diffs.

License: Apache License 2.0

C# 53.72% CSS 0.28% JavaScript 14.87% Ruby 0.02% PowerShell 0.11% HTML 0.94% Less 30.06%

diffplex's Introduction

diffplex's People

Contributors

aarnott avatar azure-pipelines[bot] avatar cezarypiatek avatar daveyostcom avatar drake53 avatar drewnoakes avatar gantrior avatar igitur avatar jamesskemp avatar kingcean avatar michasacuer avatar mmanela avatar rjantz2 avatar sharwell avatar soi013 avatar teo-tsirpanis avatar willdean avatar wojciechnagorski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

diffplex's Issues

Invalid diff containing spaces in Side By Side Diff model

I'm building diff view using DiffPlex version 1.2.1. I've noticed however that sometimes it picks up a space (or .) after the word as a difference and sometimes it doesn't. Why does it even include it if it's the same in both texts?

This is how I do it:

    SideBySideDiffBuilder DiffBuilder = new SideBySideDiffBuilder(new Differ());
    var result = DiffBuilder.BuildDiffModel(pair.Deleted.Content, pair.Added.Content);

Later I'm using Subpieces texts to highlight the difference.

Incorrect:
image

First part incorrect, second is correct:

image

Control DiffViewer: doesn't show text but color only

I'm probably wrong, but the control displays the different colors in the differences lines but without text (see you image attached).
Same problem if set 'ShowInline'.
What am I doing wrong?
DiffViewer

I use VS2019 + .net framework 4.6.1

Thanks in advance

Semantics of word by word diff

I'm trying to understand the semantics of word to word diff in diffplex w.r.t. wdiff.

Output from wdiff:

➜ git:(diffplex) βœ— echo "a b" > /tmp/a.txt
➜ git:(diffplex) βœ— echo "a b c" > /tmp/b.txt
➜ git:(diffplex) βœ— wdiff /tmp/a.txt /tmp/b.txt
a b {+c+}

{+c+} means only "c" has been inserted.

If I try the same in diffplex word to word diff:

                var prev = "a b";
		var current = "a     b c";
		var differ = new Differ();
		var result = differ.CreateWordDiffs(prev, current, false, new char[] { ' ', '\n'});

		foreach (var block in result.DiffBlocks) 
		{
			Console.WriteLine();
			Console.WriteLine("Insert Start: {0}\nInsert Count: {1}\nDelete Start: {2}\nDelete Count: {3}",
			                  block.InsertStartB, block.InsertCountB, block.DeleteStartA, block.DeleteCountA);
		}

Insert Start: 2
Insert Count: 8
Delete Start: 2
Delete Count: 0

Insert Start: 11
Insert Count: 2
Delete Start: 3
Delete Count: 0

Converting ^^^ output into wdiff format will be like this: a {+ +} b {+c+}. I'm not sure of the semantics of word to word diff in diffplex. But I think output of wdiff is intuitive and desired most of the cases, and diffplex's output is resembles char to char diff. The output of diffplex is same even if I set ignoreWhitespace=true in var result = differ.CreateWordDiffs(prev, current, true, new char[] { ' ', '\n'});. Is it by design?

ArgumentOutOfRangeException

I'm trying the following code snippet:

		var prev = "a b";
		var current = "a     b c";
		var differ = new Differ();
		var result = differ.CreateWordDiffs(prev, current, false, new char[] { ' ', '\n'});

		foreach (var block in result.DiffBlocks) 
		{
			Console.WriteLine();
			Console.WriteLine("Insert Start: {0}\nInsert Count: {1}\nDelete Start: {2}\nDelete Count: {3}",
			                  block.InsertStartB, block.InsertCountB, block.DeleteStartA, block.DeleteCountA);

			var diffTextA = prev.Substring(block.DeleteStartA, block.DeleteCountA);
			var diffTextB = current.Substring(block.InsertStartB, block.InsertCountB);

			Console.WriteLine("Diff A: {0}\nDiff B: {1}", diffTextA, diffTextB);
		}

Insert Start: 2
Insert Count: 8
Delete Start: 2
Delete Count: 0

it throws ArgumentOutOfRangeException. Same is also if I set: var result = differ.CreateWordDiffs(prev, current, false, new char[] { ' ', '\n'});.

API should take accept string[] for Lines

AArnott[CodePlex]
Instead of forcing the entire buffers to be compared into a single String instance, an array of lines (string[]) should be accepted. Since it will be split into lines anyway this means you can reuse all those instances instead of creating them yourself.
It also means that the maximum file you could operate on can increase because no object has to be too large.

Issue when passing in an IDiffer to SideBySideDiffBuilder

When using the overload to pass in an IDiffer to the SideBySide model ALL SubPieces appear on all changes. Cause appears to be:

public static SideBySideDiffModel Diff(IDiffer differ, string oldText, string newText, bool ignoreWhiteSpace = true, bool ignoreCase = false, IChunker lineChunker = null, IChunker wordChunker = null)

has lamda (ot, nt, op, np) =>
            {
                var r = differ.CreateDiffs(oldText, newText, false, false, wordChunker ?? WordChunker.Instance);
                BuildDiffPieces(r, op, np, null);
            }

Should be CreateDiffs(ot, nt ......

WebDiffer keeps loading on my browser upon Visual Studio 2019 compilation

Hi,
I am using Visual Studio 2019 on Windows 10 and try to compile and run the WebDiffer project on browser but it just keeps loading forever.
I changed the target framework to netcore 3.1 for the WebDiffer project and change to netstandard 2.0 as target frameworks for diffplex project as well. There are no error message from the error list in Visual Studio. Visual Studio itself caused the problem has been ruled out as I can create a web app in Visual Studio and run it without problem using netcore 3.1.
Please kindly give me your suggestions if you have any ideas.

Exception Using GoTo in WPF SideBySide

I am trying to use GoTo to scroll to the differences in the WPF SideBySide and am getting an exception when I call it:
"System.InvalidOperationException: 'The specified Visual and this Visual do not share a common ancestor, so there is no valid transformation between the two Visuals."

You should be able to duplicate by adding something like
DiffView.GoTo(25);
to the end of LoadData in WPFDemo.

Generic diff utility for sequences of custom objects

Python has a nice library called difflib [1], which has class SequenceMatcher that can diff not only string but also two difference sequences. Is there any plan to add something similar to SequenceMatcher to diffplex? The core algorithms in diffplex should work, just all the core classes have to be made generic and string specific code has to be refactored. This would be really good feature to add.

[1] : https://docs.python.org/3.6/library/difflib.html
[2]: https://docs.python.org/3.6/library/difflib.html#sequencematcher-objects

the difference is space symbol

Ablokha[CodePlex]
In those lines quotHello-Kittyquot quotHello - Kittyquot, the word quotHelloquot will be marked as difference. Although the difference is space symbol.

The good thing will be to have also the flag, if to mark whitespaces/word delimeters as difference at all.

Last word is different before line break.

vcpirkle[CodePlex]
In the following example the word "marketability" is different when comparing the strings using differ.CreateWordDiffs even though the strings are identical up to that point.

string string1 = "_PREDOMINANT VALUE_ The predominant value is based on all properties throughout the market area. The subject is not considered over-improved and being above the predominant value does not adversely effect the subjects marketability.quot;

string string2 = @"_PREDOMINANT VALUE_ The predominant value is based on all properties throughout the market area. The subject is not considered over-improved and being above the predominant value does not adversely effect the subjects marketability.

_REVISION/ADDITIONAL COMMENTS_
The original report dated 07/30/2014 was revised 08/11/2014 to include the following commentary: Appraiser considered the sales used to be the best available. The additional sales provided by the lenders third party source are either in a PUD/Garden home community and/or sold below market. quot;
When diffing string2 vs string1:

When diffing string1 vs string2:

Get output similar to wdiff (*nix utility)

I'm trying to get word by word diff similar to wdiff utility in *nix. Is there any way to achieve output similar to wdiff?

For reference, this is the output format of wdiff:

➜  echo "ab xy" > /tmp/a.txt
➜  echo "bc xy" > /tmp/b.txt
➜  wdiff /tmp/a.txt /tmp/b.txt          
[-ab-]{+bc+} xy

Version 1.2.1 cannot be installed for .net 4 client profile application

Trying to install version 1.2.1 with nuget for .net application targeted to .net 4 client profile, installation fails. Using VS2012 Pro. Previous version does not have this issue:


PM> Install-Package DiffPlex
Successfully installed 'DiffPlex 1.2.1'.
Successfully uninstalled 'DiffPlex 1.2.1'.
Install failed. Rolling back...
Install-Package : Could not install package 'DiffPlex 1.2.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0,P
rofile=Client', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package au
thor.
At line:1 char:16

  • Install-Package <<<< DiffPlex
    • CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
    • FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

PM> Install-Package DiffPlex -Version 1.2.0
Successfully installed 'DiffPlex 1.2.0'.
Successfully added 'DiffPlex 1.2.0' to MyProject

Won't build, stating .NET Framework 3.5 can't be found

Hi there,

I'd really like to use this package but I can't, for love nor money get it to build. Whenever I try to build the Diffplex project from Visual Studio 2017 I get an error saying .NET Framework 3.5 or higher needs to be installed. My system has both .NET Framework 4.7 and .NET Core 1.1.0 installed, I have verified this through a registry check for the Framework and dotnet --version for Core.

Googling the error:

Severity Code Description Project File Line Suppression State
Error MSB3645 .NET Framework v3.5 Service Pack 1 was not found. In order to target ".NETFramework,Version=v3.5", .NET Framework v3.5 Service Pack 1 or later must be installed. DiffPlex C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 1122

Results in only one topic: dotnet/msbuild#1333 In there I found the comment:

What's the work-around for people who need to build such projects on VS 2017? I just ran into this today, and the only thing I could figure out was to compile on a separate machine with only VS 2015 installed.

So I spun up a clean Windows 10 VM and installed Visual Studio 2015 and tried to build it there, but that failed miserably because 2015 can't work with the Core .csproj format.

If you have any suggestions on how I can get this to work I would be most grateful!

ToString override on DiffPiece (and possibly others)

Please add a ToString override or [DebuggerDisplay] on the Model.DiffPiece
e.g. $"Pos:{Pos,-6} Subs:{SubPieces.Count,-6} {Type,-16} {Text}"

Then expanding a DiffPaneModel's Lines would actually show most of what you need.

Not expected result

Hello,

I am doing the following :

string oldText ="<revision>1<revision>";
string newText = "<revision>2</revision>";
SideBySideDiffBuilder sideBySideDiffBuilder = new SideBySideDiffBuilder();
SideBySideDiffModel sideBySideDiffModel = sideBySideDiffBuilder.BuildDiffModel(oldText, newText);

The result should be that only character '1' has been changed to '2'.
Or it is not the result.
The line of the old text is defined as deleted in the subPieces and the line of the new text is defined as inserted in the subPieces.
Could you help please? Is it by design? Is there a workaround?

PS: If ignoreWhiteSpace is set to True or False, the result remains the same.

Is it possible to also target net45?

I would like to upgrade from 1.2.1 to 1.4.0, but my project targets net45 which isn't covered by netstandard1.4.

Is there a way to maintain support for net45? Are there any APIs you'd miss out on? If so, can they be worked around without excessive changes?

I maintain a library that targets net35, net45 and netstandard1.3 and need only a few #if directives to achieve this.

If there's interest and no reason this can't be done, I should be able to find time to make a PR.

NuGet version numbers

The NuGet version number shows the latest as 1.7 . How does this related to tagged versions here and can you Synchronize or at least add a mapping in the Readme?

DiffPaneModel could report pass/fail

I'm using DiffPlex to show differences when a unit test fails. Thank you!

For such uses, a property like this would be convenient in DiffPaneModel:

bool HasDifferences { get; }

Workaround is to first check if the strings are equal and call diff only if they're not.

Install via nugget on .net 4.5.2 throws

Can't install 'DiffPlex 1.4.0' package, into a project target to .NETFramework, Version=v4.5.2, but the package doesn't contains assembly references or compatible files to it.

ignoreWhitespace: true apparently ignores only leading whitespace

using System;
using DiffPlex;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
using System.Text;

// ignoreWhitespace: true
// apparently ignores only leading whitespace

// Cribbed from https://stackoverflow.com/a/23302056/1390116

namespace DiffPlexTest.Controllers {

  class Program {

    static void Main(string[] args) {
      StringBuilder sb = new StringBuilder();

      string oldText = "123\nabc def\nabc def g\n";
      string newText = " 123\nabc  def\nabc def  g\n";

      var d = new Differ();
      var builder = new InlineDiffBuilder(d);
      var result = builder.BuildDiffModel(oldText, newText, ignoreWhitespace: true);

      foreach (var line in result.Lines) {
        if (line.Type == ChangeType.Inserted) {
          sb.Append("+ ");
        } else if (line.Type == ChangeType.Deleted) {
          sb.Append("- ");
        } else if (line.Type == ChangeType.Modified) {
          sb.Append("* ");
        } else if (line.Type == ChangeType.Imaginary) {
          sb.Append("? ");
        } else if (line.Type == ChangeType.Unchanged) {
          sb.Append("  ");
        }
        sb.Append(line.Text + "\n");
      }
      Console.WriteLine(sb);
    }

  }

}

// expected:
// –––––––––
// 123
// abc def
// abc def g
//
// actual:
// –––––––
//    123
// - abc def
// - abc def g
// + abc  def
// + abc def  g

simple compare question

Using your web sample

My old text is: a
My new text is: abc

Why does it mark my old text as "Deleted" and new text as "Inserted". Shouldn't "a" be unchanged (in old and new text) and "bc" be inserted in new text?

System.StackOverFlowException in System.Web.dll

I downloaded the latest. I added DiffPlex and WebDiffer as existing projects into my solution. I made sure all the references lined up. I run the WebDiffer project and it comes up successfully. I paste text into each box and get the differences successfully.

Here's the weird part, if I let it sit for 2 to 2 1/2 minutes I get a System.StackOverFlowException in System.Web.dll.

I upgraded the target to 4.6.1 from 4.0 to target a newer version of system.web.dll but I still experience the error. Is anyone else experiencing this?

I'm going to look around the WebDiff project and will post back if I find something.

Strong name sign please

AArnott[CodePlex]
I just found I cannot reference this assembly because the build on Nuget.org isn't strong-name signed and my assembly is.

Can you please sign it?

.NET 4.5+ Framework support

Any chance of releasing .NET framework version side by side with .NET standard? There is a bug in last .NET framework version.

InlineDiffBuilder word diff in lines

Is there a way to include Subpieces in InlineDiffBuilder? I'm trying to create inline diff view but I want to higlight the changes on word level instead of line level. With SideBySideBuilder it's possible but Inline doesn't generate it.

Wrong side by side comparison

It seems there are few issues with word-breaks processing (tested with side-by-side web UI):

  1. Compare β€œHello,Β·World!β€œ with β€œHello!” – whole β€œold text” (β€œHello,Β·World!”) is marked as Deleted. But actually β€œHello” should be marked as β€œUnchanged”, β€œ,Β·World” as deleted and β€œ!” as Unchanged.
  2. Compare β€œHello,Β·World!β€œ with β€œHi, Wordl!” – β€œHello,” is marked as Modified (comma included), but whould be better if only β€œHello” is marked β€œModified” and β€œ, World” unchanged.

Question about use

I am trying to use the side by side comparison in my project. Currently my project lets the user select 2 GPOs from a list and it presents them in side by side WebBrowser controls. I would then want them to be marked up to show the differences in the 2 policies.

I know this has been around a while but are there any good examples that can be referenced? I am stuck and really don't want to reinvent the wheel if this would do the job.

I have added a reference to the DiffPlex dll but I don't see how to actually get the comparison accomplished.

Is there any way to get a subjectively better character chunker?

For example, I would like comparing "foo bar baz" and "foo bar fizz bazinga" to show a diff with inserting "fizz" and "inga", rather than inserting "fi" and "zinga". In this example, my hope is that it could still be a character matcher, but prioritize later larger- or whole-token chunk matches over earlier small-chunk matches.

Another such example is comparing "life, liberty, and property" to "life, liberty, and the pursuit of happiness, though not property". It would be nice if this would report "the pursuit of happiness, though not" as an insert, rather than smaller chunks "proper" "y, and t" "e pursuit of h", etc.

can we detect moved lines?

We know deleted, inserted, and modified lines for now. Is there any way to understand moved lines also?

like notepad++ compare plugin

Incorrect Result

Hi,

I am working on a windows application where I am comparing word by word of two strings. I used SideBySideDiffBuilder.BuildDiffModel to get the comparison result.

Sometimes, what happens is even if the word is same in both the strings at a particular position, it shows as word has been deleted in second string and it continues like this for some words untill it finds same word at later stage in the second string.

DiffPlex strange result (apparent bug)

Hi,
I'm currently working on application which allows user to compare between two strings which might contain a single character, xaml, xml, or another format of documents. I'm using a DiffPlex .Net algorithm for comparing and I get a strange result.
Here is a DiffPlex for Silverlight project. This is a state before generating DiffPlex Model:
before generate diff

After the model was built the result is:
after generate diff

Can you please explain me why do I get the blank spaces over there (marked in red)?
This behaviour does not reproduce with other Diff tools (e.g. BeyondCompare).
Thanks,

Side by side display issue

I have been looking at the results that the side by side diff model returns. I have noticed that the position of modifications / imaginary lines on both sides appears incorrect if you have deleted text followed immediately by modified text.

Example:
Line 2 from the left hand side has been deleted on the right, line 3 has been modified.
This is line 1 | This is line 1
This is line 2 | This is line 3 With Modification
This is line 3 | This is line 4
This is line 4 |

The model result for new text shows that line 1 was unchanged, line 2 was modified (not deleted), line 3 is marked as imaginary and line 4 is unchanged. It appears that in this scenario it should show line 2 as the imaginary (deleted line) and line 3 as the modified line. This is how the result is provided on other tests, when a delete is not directly followed by a modification.

Any thoughts on the above would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.