{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TextRange

value public final class TextRange


An immutable text range class, represents a text range from start (inclusive) to end (exclusive). end can be smaller than start and in those cases min and max can be used in order to fetch the values.

Summary

Nested types

public static class TextRange.Companion

Public methods

final boolean
contains(int offset)

Returns true if the given offset is a part of this range.

final boolean

Returns true if this range covers including equals with the given range.

final boolean

Returns true if the range is collapsed

final int
final int

Returns the length of the range.

final int

The maximum offset of the range.

final int

The minimum offset of the range.

final boolean

Returns true if the start offset is larger than the end offset.

final int
final boolean

Returns true if the given range has intersection with this range

@NonNull String

Extension functions

final @NonNull TextRange
TextRangeKt.coerceIn(
    @NonNull TextRange receiver,
    int minimumValue,
    int maximumValue
)

Ensures that TextRange.start and TextRange.end values lies in the specified range minimumValue and maximumValue.

Public methods

contains

public final boolean contains(int offset)

Returns true if the given offset is a part of this range.

contains

public final boolean contains(@NonNull TextRange other)

Returns true if this range covers including equals with the given range.

getCollapsed

public final boolean getCollapsed()

Returns true if the range is collapsed

getEnd

public final int getEnd()

getLength

public final int getLength()

Returns the length of the range.

getMax

public final int getMax()

The maximum offset of the range.

getMin

public final int getMin()

The minimum offset of the range.

getReversed

public final boolean getReversed()

Returns true if the start offset is larger than the end offset.

getStart

public final int getStart()

intersects

public final boolean intersects(@NonNull TextRange other)

Returns true if the given range has intersection with this range

toString

public @NonNull String toString()

Extension functions

TextRangeKt.coerceIn

public final @NonNull TextRange TextRangeKt.coerceIn(
    @NonNull TextRange receiver,
    int minimumValue,
    int maximumValue
)

Ensures that TextRange.start and TextRange.end values lies in the specified range minimumValue and maximumValue. For each TextRange.start and TextRange.end values:

Parameters
int minimumValue

the minimum value that TextRange.start or TextRange.end can be.

int maximumValue

the exclusive maximum value that TextRange.start or TextRange.end can be.