Class SegmentedString

java.lang.Object
net.sf.saxon.str.UnicodeString
net.sf.saxon.str.SegmentedString
All Implemented Interfaces:
Comparable<UnicodeString>, AtomicMatchKey

public class SegmentedString extends UnicodeString
A SegmentedString is an implementation of UnicodeString that comprises an array of segments representing substrings of the total string; all segments except the last have the same length in codepoints, so indexing is straightforward. Unlike the ZenoString, this structure is not designed for efficient modification.
  • Field Details

  • Constructor Details

    • SegmentedString

      public SegmentedString()
      Private constructor creating an empty SegmentedString (containing an empty list of segments)
    • SegmentedString

      public SegmentedString(IntIterator codepoints)
      Constructor creating a SegmentedString from a codepoint iterator
    • SegmentedString

      protected SegmentedString(UnicodeString[] segmentArray)
      Internal constructor for use by UnicodeBuilder
      Parameters:
      segmentArray - the array of segments. The method assumes that the segment length is correct.
  • Method Details

    • of

      public static SegmentedString of(UnicodeString content)
      Construct a SegmentedString from a supplied UnicodeString
      Parameters:
      content - the supplied UnicodeString
      Returns:
      the resulting ZenoString
    • codePoints

      public IntIterator codePoints()
      Get an iterator over the code points present in the string.
      Specified by:
      codePoints in class UnicodeString
      Returns:
      an iterator that delivers the individual code points
    • length

      public long length()
      Get the length of the string
      Specified by:
      length in class UnicodeString
      Returns:
      the number of code points in the string
    • isEmpty

      public boolean isEmpty()
      Ask whether the string is empty
      Overrides:
      isEmpty in class UnicodeString
      Returns:
      true if the length of the string is zero
    • getWidth

      public int getWidth()
      Get the number of bits needed to hold all the characters in this string
      Specified by:
      getWidth in class UnicodeString
      Returns:
      7 for ascii characters, 8 for latin-1, 16 for BMP, 24 for general Unicode.
    • indexOf

      public long indexOf(int codePoint, long from)
      Get the position of the first occurrence of the specified codepoint, starting the search at a given position in the string
      Specified by:
      indexOf in class UnicodeString
      Parameters:
      codePoint - the sought codePoint
      from - the position from which the search should start (0-based). A negative value is treated as zero. A position beyond the end of the string results in a return value of -1 (meaning not found).
      Returns:
      the position (0-based) of the first occurrence found, or -1 if not found
      Throws:
      IndexOutOfBoundsException - if the from value is out of range
    • indexWhere

      public long indexWhere(IntPredicate predicate, long from)
      Description copied from class: UnicodeString
      Get the position of the first occurrence of a codepoint that matches a supplied predicate, starting the search at a given position in the string
      Specified by:
      indexWhere in class UnicodeString
      Parameters:
      predicate - condition that the codepoint must satisfy
      from - the position from which the search should start (0-based). A negative value is treated as zero. A position beyond the end of the string results in a return value of -1 (meaning not found).
      Returns:
      the position (0-based) of the first codepoint to match the predicate, or -1 if not found
    • codePointAt

      public int codePointAt(long index)
      Get the code point at a given position in the string
      Specified by:
      codePointAt in class UnicodeString
      Parameters:
      index - the given position (0-based)
      Returns:
      the code point at the given position
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • substring

      public UnicodeString substring(long start, long end)
      Get a substring of this codepoint sequence, with a given start and end position
      Specified by:
      substring in class UnicodeString
      Parameters:
      start - the start position (0-based): that is, the position of the first code point to be included
      end - the end position (0-based): specifically, the position of the first code point not to be included
      Returns:
      the requested substring
    • concat

      public UnicodeString concat(UnicodeString other)
      Concatenate another string
      Overrides:
      concat in class UnicodeString
      Parameters:
      other - the string to be appended to this one
      Returns:
      the result of the concatenation (neither input string is altered)
    • writeSegments

      public void writeSegments(UnicodeWriter writer) throws IOException
      Write each of the segments in turn to a UnicodeWriter
      Parameters:
      writer - the writer to which the string is to be written
      Throws:
      IOException
    • concatSegments

      public static UnicodeString concatSegments(UnicodeString left, UnicodeString right)
    • economize

      public UnicodeString economize()
      Get an equivalent UnicodeString that uses the most economical representation available
      Overrides:
      economize in class UnicodeString
      Returns:
      an equivalent UnicodeString
    • toString

      public String toString()
      Overrides:
      toString in class Object