@Immutable public final class CharSequenceInputBuffer extends Object implements InputBuffer
InputBuffer
over a CharSequence
A CharSequence
is the most basic character interface in the JDK.
It is implemented by a lot of character related classes, including String
, and is also the argument type used by a Pattern
's Matcher
.
Among other things, this means you can use this package on very large
files using largetext, which
implements CharSequence
over multi-gigabyte files.
Constructor and Description |
---|
CharSequenceInputBuffer(CharSequence charSequence) |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index)
Returns the character at the given index.
|
int |
codePointAt(int index)
Returns the Unicode code point starting at a given index
|
String |
extract(IndexRange range)
Constructs a new
String from all character covered by the given
IndexRange. |
String |
extract(int start,
int end)
Constructs a new
String from all character between the given
indices. |
String |
extractLine(int lineNumber)
Constructs a new
String containing all characters with the given
line number except for the trailing newline. |
int |
getLineCount()
Returns the number of lines in the input buffer.
|
IndexRange |
getLineRange(int lineNumber)
Get the index range matching a given line number
|
Position |
getPosition(int index)
Returns the line and column number of the character with the given index
encapsulated in a
Position object. |
int |
length() |
public CharSequenceInputBuffer(@Nonnull CharSequence charSequence)
public char charAt(int index)
InputBuffer
If the index is greater than, or equal to, the buffer's length, this
method returns Chars.EOI
.
charAt
in interface InputBuffer
index
- the indexpublic int codePointAt(int index)
InputBuffer
If the index is greater than, or equal to, the buffer's length, this method returns -1.
codePointAt
in interface InputBuffer
index
- the indexpublic String extract(int start, int end)
InputBuffer
String
from all character between the given
indices. Invalid indices are automatically adjusted to their respective
boundary.extract
in interface InputBuffer
start
- the start index (inclusively)end
- the end index (exclusively)public String extract(IndexRange range)
InputBuffer
String
from all character covered by the given
IndexRange.extract
in interface InputBuffer
range
- the IndexRangepublic Position getPosition(int index)
InputBuffer
Position
object. The very first character has
the line number 1 and the column number 1.getPosition
in interface InputBuffer
index
- the index of the character to get the line number ofpublic String extractLine(int lineNumber)
InputBuffer
String
containing all characters with the given
line number except for the trailing newline.extractLine
in interface InputBuffer
lineNumber
- the line number to getpublic IndexRange getLineRange(int lineNumber)
InputBuffer
getLineRange
in interface InputBuffer
lineNumber
- the line numberpublic int getLineCount()
InputBuffer
getLineCount
in interface InputBuffer
public int length()
length
in interface InputBuffer