Skip to main content

Interface IBuffer

Namespace: OceanApocalypse.RSML.Toolchain.Abstractions.Sources
Assembly: RSML.Toolchain.Abstractions.dll

Represents a buffer of characters.

public interface IBuffer : IDisposable, IEquatable<IBuffer>, IEquatable<Char[]?>, IEquatable<String?>, IEquatable<ReadOnlyMemory<Char>>

Implements

IDisposable, IEquatable<IBuffer>, IEquatable<Char[]?>, IEquatable<String?>, IEquatable<ReadOnlyMemory<Char>>

Properties

IsEmpty

Whether the source is completely empty.

Boolean IsEmpty { get; }

Property Value

Boolean

IsReadOnly

Whether the source can be mutated.

Boolean IsReadOnly { get; }

Property Value

Boolean

Length

The length of the source.

Int32 Length { get; }

Property Value

Int32

LineCount

The total amount of lines in the buffer.

Int32 LineCount { get; }

Property Value

Int32

Remarks

Keep in mind lines might be empty.

this[Int32]

Gets a single item out of the buffer.

Char this[Int32 index] { get; }

Property Value

Char

this[SourceLocation]

Gets a single item out of the buffer.

Char this[SourceLocation location] { get; }

Property Value

Char

Methods

CountUntilEndOfLine(Int32, out Boolean)

Counts the amount of items until the next line separator in the buffer, relative to a given index. Only line separators count - regular whitespace do not. CRLF counts as a single line separator, to avoid double counting.

Int32 CountUntilEndOfLine(Int32 index, out Boolean isCrLf)

Parameters

index Int32

The index at which to start counting.

isCrLf Boolean

Whether the line separator at which the method stopped is the CR in a CRLF sequence. If true, the next item in the buffer is LF.

Returns

Int32

The index of the next line separator, relative to an index.

CountUntilNotWhitespace(Int32)

Counts the amount of items until the next non-whitespace item in the buffer, relative to a given index. Line separators are included in the whitespace category.

Int32 CountUntilNotWhitespace(Int32 index)

Parameters

index Int32

The index at which to start counting.

Returns

Int32

The index of the next non-whitespace item, relative to a index.

CountUntilWhitespace(Int32)

Counts the amount of items until the next whitespace item in the buffer, relative to a given index. Line separators are included in the whitespace category.

Int32 CountUntilWhitespace(Int32 index)

Parameters

index Int32

The index at which to start counting.

Returns

Int32

The index of the next whitespace item, relative to a index.

CountWhile(Func<Int32, Char, Boolean>, Int32)

Counts the amount of items, starting from a given index, while a predicate returns true.

Int32 CountWhile(Func<Int32, Char, Boolean> predicate, Int32 index)

Parameters

predicate Func<Int32, Char, Boolean>

A function that takes the current index (relative to index), which is incremented every item, and the item associated with it. Execution stops when the predicate returns false or the index is out of bounds.

index Int32

The index at which to start counting; all indexes will also be given to the predicate as an offset that when added to the index of the position equal the actual index.

Returns

Int32

The amount of items counted.

GetLengthOfLine(Int32)

Returns the length of a line given its 0-based line number. Line separators do not count towards the length.

Int32 GetLengthOfLine(Int32 lineNumber)

Parameters

lineNumber Int32

The 0-based line number.

Returns

Int32

The length of the line.

GetLengthOfLineFromIndex(Int32)

Returns the length of a line given a 0-based index of one of its items. Line separators do not count towards the length.

Int32 GetLengthOfLineFromIndex(Int32 index)

Parameters

index Int32

The 0-based index whose line is considered.

Returns

Int32

The length of the line.

GetLine(Int32)

Given a 0-based line number, returns the matching line as an array of buffer items.

ReadOnlySpan<Char> GetLine(Int32 lineNumber)

Parameters

lineNumber Int32

The 0-based line number.

Returns

ReadOnlySpan<Char>

The line as an array of items.

GetLineFromIndex(Int32)

Tries to read the line that contains the item at index. No end of line characters are added.

ReadOnlySpan<Char> GetLineFromIndex(Int32 index)

Parameters

index Int32

The index at which to determine what the current line is.

Returns

ReadOnlySpan<Char>

The line, as an array of items.

GetLineNumberFromIndex(Int32)

Determines the 0-based line number of the line that contains the item located at index.

Int32 GetLineNumberFromIndex(Int32 index)

Parameters

index Int32

The index whose parent line's number is to be returned.

Returns

Int32

The 0-based number of the line that contains item located at index.

GetSourceLocation(Int32)

Converts an index into a location.

SourceLocation GetSourceLocation(Int32 index)

Parameters

index Int32

The index.

Returns

SourceLocation

The location.

GetSourceSpan(Int32, Int32)

Converts the buffer region into a span.

SourceSpan GetSourceSpan(Int32 startIndex, Int32 endIndex)

Parameters

startIndex Int32

The starting index.

endIndex Int32

The end index, which is included in the span.

Returns

SourceSpan

The span.

Slice(Int32, Int32)

Slices a region of the buffer.

ReadOnlySpan<Char> Slice(Int32 start, Int32 length)

Parameters

start Int32

The index of the first item in the slice.

length Int32

The amount of items to slice starting at start.

Returns

ReadOnlySpan<Char>

A slice, as an array of items.

TryGetChar(Int32, out Char)

Tries to return the item at index.

Boolean TryGetChar(Int32 index, out Char item)

Parameters

index Int32

The index of the character.

item Char

The item.

Returns

Boolean

False if the buffer is out of bounds or an exception occured.

TryGetChar(SourceLocation, out Char)

Tries to return the item at the specified location.

Boolean TryGetChar(SourceLocation location, out Char item)

Parameters

location SourceLocation

The item's location.

item Char

The item.

Returns

Boolean

False if the buffer is out of bounds or an exception occured.

TryGetLine(Int32, Span<Char>)

Given a 0-based line number, assigns the exact line to a result buffer (destination). No end of line characters are added.

Boolean TryGetLine(Int32 lineNumber, Span<Char> destination)

Parameters

lineNumber Int32

The 0-based line number.

destination Span<Char>

The destination buffer for the line.

Returns

Boolean

True if successful.

TryGetLineFromIndex(Int32, Span<Char>)

Tries to read the line that contains the item at index. No end of line characters are added.

Boolean TryGetLineFromIndex(Int32 index, Span<Char> destination)

Parameters

index Int32

The index at which to determine what the current line is.

destination Span<Char>

The destination span that will contain the line.

Returns

Boolean

True if successful.

TrySlice(Int32, Span<Char>)

Slices a region of the buffer into a performant span.

Boolean TrySlice(Int32 start, Span<Char> slice)

Parameters

start Int32

The index of the first item in the slice.

slice Span<Char>

The span serving as the destination for the slice.

Returns

Boolean

TrySlice(SourceSpan, Span<Char>)

Slices a region of the buffer into a performant span.

Boolean TrySlice(SourceSpan sourceSpan, Span<Char> slice)

Parameters

sourceSpan SourceSpan

The span indicating what the slice is.

slice Span<Char>

The span serving as the destination for the slice.

Returns

Boolean