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
StreamThe underlying stream as data source.
encoding
EncodingThe 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
stringThe data source.
Properties
CurrentEncoding
Gets or sets the encoding to use.
public Encoding CurrentEncoding { get; set; }
Property Value
Index
Gets or sets the current index of the insertation and read point.
public int Index { get; set; }
Property Value
this[int]
Gets the character at the given position in the text buffer.
public char this[int index] { get; }
Parameters
index
intThe index of the character.
Property Value
- char
The character.
Length
Gets the length of the text buffer.
public int Length { get; }
Property Value
Text
Gets the full text buffer.
public string Text { get; }
Property Value
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
stringThe content to insert.
PrefetchAllAsync(CancellationToken)
Prefetches the whole stream by expanding the internal buffer.
public Task PrefetchAllAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationTokenThe 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
intThe number of bytes to prefetch.
cancellationToken
CancellationTokenThe 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
intThe number of characters to read.
Returns
- string
The string with the next characters.