public final class CharSlice
extends java.lang.Object
implements java.lang.CharSequence
Constructor and Description |
---|
CharSlice(char[] array)
Create a CharSlice that maps to the whole of a char[] array
|
CharSlice(char[] array,
int start,
int length)
Create a CharSlice that maps to a section of a char[] array
|
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index)
Returns the character at the specified index.
|
void |
copyTo(char[] destination,
int destOffset)
Append the contents to another array at a given offset.
|
boolean |
equals(java.lang.Object other)
Compare equality
|
void |
getChars(int start,
int end,
char[] destination,
int destOffset)
Append the contents to another array at a given offset.
|
int |
hashCode()
Generate a hash code
|
int |
indexOf(char c)
Get the index of a specific character in the sequence.
|
int |
length()
Returns the length of this character sequence.
|
void |
setLength(int length)
Set the length of this character sequence, without changing the array and start offset
to which it is bound
|
java.lang.CharSequence |
subSequence(int start,
int end)
Returns a new character sequence that is a subsequence of this sequence.
|
java.lang.String |
substring(int start,
int end)
Returns a new character sequence that is a subsequence of this sequence.
|
char[] |
toCharArray() |
static char[] |
toCharArray(java.lang.CharSequence in)
Utility method to turn a CharSequence into an array of chars
|
java.lang.String |
toString()
Convert to a string
|
void |
write(java.io.Writer writer)
Write the value to a writer
|
public CharSlice(char[] array)
array
- the char[] arraypublic CharSlice(char[] array, int start, int length)
array
- the char[] arraystart
- position of the first character to be includedlength
- number of characters to be includedpublic int length()
length
in interface java.lang.CharSequence
public void setLength(int length)
length
- the new length of the CharSlice (which must be less than the existing length,
though this is not enforced)public char charAt(int index)
charAt
in interface java.lang.CharSequence
index
- the index of the character to be returnedjava.lang.IndexOutOfBoundsException
- if the index argument is negative or not less than
length()public java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
start
- the start index, inclusiveend
- the end index, exclusivejava.lang.IndexOutOfBoundsException
- if start or end are negative,
if end is greater than length(),
or if start is greater than endpublic java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int indexOf(char c)
String.indexOf(int)
c
- the character to be foundpublic java.lang.String substring(int start, int end)
start
- position of the first character to be included (relative to the
start of the CharSlice, not the underlying array)end
- position of the first character not to be included (relative
to the start of the CharSlice)public void copyTo(char[] destination, int destOffset)
destination
- the array to which the characters will be copieddestOffset
- the offset in the target array where the copy will startpublic void getChars(int start, int end, char[] destination, int destOffset)
start
- offset of first character to be copiedend
- offset of the first character that is not copieddestination
- the array to which the characters will be copieddestOffset
- the offset in the target array where the copy will startpublic char[] toCharArray()
public static char[] toCharArray(java.lang.CharSequence in)
in
- the CharSequencepublic void write(java.io.Writer writer) throws java.io.IOException
writer
- the writer to be written tojava.io.IOException
- if writing failsCopyright (c) 2004-2018 Saxonica Limited. All rights reserved.