Skip to content

Class StringReader

Namespace: Void.Minecraft.Commands.Brigadier
Assembly: Void.Minecraft.dll

Provides cursor-based parsing primitives for Brigadier command input.

public class StringReader : IImmutableStringReader

Inheritance

objectStringReader

Implements

IImmutableStringReader

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

StringReader(string, int)

Provides cursor-based parsing primitives for Brigadier command input.

public StringReader(string source, int cursor = 0)

Parameters

source string

The complete command input.

cursor int

The initial zero-based cursor.

StringReader(StringReader)

Creates a reader with the same source and cursor as another reader.

public StringReader(StringReader reader)

Parameters

reader StringReader

The reader state to copy.

Properties

CanRead

Gets whether at least one character can be read.

public bool CanRead { get; }

Property Value

bool

Cursor

Gets or sets the zero-based cursor.

public int Cursor { get; set; }

Property Value

int

Peek

Gets the character at the current cursor without advancing it.

public char Peek { get; }

Property Value

char

Read

Gets the source prefix before the cursor.

public string Read { get; }

Property Value

string

Remaining

Gets the source suffix beginning at the cursor.

public string Remaining { get; }

Property Value

string

RemainingLength

Gets the number of characters from the cursor through the end.

public int RemainingLength { get; }

Property Value

int

Source

Gets the complete source string.

public string Source { get; init; }

Property Value

string

TotalLength

Gets the total source length.

public int TotalLength { get; }

Property Value

int

Methods

CanReadLength(int)

Determines whether advancing the cursor by length characters remains within the source.

public bool CanReadLength(int length)

Parameters

length int

The number of characters to test from the current cursor position.

Returns

bool

true when length characters can be read without moving past ; otherwise, false.

Expect(char)

Consumes an expected character.

public void Expect(char character)

Parameters

character char

The required next character.

Exceptions

CommandSyntaxException

The source ended or the next character differs.

IsAllowedInUnquotedString(char)

Determines whether a character is accepted in an unquoted argument token.

public static bool IsAllowedInUnquotedString(char character)

Parameters

character char

The character to test.

Returns

bool

true for an ASCII letter, digit, underscore, hyphen, period, or plus.

IsAllowedNumber(char)

Determines whether a character may be consumed as part of a numeric token.

public static bool IsAllowedNumber(char digit)

Parameters

digit char

The character to test.

Returns

bool

true for an ASCII digit, period, or hyphen.

IsQuotedStringStart(char)

Determines whether a character opens a quoted string.

public static bool IsQuotedStringStart(char character)

Parameters

character char

The character to test.

Returns

bool

true for a single or double quote.

PeekAt(int)

Gets a character at an offset from the cursor without advancing it.

public char PeekAt(int offset)

Parameters

offset int

The relative character offset.

Returns

char

The selected character.

ReadBoolean()

Reads a quoted or unquoted Boolean token.

public bool ReadBoolean()

Returns

bool

The parsed Boolean.

Exceptions

CommandSyntaxException

No token is present or the token is not true or false.

ReadDouble()

Reads a double-precision token using the current culture.

public double ReadDouble()

Returns

double

The parsed value.

Exceptions

CommandSyntaxException

No numeric token is present or it is not a valid double.

ReadFloat()

Reads a single-precision token using the current culture.

public float ReadFloat()

Returns

float

The parsed value.

Exceptions

CommandSyntaxException

No numeric token is present or it is not a valid float.

ReadInt()

Reads a signed 32-bit integer token using the current culture.

public int ReadInt()

Returns

int

The parsed integer.

Exceptions

CommandSyntaxException

No numeric token is present or it is not a valid integer.

ReadLong()

Reads a signed 64-bit integer token using the current culture.

public long ReadLong()

Returns

long

The parsed long integer.

Exceptions

CommandSyntaxException

No numeric token is present or it is not a valid long integer.

ReadNext()

Returns the current character and advances the cursor by one.

public char ReadNext()

Returns

char

The consumed character.

ReadQuotedString()

Reads a single- or double-quoted string including escape processing.

public string ReadQuotedString()

Returns

string

The unescaped contents, or an empty string at end of input.

Exceptions

CommandSyntaxException

The next character is not a quote, an escape is invalid, or the quote is unclosed.

ReadString()

Reads either a quoted string or an unquoted token according to the next character.

public string ReadString()

Returns

string

The parsed string, or an empty string at end of input.

Exceptions

CommandSyntaxException

A quoted token contains an invalid escape or is unclosed.

ReadStringUntil(char)

Reads through an unescaped terminator and processes backslash escapes.

public string ReadStringUntil(char terminator)

Parameters

terminator char

The quote character that ends the string.

Returns

string

The unescaped contents without the terminator.

Exceptions

CommandSyntaxException

An escape targets an unsupported character or the terminator is absent.

ReadUnquotedString()

Reads consecutive characters accepted by .

public string ReadUnquotedString()

Returns

string

The consumed string, which may be empty.

Skip()

Advances the cursor by one without reading the character.

public void Skip()

SkipWhitespace()

Advances past consecutive Unicode whitespace characters.

public void SkipWhitespace()