Class LargeTextBuffer

java.lang.Object
net.sf.saxon.str.LargeTextBuffer

public final class LargeTextBuffer extends Object
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 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

      public void appendUnicodeString(UnicodeString chars)
      Append a string to the contents of the LargeTextBuffer
      Parameters:
      chars - the string to be added
    • substring

      public UnicodeString substring(int start, int end)
      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 index end - 1. The length of the returned sequence is end - start, so if start == 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 - if start or end are negative, if end is greater than length(), or if start is greater than end
    • 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