Package net.sf.saxon.str
Class LargeTextBuffer
java.lang.Object
net.sf.saxon.str.LargeTextBuffer
The segments (other than the last) have a fixed size of 65536 codepoints,
which may use one byte per codepoint, two bytes per codepoint, or three bytes per
codepoint, depending on the largest codepoint present in the segment.
This is more efficient than a buffer backed by a contiguous array of characters in cases where the size is likely to grow very large, and where substring operations are rare. As used within the TinyTree, extraction of the string value of a node requires character copying only in the case where the value crosses segment boundaries.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendUnicodeString
(UnicodeString chars) Append a string to the contents of the LargeTextBuffervoid
close()
int
length()
Get the number of characters in the LargeTextBuffervoid
setLength
(int newLength) Set the length.substring
(int start, int end) Returns a new character sequence that is a subsequence of this sequence.
-
Constructor Details
-
LargeTextBuffer
public LargeTextBuffer(int initialSize) Create an empty LargeTextBuffer- Parameters:
initialSize
- an estimate of the number of characters needed in the first segment
-
-
Method Details
-
appendUnicodeString
Append a string to the contents of the LargeTextBuffer- Parameters:
chars
- the string to be added
-
substring
Returns a new character sequence that is a subsequence of this sequence. The subsequence starts with the character at the specified index and ends with the character at indexend - 1
. The length of the returned sequence isend - start
, so ifstart == end
then an empty sequence is returned.- Parameters:
start
- the start index, inclusive (codepoints, not bytes)end
- the end index, exclusive (codepoints, not bytes)- Returns:
- the specified subsequence
- Throws:
IndexOutOfBoundsException
- ifstart
orend
are negative, ifend
is greater thanlength()
, or ifstart
is greater thanend
-
close
public void close() -
length
public int length()Get the number of characters in the LargeTextBuffer- Returns:
- the number of characters present
-
setLength
public void setLength(int newLength) Set the length. If this exceeds the current length, this method is a no-op. If this is less than the current length, characters beyond the specified point are deleted.- Parameters:
newLength
- the new length
-