TextChunker Class
Splits a text into the chunks that a diff compares against each other. Derive from this type and override TextChunker.Chunk to supply a custom chunking strategy.
public class TextChunkerConstructors
| Name | Description |
|---|---|
| TextChunker() |
TextChunker()
public TextChunker()No documentation is available.
Properties
| Name | Description |
|---|---|
| Characters | Gets a chunker that produces one chunk per Char. |
| Lines | Gets a chunker that splits on line terminators, keeping the terminator at the end of each chunk so the text can be rebuilt exactly. |
| Words | Gets a chunker that alternates between runs of non-whitespace and runs of whitespace, so that whitespace is preserved in its own chunks. |
Characters
TextChunker.csGets a chunker that produces one chunk per Char.
public static TextChunker Characters { get; }Property value
Remarks
Chunks are UTF-16 code units, not grapheme clusters: a surrogate pair is split into two chunks.
Lines
TextChunker.csGets a chunker that splits on line terminators, keeping the terminator at the end of each chunk so the text can be rebuilt exactly.
public static TextChunker Lines { get; }Property value
Remarks
A text that ends with a line terminator produces a final empty chunk, and an empty text produces a single empty chunk. This is what makes the chunks concatenate back to the original text; TextChunker.Words and TextChunker.Characters produce no chunks at all for an empty text.
Words
TextChunker.csGets a chunker that alternates between runs of non-whitespace and runs of whitespace, so that whitespace is preserved in its own chunks.
public static TextChunker Words { get; }Property value
Methods
| Name | Description |
|---|---|
| Chunk(ReadOnlySpan<char>) | Splits value into chunks. |
Chunk(ReadOnlySpan<char>)
TextChunker.csSplits value into chunks.
public virtual IEnumerable<string> Chunk(ReadOnlySpan<char> value)Parameters
valueReadOnlySpan<char>- The text to split.
Returns
IEnumerable<string> The chunks, in order. Concatenating them should reproduce value exactly, otherwise the diff cannot be used to rebuild either text.
Remarks
The base implementation delegates to TextChunker.Lines. A derived chunker that does not override this method therefore produces line chunks rather than failing.