TextDiffOptions Class

public sealed class TextDiffOptions

No documentation is available.

Constructors

NameDescription
TextDiffOptions()

TextDiffOptions()

TextDiffOptions.cs
public TextDiffOptions()

No documentation is available.

Properties

NameDescription
AlgorithmGets or sets the algorithm used to compute the diff. TextDiffAlgorithm.Myers is the default and is recommended for general use.
ChunkerGets or sets how the texts are split into the chunks that are compared against each other. Defaults to TextChunker.Lines.
CompareOptionsGets or sets the options of a culture-aware comparison of the chunks, such as CompareOptions.IgnoreNonSpace to ignore accents. Defaults to CompareOptions.None.
CultureGets or sets the culture whose rules compare the chunks. Defaults to null: the chunks are compared ordinally, unless TextDiffOptions.CompareOptions is set, which then uses CultureInfo.InvariantCulture.
DetectMovesGets or sets a value indicating whether TextDiff.ComputeDiff looks for blocks of chunks that are deleted at one place and inserted at another. Defaults to false.
IgnoreCaseGets or sets a value indicating whether two chunks that differ only in casing are considered equal.
IgnoreEndOfLineGets or sets a value indicating whether line terminators are normalized to "\n" before the texts are chunked, so that "\r\n", "\r" and "\n" compare equal.
IgnoreWhitespaceGets or sets a value indicating whether the leading and trailing whitespace of a chunk is ignored when comparing chunks.
MaxEditCostGets or sets the maximum number of deleted and inserted chunks the Myers search looks for in a region before it settles for a diff that may not be minimal. Defaults to null: no limit, the diff is minimal.
TimeoutGets or sets the time after which the diff stops searching for matching chunks. Defaults to null: no time limit.

Gets or sets the algorithm used to compute the diff. TextDiffAlgorithm.Myers is the default and is recommended for general use.

public TextDiffAlgorithm Algorithm { get; set; }

Property value

TextDiffAlgorithm

Gets or sets how the texts are split into the chunks that are compared against each other. Defaults to TextChunker.Lines.

public TextChunker Chunker { get; set; }

Property value

TextChunker

CompareOptions

TextDiffOptions.cs

Gets or sets the options of a culture-aware comparison of the chunks, such as CompareOptions.IgnoreNonSpace to ignore accents. Defaults to CompareOptions.None.

public CompareOptions CompareOptions { get; set; }

Property value

CompareOptions

Remarks

Any value but CompareOptions.None compares the chunks with the CompareInfo of TextDiffOptions.Culture, or of CultureInfo.InvariantCulture when TextDiffOptions.Culture is null. CompareOptions.Ordinal, CompareOptions.OrdinalIgnoreCase and CompareOptions.StringSort are not supported: leave both properties unset for an ordinal comparison.

Gets or sets the culture whose rules compare the chunks. Defaults to null: the chunks are compared ordinally, unless TextDiffOptions.CompareOptions is set, which then uses CultureInfo.InvariantCulture.

public CultureInfo? Culture { get; set; }

Property value

CultureInfo?

Remarks

A culture-aware comparison treats canonically equivalent strings as equal, such as "\u00E9" and "e\u0301". It depends on ICU: in invariant globalization mode, it is ordinal.

Gets or sets a value indicating whether TextDiff.ComputeDiff looks for blocks of chunks that are deleted at one place and inserted at another. Defaults to false.

public bool DetectMoves { get; set; }

Property value

bool

Remarks

A moved block is still reported as TextDiffOperation.Delete entries where it was and TextDiffOperation.Insert entries where it is now, so the entries rebuild both texts as usual. The entries of both places share the same TextDiffEntry.MoveId.

A block of chunks that holds only whitespace is never a move, and neither is a block deleted and inserted at the same place. TextDiff.ComputeHierarchyDiff does not detect moves.

Gets or sets a value indicating whether two chunks that differ only in casing are considered equal.

public bool IgnoreCase { get; set; }

Property value

bool

Remarks

The comparison is ordinal, so casing rules are not culture-sensitive, unless TextDiffOptions.Culture or TextDiffOptions.CompareOptions is set: CompareOptions.IgnoreCase is then added to the culture-aware comparison.

IgnoreEndOfLine

TextDiffOptions.cs

Gets or sets a value indicating whether line terminators are normalized to "\n" before the texts are chunked, so that "\r\n", "\r" and "\n" compare equal.

public bool IgnoreEndOfLine { get; set; }

Property value

bool

Remarks

The normalization happens before chunking, so the entries of the result carry the normalized text rather than the original line terminators.

IgnoreWhitespace

TextDiffOptions.cs

Gets or sets a value indicating whether the leading and trailing whitespace of a chunk is ignored when comparing chunks.

public bool IgnoreWhitespace { get; set; }

Property value

bool

Remarks

Only the edges of a chunk are trimmed; whitespace inside a chunk remains significant. With the default TextChunker.Lines chunker, "a b" and "a b" are still different. Use TextChunker.Words to make internal whitespace insignificant: it puts each run of whitespace in its own chunk, which trimming then reduces to an empty one.

Gets or sets the maximum number of deleted and inserted chunks the Myers search looks for in a region before it settles for a diff that may not be minimal. Defaults to null: no limit, the diff is minimal.

public int? MaxEditCost { get; set; }

Property value

int?

Remarks

The cost of the Myers search grows with the square of the number of differences. When the shortest edit script of a region needs more than this many deleted and inserted chunks, the search stops and splits the region at the furthest point it reached, as git does, then diffs both parts. A region that needs at most this many edits is still diffed exactly.

The limit applies to TextDiffAlgorithm.Myers, and to the regions TextDiffAlgorithm.Patience and TextDiffAlgorithm.Histogram hand to Myers. TextDiffAlgorithm.HuntSzymanski does not use it; use TextDiffOptions.Timeout to bound it.

Gets or sets the time after which the diff stops searching for matching chunks. Defaults to null: no time limit.

public TimeSpan? Timeout { get; set; }

Property value

TimeSpan?

Remarks

Once the time limit is reached, every region of the texts that is not diffed yet is reported as deleted and inserted as a whole, so the diff completes quickly and is still valid: it rebuilds both texts, but may report as changed chunks that a full search would match. The common start and end of a region are still matched. A null value and Timeout.InfiniteTimeSpan disable the limit.