CommandAPI 9.7.0
An API for the command UI introduced in Minecraft 1.13
com.mojang.brigadier.context.StringRange Class Reference

A range within a string, i.e. More...

Public Member Functions

 StringRange (final int start, final int end)
 Creates a new StringRange with the given start and end index. More...
 
int getStart ()
 Returns the start of this StringRange (inclusive). More...
 
int getEnd ()
 Returns the end of this StringRange (exclusive). More...
 
String get (final ImmutableStringReader reader)
 Applies this range to the complete String of the passed ImmutableStringReader, returning all characters from it that lie within this range. More...
 
String get (final String string)
 Returns the substring of the passed string, that is defined by this range. More...
 
boolean isEmpty ()
 Checks if this range is empty, i.e. More...
 
int getLength ()
 Returns the length of this string range. More...
 
boolean equals (final Object o)
 
int hashCode ()
 
String toString ()
 

Static Public Member Functions

static StringRange at (final int pos)
 Returns a StringRange containing no index. More...
 
static StringRange between (final int start, final int end)
 Returns a StringRange with the given start and end indices. More...
 
static StringRange encompassing (final StringRange a, final StringRange b)
 Returns a StringRange} that wraps around both passed StringRanges. More...
 

Detailed Description

A range within a string, i.e.

the start and end values of a substring.

Constructor & Destructor Documentation

◆ StringRange()

com.mojang.brigadier.context.StringRange.StringRange ( final int  start,
final int  end 
)

Creates a new StringRange with the given start and end index.

Parameters
startthe start index (inclusive)
endthe end index (exclusive)

Member Function Documentation

◆ at()

static StringRange com.mojang.brigadier.context.StringRange.at ( final int  pos)
static

Returns a StringRange containing no index.

Parameters
posthe minimum and maximum index of the range
Returns
a StringRange that includes no index

◆ between()

static StringRange com.mojang.brigadier.context.StringRange.between ( final int  start,
final int  end 
)
static

Returns a StringRange with the given start and end indices.

Parameters
startthe start index (inclusive)
endthe end index (exclusive)
Returns
a StringRange spanning the given range

◆ encompassing()

static StringRange com.mojang.brigadier.context.StringRange.encompassing ( final StringRange  a,
final StringRange  b 
)
static

Returns a StringRange} that wraps around both passed StringRanges.

Parameters
athe first StringRange
bthe second StringRange
Returns
a StringRange that includes everything from the lowest (inclusive) to the highest index (exclusive) from both ranges

◆ get() [1/2]

String com.mojang.brigadier.context.StringRange.get ( final ImmutableStringReader  reader)

Applies this range to the complete String of the passed ImmutableStringReader, returning all characters from it that lie within this range.

Equivalent to: reader.getString().substring(range.getStart(), range.getEnd()

Parameters
readerthe string reader to read from
Returns
the substring of the passed reader that is defined by this range

◆ get() [2/2]

String com.mojang.brigadier.context.StringRange.get ( final String  string)

Returns the substring of the passed string, that is defined by this range.

Equivalent to: string.substring(range.getStart(), range.getEnd()

Parameters
stringthe string to get the substring from
Returns
all characters in this range in the passed string

◆ getEnd()

int com.mojang.brigadier.context.StringRange.getEnd ( )

Returns the end of this StringRange (exclusive).

Returns
the end of this StringRange (exclusive)

◆ getLength()

int com.mojang.brigadier.context.StringRange.getLength ( )

Returns the length of this string range.

Returns
the length of this string range

◆ getStart()

int com.mojang.brigadier.context.StringRange.getStart ( )

Returns the start of this StringRange (inclusive).

Returns
the start of this StringRange (inclusive)

◆ isEmpty()

boolean com.mojang.brigadier.context.StringRange.isEmpty ( )

Checks if this range is empty, i.e.

contains not even a single index.

Returns
true if this range is empty, i.e. contains not even a single index