In This Article

ITextSnapshotReader Interface

Provides the base requirements for an object that reads through characters and tokens from an ITextSnapshot.

public interface ITextSnapshotReader

Properties

BufferReader

Gets the ITextBufferReader that is wrapped by this reader and can be used for performing fast low-level text scanning on the snapshot.

ITextBufferReader BufferReader { get; }

Property Value

ITextBufferReader:

The ITextBufferReader that can be used for performing fast low-level text scanning on the snapshot.

Character

Gets the character at the Offset.

char Character { get; }

Property Value

char:

The character at the Offset.

Remarks

This value is the same as the return value of the PeekCharacter() method.

IsAtSnapshotEnd

Gets whether the current Offset is at the end of the snapshot.

bool IsAtSnapshotEnd { get; }

Property Value

bool:

true if the current Offset is at the end of the snapshot; otherwise, false.

IsAtSnapshotLineEnd

Gets whether the current Offset is at the end of an ITextSnapshotLine.

bool IsAtSnapshotLineEnd { get; }

Property Value

bool:

true if the current Offset is at the end of an ITextSnapshotLine; otherwise, false.

IsAtSnapshotLineStart

Gets whether the current Offset is at the start of an ITextSnapshotLine.

bool IsAtSnapshotLineStart { get; }

Property Value

bool:

true if the current Offset is at the start of an ITextSnapshotLine; otherwise, false.

IsAtSnapshotStart

Gets whether the current Offset is at the start of the snapshot.

bool IsAtSnapshotStart { get; }

Property Value

bool:

true if the current Offset is at the start of the snapshot; otherwise, false.

IsAtTokenStart

Gets whether the current Offset is at the start of the Token.

bool IsAtTokenStart { get; }

Property Value

bool:

true if the current Offset is at the start of the Token; otherwise, false.

IsCharacterLineTerminator

Gets whether the Character is a newline character.

bool IsCharacterLineTerminator { get; }

Property Value

bool:

true if the Character is a newline character; otherwise, false.

IsCharacterWhitespace

Gets whether the Character is categorized as a whitespace character.

bool IsCharacterWhitespace { get; }

Property Value

bool:

true if the Character is categorized as a whitespace character; otherwise, false.

Language

Gets the ISyntaxLanguage that contains the current offset within the snapshot.

ISyntaxLanguage Language { get; }

Property Value

ISyntaxLanguage:

The ISyntaxLanguage that contains the current offset within the snapshot.

Length

Gets the length of the snapshot.

int Length { get; }

Property Value

int:

The length of the snapshot.

Offset

Gets or sets the current offset within the snapshot.

int Offset { get; set; }

Property Value

int:

The current offset within the snapshot.

Options

Gets the ITextSnapshotReaderOptions that contains optimization options for the reader.

ITextSnapshotReaderOptions Options { get; }

Property Value

ITextSnapshotReaderOptions:

The ITextSnapshotReaderOptions that contains optimization options for the reader.

Remarks

Configure the options before accessing any members on this reader instance.

Position

Gets the current TextPosition within the snapshot.

TextPosition Position { get; }

Property Value

TextPosition:

The current TextPosition within the snapshot.

Snapshot

Gets the core ITextSnapshot that is examined by this reader.

ITextSnapshot Snapshot { get; }

Property Value

ITextSnapshot:

The core ITextSnapshot that is examined by this reader.

SnapshotLine

Gets the ITextSnapshotLine that contains the Offset.

ITextSnapshotLine SnapshotLine { get; }

Property Value

ITextSnapshotLine:

The ITextSnapshotLine that contains the Offset.

Token

Gets the IToken that contains the offset indicated by Offset.

IToken Token { get; }

Property Value

IToken:

The IToken that contains the offset indicated by Offset.

Remarks

This value is the same as the return value of the PeekToken() method.

TokenText

Gets the snapshot text contained by the Token.

string TokenText { get; }

Property Value

string:

The snapshot text contained by the Token.

Methods

GoToCurrentSnapshotLineEnd()

Moves the Offset to the end of the snapshot line that contains the Offset.

void GoToCurrentSnapshotLineEnd()

GoToCurrentSnapshotLineStart()

Moves the Offset to the start of the snapshot line that contains the Offset.

void GoToCurrentSnapshotLineStart()

GoToCurrentTokenStart()

Moves the Offset to the start of the IToken that contains the Offset.

void GoToCurrentTokenStart()

GoToCurrentWordEnd()

Moves to the current word's end offset.

bool GoToCurrentWordEnd()

Returns

bool:

true if the word end is found; otherwise, false.

Remarks

If a proper word end is not found, the reader's Offset will be the end of the snapshot.

GoToCurrentWordStart()

Moves to the current word's start offset.

bool GoToCurrentWordStart()

Returns

bool:

true if the word start is found; otherwise, false.

Remarks

If a proper word start is not found, the reader's Offset will be the beginning of the snapshot.

GoToNextMatchingTokenById(int, int)

Moves the Offset to the next matching token where there can be nested token pairs.

bool GoToNextMatchingTokenById(int startTokenId, int endTokenId)
Parameter Type Description
startTokenId int

The ID of the start IToken.

endTokenId int

The ID of the related end IToken for which to search.

Returns

bool:

true if the next matching token is found; otherwise, false.

Remarks

This method is useful for bracket matching.

GoToNextSnapshotLineStart()

Moves the Offset to the start of the snapshot line after the snapshot line that contains the Offset.

void GoToNextSnapshotLineStart()

GoToNextToken()

Moves to the next token's start offset.

bool GoToNextToken()

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextToken(int)

Moves backward the specified number of tokens.

bool GoToNextToken(int count)
Parameter Type Description
count int

The number of tokens to move.

Returns

bool:

true if a token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextToken(Predicate<IToken>)

Continues forward token scanning until the specified predicate returns true, at which time the reader points to the token's start offset.

bool GoToNextToken(Predicate<IToken> predicate)
Parameter Type Description
predicate Predicate<IToken>

The predicate to use. Return true to stop scanning; otherwise, false to continue scanning.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextTokenWithId(int)

Moves to the next token's start offset whose token ID matches the specified ID.

bool GoToNextTokenWithId(int id)
Parameter Type Description
id int

The token ID to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextTokenWithId(params int[])

Moves to the next token's start offset whose token ID matches any of the specified IDs.

bool GoToNextTokenWithId(params int[] ids)
Parameter Type Description
ids int[]

An array of token IDs to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextTokenWithKey(string)

Moves to the next token's start offset whose token key matches the specified key.

bool GoToNextTokenWithKey(string key)
Parameter Type Description
key string

The token key to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextTokenWithKey(params string[])

Moves to the next token's start offset whose token key matches any of the specified keys.

bool GoToNextTokenWithKey(params string[] keys)
Parameter Type Description
keys string[]

An array of token keys to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToNextWordStart()

Moves to the next word's start offset.

bool GoToNextWordStart()

Returns

bool:

true if the word start is found; otherwise, false.

Remarks

If a proper word start is not found, the reader's Offset will be the end of the snapshot.

GoToPreviousMatchingTokenById(int, int)

Moves the Offset to the previous matching token where there can be nested token pairs.

bool GoToPreviousMatchingTokenById(int endTokenId, int startTokenId)
Parameter Type Description
endTokenId int

The ID of the end IToken.

startTokenId int

The ID of the related start IToken for which to search.

Returns

bool:

true if the previous matching token is found; otherwise, false.

Remarks

This method is useful for bracket matching.

GoToPreviousSnapshotLineEnd()

Moves the Offset to the end of the snapshot line before the snapshot line that contains the Offset.

void GoToPreviousSnapshotLineEnd()

GoToPreviousToken()

Moves to the previous token's start offset.

bool GoToPreviousToken()

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the beginning of the snapshot.

GoToPreviousToken(int)

Moves backward the specified number of tokens.

bool GoToPreviousToken(int count)
Parameter Type Description
count int

The number of tokens to move.

Returns

bool:

true if a token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the beginning of the snapshot.

GoToPreviousToken(Predicate<IToken>)

Continues backward token scanning until the specified predicate returns true, at which time the reader points to the token's start offset.

bool GoToPreviousToken(Predicate<IToken> predicate)
Parameter Type Description
predicate Predicate<IToken>

The predicate to use. Return true to stop scanning; otherwise, false to continue scanning.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the end of the snapshot.

GoToPreviousTokenWithId(int)

Moves to the previous token's start offset whose token ID matches the specified ID.

bool GoToPreviousTokenWithId(int id)
Parameter Type Description
id int

The token ID to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the beginning of the snapshot.

GoToPreviousTokenWithId(params int[])

Moves to the previous token's start offset whose token ID matches any of the specified IDs.

bool GoToPreviousTokenWithId(params int[] ids)
Parameter Type Description
ids int[]

An array of token IDs to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the beginning of the snapshot.

GoToPreviousTokenWithKey(string)

Moves to the previous token's start offset whose token key matches the specified key.

bool GoToPreviousTokenWithKey(string key)
Parameter Type Description
key string

The token key to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the beginning of the snapshot.

GoToPreviousTokenWithKey(params string[])

Moves to the previous token's start offset whose token key matches any of the specified keys.

bool GoToPreviousTokenWithKey(params string[] keys)
Parameter Type Description
keys string[]

An array of token keys to look for.

Returns

bool:

true if the token is found; otherwise, false.

Remarks

If a token is not found, the stream's Offset will be the beginning of the snapshot.

GoToPreviousWordStart()

Moves to the previous word's start character.

bool GoToPreviousWordStart()

Returns

bool:

true if the word start is found; otherwise, false.

Remarks

If a proper word start is not found, the reader's Offset will be the beginning of the snapshot.

GoToSnapshotEnd()

Moves the Offset to the end of the Snapshot.

void GoToSnapshotEnd()

GoToSnapshotStart()

Moves the Offset to the start of the Snapshot.

void GoToSnapshotStart()

PeekCharacter()

Peeks at a single character without seeking past it.

char PeekCharacter()

Returns

char:

The character that was read.

PeekCharacterReverse()

Reverse peeks at a single character without seeking past it.

char PeekCharacterReverse()

Returns

char:

The character that was read.

PeekText(int)

Peeks at a string without seeking past it.

string PeekText(int maxCharCount)
Parameter Type Description
maxCharCount int

The maximum number of characters to read, if the end of the snapshot is not reached beforehand.

Returns

string:

The string that was read.

PeekTextReverse(int)

Reverse peeks at a string without seeking past it.

string PeekTextReverse(int maxCharCount)
Parameter Type Description
maxCharCount int

The maximum number of characters to read, if the start of the snapshot is not reached beforehand.

Returns

string:

The string that was read.

PeekToken()

Peeks at a single IToken from the snapshot without seeking past it.

IToken PeekToken()

Returns

IToken:

The IToken that was read.

PeekTokenReverse()

Reverse peeks at a single IToken from the snapshot without seeking past it.

IToken PeekTokenReverse()

Returns

IToken:

The IToken that was read.

ReadCharacter()

Reads a single character and seeks forward one offset.

char ReadCharacter()

Returns

char:

The character that was read.

ReadCharacterReverse()

Reverse reads a single character and seeks backward one offset.

char ReadCharacterReverse()

Returns

char:

The character that was read.

ReadCharacterReverseThrough(char)

Reverse reads characters from the snapshot until the specified character is read through.

bool ReadCharacterReverseThrough(char ch)
Parameter Type Description
ch char

The desired character.

Returns

bool:

true if the desired character was read; otherwise, false if the start of the snapshot was reached.

ReadCharacterReverseThrough(char, int)

Reverse reads characters from the snapshot until the specified character is read through, or the specified offset is reached.

bool ReadCharacterReverseThrough(char ch, int minOffset)
Parameter Type Description
ch char

The desired character.

minOffset int

The minimum offset to check.

Returns

bool:

true if the desired character was read; otherwise, false if the specified offset was reached.

ReadCharacterThrough(char)

Reads characters from the snapshot until the specified character is read through.

bool ReadCharacterThrough(char ch)
Parameter Type Description
ch char

The desired character.

Returns

bool:

true if the desired character was read; otherwise, false if the end of the snapshot was reached.

ReadCharacterThrough(char, int)

Reads characters from the snapshot until the specified character is read through, or the specified offset is reached.

bool ReadCharacterThrough(char ch, int maxOffset)
Parameter Type Description
ch char

The desired character.

maxOffset int

The maximum offset to check.

Returns

bool:

true if the desired character was read; otherwise, false if the specified offset was reached.

ReadText(int)

Reads a string and seeks forward to the end of it.

string ReadText(int maxCharCount)
Parameter Type Description
maxCharCount int

The maximum number of characters to read, if the end of the snapshot is not reached beforehand.

Returns

string:

The string that was read.

ReadTextReverse(int)

Reverse reads a string and seeks backward to the start of it.

string ReadTextReverse(int maxCharCount)
Parameter Type Description
maxCharCount int

The maximum number of characters to read, if the start of the snapshot is not reached beforehand.

Returns

string:

The string that was read.

ReadToken()

Reads a single IToken from the snapshot and seeks forward one IToken.

IToken ReadToken()

Returns

IToken:

The IToken that was read.

ReadTokenReverse()

Reverse reads a single IToken from the snapshot and seeks backward one IToken.

IToken ReadTokenReverse()

Returns

IToken:

The IToken that was read.

SeekCharacter(int)

Moves the Offset by the specified amount.

void SeekCharacter(int delta)
Parameter Type Description
delta int

The amount of characters to move. This value may be negative.