Giter Club home page Giter Club logo

diffplex's Introduction

DiffPlex .NET DiffPlex NuGet version

DiffPlex is C# library to generate textual diffs. It targets netstandard1.0+.

About the API

The DiffPlex library currently exposes two interfaces for generating diffs:

  • IDiffer (implemented by the Differ class) - This is the core diffing class. It exposes the low level functions to generate differences between texts.
  • ISidebySideDiffer (implemented by the SideBySideDiffer class) - This is a higher level interface. It consumes the IDiffer interface and generates a SideBySideDiffModel. This is a model which is suited for displaying the differences of two pieces of text in a side by side view.

Examples

For examples of how to use the API please see the the following projects contained in the DiffPlex solution.

For use of the IDiffer interface see:

  • SidebySideDiffer.cs contained in the DiffPlex Project.
  • UnidiffFormater.cs contained in the DiffPlex.ConsoleRunner project.

For use of the ISidebySideDiffer interface see:

  • DiffController.cs and associated MVC views in the WebDiffer project
  • TextBoxDiffRenderer.cs in the SilverlightDiffer project

Sample code

var diff = InlineDiffBuilder.Diff(before, after);

var savedColor = Console.ForegroundColor;
foreach (var line in diff.Lines)
{
    switch (line.Type)
    {
        case ChangeType.Inserted:
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("+ ");
            break;
        case ChangeType.Deleted:
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("- ");
            break;
        default:
            Console.ForegroundColor = ConsoleColor.Gray; // compromise for dark or light background
            Console.Write("  ");
            break;
    }

    Console.WriteLine(line.Text);
}
Console.ForegroundColor = savedColor;

IDiffer Interface

/// <summary>
/// Provides methods for generate differences between texts
/// </summary>
public interface IDiffer
{
    /// <summary>
    /// Create a diff by comparing text line by line
    /// </summary>
    /// <param name="oldText">The old text.</param>
    /// <param name="newText">The new text.</param>
    /// <param name="ignoreWhiteSpace">if set to <c>true</c> will ignore white space when determining if lines are the same.</param>
    /// <returns>A DiffResult object which details the differences</returns>
    DiffResult CreateLineDiffs(string oldText, string newText, bool ignoreWhiteSpace);

    /// <summary>
    /// Create a diff by comparing text character by character
    /// </summary>
    /// <param name="oldText">The old text.</param>
    /// <param name="newText">The new text.</param>
    /// <param name="ignoreWhitespace">if set to <c>true</c> will treat all whitespace characters are empty strings.</param>
    /// <returns>A DiffResult object which details the differences</returns>
    DiffResult CreateCharacterDiffs(string oldText, string newText, bool ignoreWhitespace);

    /// <summary>
    /// Create a diff by comparing text word by word
    /// </summary>
    /// <param name="oldText">The old text.</param>
    /// <param name="newText">The new text.</param>
    /// <param name="ignoreWhitespace">if set to <c>true</c> will ignore white space when determining if words are the same.</param>
    /// <param name="separators">The list of characters which define word separators.</param>
    /// <returns>A DiffResult object which details the differences</returns>
    DiffResult CreateWordDiffs(string oldText, string newText, bool ignoreWhitespace, char[] separators);

    /// <summary>
    /// Create a diff by comparing text in chunks determined by the supplied chunker function.
    /// </summary>
    /// <param name="oldText">The old text.</param>
    /// <param name="newText">The new text.</param>
    /// <param name="ignoreWhiteSpace">if set to <c>true</c> will ignore white space when determining if chunks are the same.</param>
    /// <param name="chunker">A function that will break the text into chunks.</param>
    /// <returns>A DiffResult object which details the differences</returns>
    DiffResult CreateCustomDiffs(string oldText, string newText, bool ignoreWhiteSpace, Func<string, string[]> chunker);

            /// <summary>
        /// Create a diff by comparing text line by line
        /// </summary>
        /// <param name="oldText">The old text.</param>
        /// <param name="newText">The new text.</param>
        /// <param name="ignoreWhiteSpace">if set to <c>true</c> will ignore white space when determining if lines are the same.</param>
        /// <param name="ignoreCase">Determine if the text comparision is case sensitive or not</param>
        /// <param name="chunker">Component responsible for tokenizing the compared texts</param>
        /// <returns>A DiffResult object which details the differences</returns>
        DiffResult CreateDiffs(string oldText, string newText, bool ignoreWhiteSpace, bool ignoreCase, IChunker chunker);
}

IChunker Interface

public interface IChunker
{
    /// <summary>
    /// Dive text into sub-parts
    /// </summary>
    string[] Chunk(string text);
}

Currently provided implementations:

  • CharacterChunker
  • CustomFunctionChunker
  • DelimiterChunker
  • LineChunker
  • LineEndingsPreservingChunker
  • WordChunker

ISideBySideDifferBuilder Interface

/// <summary>
/// Provides methods that generate differences between texts for displaying in a side by side view.
/// </summary>
public interface ISideBySideDiffBuilder
{
    /// <summary>
    /// Builds a diff model for  displaying diffs in a side by side view
    /// </summary>
    /// <param name="oldText">The old text.</param>
    /// <param name="newText">The new text.</param>
    /// <returns>The side by side diff model</returns>
    SideBySideDiffModel BuildDiffModel(string oldText, string newText);
}

Sample Website

DiffPlex also contains a sample website that shows how to create a basic side by side diff in an ASP MVC website.

Web page sample

Windows app

There are 2 libraries for Windows app development. One is for Windows App SDK, another is for WPF and WinForms.

WinUI 3 Elements

NuGet

DiffPlex WinUI library DiffPlex.Windows is used to render textual diffs in your app which targets to Windows App SDK.

using DiffPlex.UI;

And insert following code into the root node of your xaml file, e.g. user control, page or window.

xmlns:diffplex="using:DiffPlex.UI"
  • DiffTextView Textual diffs view element.

For example.

<diffplex:DiffTextView x:Name="DiffView" />
DiffView.SetText(OldText, NewText);

WinUI sample

You can also customize the style. Following are some of the properties you can get or set.

// true if it is in split view; otherwise, false, in unified view.
public bool IsSplitView { get; set; }

// true if it is in unified view; otherwise, false, in split view.
public bool IsUnifiedView { get; set; }

// The selection mode of list view. Default is None.
public ListViewSelectionMode SelectionMode { get; set; }

// true if ignore white spaces; otherwise, false. Default is true.
public bool IgnoreWhiteSpace { get; set; }

// true if the text is case sensitive; otherwise, false. Default is false.
public bool IsCaseSensitive { get; set; }

// The default text color (foreground brush).
public Brush Foreground { get; set; }

// The background.
public Brush Background { get; set; }

// The width of the line number. Default is 50.
public GridLength LineNumberWidth { get; set; }

// The style of the line number.
public Style LineNumberStyle { get; set; }

// The width of the change type symbol. Default is 20.
public GridLength ChangeTypeWidth { get; set; }

// The style of the change type symbol.
public Style ChangeTypeStyle { get; set; }

// The style of the text.
public Style TextStyle { get; set; }

// true if the text is selection enabled; otherwise, false. Default is true.
public bool IsTextSelectionEnabled { get; set; }

// true if collapse unchanged sections; otherwise, false. Default is false.
public bool IsUnchangedSectionCollapsed { get; set; }

// The lines for context. Default is 2.
public int LineCountForContext { get; set; }

// true if the file selector menu button is enabled; otherwise, false. Default is true.
public bool IsFileMenuEnabled { get; set; }

// The height of command bar. Default is 50.
public GridLength CommandBarHeight { get; set; }

// The default label position of command bar. Default is Right.
public CommandBarDefaultLabelPosition CommandLabelPosition { get; set; }

// The collection of secondary command elements for the command bar.
public IObservableVector<ICommandBarElement> SecondaryCommands { get; }

WPF Controls

NuGet

DiffPlex WPF control library DiffPlex.Wpf is used to render textual diffs in your WPF application. It targets .NET 6, .NET Framework 4.8 and .NET Framework 4.6.

using DiffPlex.Wpf.Controls;

To import the controls into your window/page/control, please insert following attribute into the root node (such as <Window />) of your xaml files.

xmlns:diffplex="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf"
  • DiffViewer Textual diffs viewer control with view mode switching by setting an old text and a new text to diff.
  • SideBySideDiffViewer Side-by-side (splitted) textual diffs viewer control by setting a diff model SideBySideDiffModel.
  • InlineDiffViewer Inline textual diffs viewer control by setting a diff model DiffPaneModel.

For example.

<diffplex:DiffViewer x:Name="DiffView" />
DiffView.OldText = oldText;
DiffView.NewText = newText;

WPF sample

You can also customize the style. Following are some of the properties you can get or set.

// The header of old text.
public string OldTextHeader { get; set; }

// The header of new text.
public string NewTextHeader { get; set; }

// true if it is in side-by-side (split) view;
// otherwise, false, in inline (unified) view.
public bool IsSideBySideViewMode { get; }

// true if collapse unchanged sections; otherwise, false.
public bool IgnoreUnchanged { get; set; }

// The font size.
public double FontSize { get; set; }

// The preferred font family.
public FontFamily FontFamily { get; set; }

// The font weight.
public FontWeight FontWeight { get; set; }

// The font style.
public FontStyle FontStyle { get; set; }

// The font-stretching characteristics.
public FontStretch FontStretch { get; set; }

// The default text color (foreground brush).
public Brush Foreground { get; set; }

// The background brush of the line inserted.
public Brush InsertedBackground { get; set; }

// The background brush of the line deleted.
public Brush DeletedBackground { get; set; }

// The text color (foreground brush) of the line number.
public Brush LineNumberForeground { get; set; }

// The width of the line number and change type symbol.
public int LineNumberWidth { get; set; }

// The background brush of the line imaginary.
public Brush ImaginaryBackground { get; set; }

// The text color (foreground brush) of the change type symbol.
public Brush ChangeTypeForeground { get; set; }

// The background brush of the header.
public Brush HeaderBackground { get; set; }

// The height of the header.
public double HeaderHeight { get; set; }

// The background brush of the grid splitter.
public Brush SplitterBackground { get; set; }

// The width of the grid splitter.
public Thickness SplitterWidth { get; set; }

// A value that represents the actual calculated width of the left side panel.
public double LeftSideActualWidth { get; }

// A value that represents the actual calculated width of the right side panel.
public double RightSideActualWidth { get; }

And you can listen following event handlers.

// Occurs when the grid splitter loses mouse capture.
public event DragCompletedEventHandler SplitterDragCompleted;

// Occurs one or more times as the mouse changes position when the grid splitter has logical focus and mouse capture.
public event DragDeltaEventHandler SplitterDragDelta;

// Occurs when the grid splitter receives logical focus and mouse capture.
public event DragStartedEventHandler SplitterDragStarted;

// Occurs when the view mode is changed.
public event EventHandler<ViewModeChangedEventArgs> ViewModeChanged;

WinForms Controls

NuGet

Windows Forms control of diff viewer is a WPF element host control. It is also included in DiffPlex.Wpf assembly. You can import it to use in your Windows Forms application. It targets .NET 6, .NET Framework 4.8 and .NET Framework 4.6.

using DiffPlex.WindowsForms.Controls;

Then you can add the following control in window or user control.

  • DiffViewer Textual diffs viewer control with view mode switching by setting an old text and a new text to diff.

For example.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var diffView = new DiffViewer
        {
            Margin = new Padding(0),
            Dock = DockStyle.Fill,
            OldText = oldText,
            NewText = newText
        };
        Controls.Add(diffView);
    }
}

Windows Forms sample

You can also customize the style. Following are some of the properties you can get or set.

// The header of old text.
public string OldTextHeader { get; set; }

// The header of new text.
public string NewTextHeader { get; set; }

// true if it is in side-by-side (split) view;
// otherwise, false, in inline (unified) view.
public bool IsSideBySideViewMode { get; }

// true if collapse unchanged sections; otherwise, false.
public bool IgnoreUnchanged { get; set; }

// The font size.
public double FontSize { get; set; }

// The preferred font family names in string.
public string FontFamilyNames { get; set; }

// The font weight.
public int FontWeight { get; set; }

// The font style.
public bool IsFontItalic { get; set; }

// The default text color (foreground brush).
public Color ForeColor { get; set; }

// The background brush of the line inserted.
public Color InsertedBackColor { get; set; }

// The background brush of the line deleted.
public Color DeletedBackColor { get; set; }

// The text color (foreground color) of the line number.
public Color LineNumberForeColor { get; set; }

// The width of the line number and change type symbol.
public int LineNumberWidth { get; set; }

// The background brush of the line imaginary.
public Color ImaginaryBackColor { get; set; }

// The text color (foreground color) of the change type symbol.
public Color ChangeTypeForeColor { get; set; }

// The background brush of the header.
public Color HeaderBackColor { get; set; }

// The height of the header.
public double HeaderHeight { get; set; }

// The background brush of the grid splitter.
public Color SplitterBackColor { get; set; }

// The width of the grid splitter.
public Padding SplitterWidth { get; set; }

// A value that represents the actual calculated width of the left side panel.
public double LeftSideActualWidth { get; }

// A value that represents the actual calculated width of the right side panel.
public double RightSideActualWidth { get; }

diffplex's People

Contributors

aarnott avatar azure-pipelines[bot] avatar cezarypiatek avatar daveyostcom avatar drake53 avatar drewnoakes avatar gantrior avatar igitur avatar jamesskemp avatar kbeatty-ascensionas avatar kingcean avatar michasacuer avatar mmanela avatar rjantz2 avatar sharwell avatar simoncropp 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

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.

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.

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.

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

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.

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?

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.

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?

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

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.

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?

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,

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.

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:

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

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.

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?

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.

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

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.

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!

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.

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

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.

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

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.

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

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 ......

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.

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.

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.

.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.

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.