public final class FastStringBuffer extends java.lang.Object implements AppendableCharSequence
Modifier and Type | Field and Description |
---|---|
static int |
C1024 |
static int |
C16 |
static int |
C256 |
static int |
C64 |
Constructor and Description |
---|
FastStringBuffer(java.lang.CharSequence cs)
Create a FastStringBuffer with initial content
|
FastStringBuffer(int initialSize)
Create a FastStringBuffer with a given initial capacity
|
Modifier and Type | Method and Description |
---|---|
void |
append(char ch)
Append a character to the buffer
|
void |
append(char[] srcArray)
Append the entire contents of a character array to the buffer
|
void |
append(char[] srcArray,
int start,
int length)
Append the contents of a character array to the buffer
|
void |
append(java.lang.CharSequence s)
Append the contents of a general CharSequence to the buffer
|
void |
append(CharSlice s)
Append the contents of a CharSlice to the buffer
|
void |
append(FastStringBuffer s)
Append the contents of a FastStringBuffer to the buffer
|
void |
append(java.lang.String s)
Append the contents of a String to the buffer
|
void |
append(java.lang.StringBuffer s)
Append the contents of a StringBuffer to the buffer
|
void |
append(UnicodeString str)
Append a UnicodeString to the buffer (using surrogate pairs if necessary)
|
void |
appendWideChar(int ch)
Append a wide character to the buffer (as a surrogate pair if necessary)
|
char |
charAt(int index)
Returns the
char value at the specified index. |
FastStringBuffer |
condense()
Remove surplus space from the array.
|
static java.lang.String |
diagnosticPrint(java.lang.CharSequence in)
Diagnostic print of the contents of a CharSequence.
|
void |
ensureCapacity(int extra)
Expand the character array if necessary to ensure capacity for appended data
|
boolean |
equals(java.lang.Object other)
Compare equality
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies characters from this FastStringBuffer into the destination character
array.
|
int |
hashCode()
Generate a hash code
|
int |
indexOf(char ch)
Get the index of the first character equal to a given value
|
void |
insert(int index,
char ch)
Insert a character at a particular offset
|
void |
insertWideChar(int index,
int ch)
Insert wide character at a particular offset
|
boolean |
isEmpty()
Ask whether the string buffer is empty
|
int |
length()
Returns the length of this character sequence.
|
void |
prepend(char ch)
Insert a given character at the start of the buffer
|
void |
prepend(java.lang.CharSequence str)
Insert a given string at the start of the buffer
|
void |
prependRepeated(char ch,
int repeat)
Insert a given character N times at the start of the buffer
|
void |
prependWideChar(int ch)
Prepend a wide character to the buffer (as a surrogate pair if necessary)
|
void |
removeCharAt(int index)
Remove a character at a particular offset
|
void |
setCharAt(int index,
char ch)
Set the character at a particular offset
|
void |
setLength(int length)
Set the length.
|
java.lang.CharSequence |
subSequence(int start,
int end)
Returns a new
CharSequence that is a subsequence of this sequence. |
char[] |
toCharArray()
Get a char[] array containing the characters.
|
java.lang.String |
toString()
Convert contents of the FastStringBuffer to a string
|
void |
write(java.io.Writer writer)
Write the value to a writer
|
public static final int C16
public static final int C64
public static final int C256
public static final int C1024
public FastStringBuffer(int initialSize)
initialSize
- the initial capacitypublic FastStringBuffer(java.lang.CharSequence cs)
cs
- the initial content. The buffer is created with just enough capacity for
this content (it will be expanded if more content is added later).public void append(java.lang.String s)
s
- the String to be appendedpublic void append(CharSlice s)
s
- the String to be appendedpublic void append(FastStringBuffer s)
s
- the FastStringBuffer to be appendedpublic void append(java.lang.StringBuffer s)
s
- the StringBuffer to be appendedpublic void append(java.lang.CharSequence s)
append
in interface AppendableCharSequence
s
- the CharSequence to be appendedpublic void append(char[] srcArray, int start, int length)
srcArray
- the array whose contents are to be addedstart
- the offset of the first character in the array to be copiedlength
- the number of characters to be copiedpublic void append(char[] srcArray)
srcArray
- the array whose contents are to be addedpublic void append(char ch)
ch
- the character to be addedpublic void appendWideChar(int ch)
ch
- the character, as a 32-bit Unicode codepointpublic void append(UnicodeString str)
str
- the UnicodeStringpublic void prependWideChar(int ch)
ch
- the character, as a 32-bit Unicode codepointpublic int length()
char
s in the sequence.length
in interface java.lang.CharSequence
char
s in this sequencepublic boolean isEmpty()
public char charAt(int index)
char
value at the specified index. An index ranges from zero
to length() - 1. The first char
value of the sequence is at
index zero, the next at index one, and so on, as for array
indexing.
If the char
value specified by the index is a
surrogate, the surrogate
value is returned.
charAt
in interface java.lang.CharSequence
index
- the index of the char
value to be returnedchar
valuejava.lang.IndexOutOfBoundsException
- if the index argument is negative or not less than
length()public java.lang.CharSequence subSequence(int start, int end)
CharSequence
that is a subsequence of this sequence.
The subsequence starts with the char
value at the specified index and
ends with the char
value at index end - 1. The length
(in char
s) of the
returned sequence is end - start, so if start == end
then an empty sequence is returned.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 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
The first character to be copied is at index srcBegin
;
the last character to be copied is at index srcEnd-1
(thus the total number of characters to be copied is
srcEnd-srcBegin
). The characters are copied into the
subarray of dst
starting at index dstBegin
and ending at index:
dstbegin + (srcEnd-srcBegin) - 1
srcBegin
- index of the first character in the string
to copy.srcEnd
- index after the last character in the string
to copy.dst
- the destination array.dstBegin
- the start offset in the destination array.java.lang.IndexOutOfBoundsException
- If any of the following
is true:
srcBegin
is negative.
srcBegin
is greater than srcEnd
srcEnd
is greater than the length of this
string
dstBegin
is negative
dstBegin+(srcEnd-srcBegin)
is larger than
dst.length
public int indexOf(char ch)
ch
- the character to search forpublic 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 char[] toCharArray()
public void setCharAt(int index, char ch)
index
- the index of the character to be setch
- the new character to overwrite the existing character at that locationjava.lang.IndexOutOfBoundsException
- if int<0 or int>=length()public void insert(int index, char ch)
index
- the index of the character to be setch
- the new character to insert at that locationjava.lang.IndexOutOfBoundsException
- if int<0 or int>=length()public void insertWideChar(int index, int ch)
index
- the index of the character to be setch
- the character, as a 32-bit Unicode codepointjava.lang.IndexOutOfBoundsException
- if int<0 or int>=length()public void removeCharAt(int index)
index
- the index of the character to be setjava.lang.IndexOutOfBoundsException
- if int<0 or int>=length()public void prepend(char ch)
ch
- the character to insertpublic void prepend(java.lang.CharSequence str)
str
- the string to insertpublic void prependRepeated(char ch, int repeat)
ch
- the character to insertrepeat
- the number of occurrences required. Supplying 0 or a negative number is OK,
and is treated as a no-op.public void setLength(int length)
setLength
in interface AppendableCharSequence
length
- the new lengthpublic void ensureCapacity(int extra)
extra
- the amount of additional capacity needed, in characterspublic FastStringBuffer condense()
public void write(java.io.Writer writer) throws java.io.IOException
writer
- the writer to which the content is to be writtenjava.io.IOException
public static java.lang.String diagnosticPrint(java.lang.CharSequence in)
in
- the CharSequence whose contents are to be displayed.Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.