TextDiffOptions Class
public sealed class TextDiffOptionsNo documentation is available.
Constructors
| Name | Description |
|---|---|
| TextDiffOptions() |
TextDiffOptions()
TextDiffOptions.cspublic TextDiffOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| Algorithm | Gets or sets the algorithm used to compute the diff. TextDiffAlgorithm.Myers is the default and is recommended for general use. |
| Chunker | Gets or sets how the texts are split into the chunks that are compared against each other. Defaults to TextChunker.Lines. |
| CompareOptions | Gets or sets the options of a culture-aware comparison of the chunks, such as CompareOptions.IgnoreNonSpace to ignore accents. Defaults to CompareOptions.None. |
| Culture | 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. |
| DetectMoves | 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. |
| IgnoreCase | Gets or sets a value indicating whether two chunks that differ only in casing are considered equal. |
| IgnoreEndOfLine | 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. |
| IgnoreWhitespace | Gets or sets a value indicating whether the leading and trailing whitespace of a chunk is ignored when comparing chunks. |
| MaxEditCost | 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. |
| Timeout | Gets or sets the time after which the diff stops searching for matching chunks. Defaults to null: no time limit. |
Algorithm
TextDiffOptions.csGets 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
Chunker
TextDiffOptions.csGets 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
CompareOptions
TextDiffOptions.csGets 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
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.
Culture
TextDiffOptions.csGets 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
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.
DetectMoves
TextDiffOptions.csGets 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
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.
IgnoreCase
TextDiffOptions.csGets or sets a value indicating whether two chunks that differ only in casing are considered equal.
public bool IgnoreCase { get; set; }Property value
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.csGets 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
Remarks
The normalization happens before chunking, so the entries of the result carry the normalized text rather than the original line terminators.
IgnoreWhitespace
TextDiffOptions.csGets 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
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.
MaxEditCost
TextDiffOptions.csGets 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
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.
Timeout
TextDiffOptions.csGets 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
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.