Table of Contents

Class TextSource

Namespace
AngleSharp.Text
Assembly
AngleSharp.dll

A stream abstraction to handle encoding and more.

public sealed class TextSource : IDisposable
Inheritance
TextSource
Implements
Inherited Members
Extension Methods

Constructors

TextSource(Stream, Encoding)

Creates a new text source from a string. The underlying stream is used as an unknown data source.

public TextSource(Stream baseStream, Encoding encoding = null)

Parameters

baseStream Stream

The underlying stream as data source.

encoding Encoding

The initial encoding. Otherwise UTF-8.

TextSource(string)

Creates a new text source from a string. No underlying stream will be used.

public TextSource(string source)

Parameters

source string

The data source.

Properties

CurrentEncoding

Gets or sets the encoding to use.

public Encoding CurrentEncoding { get; set; }

Property Value

Encoding

Index

Gets or sets the current index of the insertation and read point.

public int Index { get; set; }

Property Value

int

this[int]

Gets the character at the given position in the text buffer.

public char this[int index] { get; }

Parameters

index int

The index of the character.

Property Value

char

The character.

Length

Gets the length of the text buffer.

public int Length { get; }

Property Value

int

Text

Gets the full text buffer.

public string Text { get; }

Property Value

string

Methods

Dispose()

Disposes the text source by freeing the underlying stream, if any.

public void Dispose()

InsertText(string)

Inserts the given content at the current insertation mark. Moves the insertation mark.

public void InsertText(string content)

Parameters

content string

The content to insert.

PrefetchAllAsync(CancellationToken)

Prefetches the whole stream by expanding the internal buffer.

public Task PrefetchAllAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task

The awaitable task.

PrefetchAsync(int, CancellationToken)

Prefetches the number of bytes by expanding the internal buffer.

public Task PrefetchAsync(int length, CancellationToken cancellationToken)

Parameters

length int

The number of bytes to prefetch.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

The awaitable task.

ReadCharacter()

Reads the next character from the buffer or underlying stream, if any.

public char ReadCharacter()

Returns

char

The next character.

ReadCharacters(int)

Reads the upcoming numbers of characters from the buffer or underlying stream, if any.

public string ReadCharacters(int characters)

Parameters

characters int

The number of characters to read.

Returns

string

The string with the next characters.