Class Slice16

  • All Implemented Interfaces:
    java.lang.Comparable<UnicodeString>, AtomicMatchKey

    public class Slice16
    extends UnicodeString
    A Unicode string consisting entirely of 16-bit BMP characters, implemented as a range of an underlying byte array
    • Constructor Detail

      • Slice16

        public Slice16​(char[] chars,
                       int start,
                       int end)
        Create a slice of an underlying char array
        Parameters:
        chars - the char array, containing Unicode codepoints in the range 0-65535; the caller warrants that there are no surrogate characters present
        start - the offset of the first character within the character array
        end - the offset of the first excluded character, so the length of the string is end-start
    • Method Detail

      • length

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

        public int getWidth()
        Description copied from class: UnicodeString
        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 (not used??), 8 for latin-1, 16 for BMP, 24 for general Unicode.
      • getCharArray

        public char[] getCharArray()
      • getStart

        public int getStart()
      • getEnd

        public int getEnd()
      • indexOf

        public long indexOf​(int codePoint,
                            long from)
        Description copied from class: UnicodeString
        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)
        Returns:
        the position (0-based) of the first occurrence found, or -1 if not found
      • codePointAt

        public int codePointAt​(long index)
        Description copied from class: UnicodeString
        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
      • substring

        public UnicodeString substring​(long start,
                                       long end)
        Description copied from class: UnicodeString
        Get a substring of this string, 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
      • indexWhere

        public long indexWhere​(java.util.function.IntPredicate predicate,
                               long from)
        Get the position of the first occurrence of the specified codepoint, starting the search at a given position in the string
        Overrides:
        indexWhere in class UnicodeString
        Parameters:
        predicate - condition that the codepoint must satisfy
        from - the position from which the search should start (0-based)
        Returns:
        the position (0-based) of the first codepoint to match the predicate, or -1 if not found
        Throws:
        java.lang.UnsupportedOperationException - if the UnicodeString has not been prepared for codePoint access
      • codePoints

        public IntIterator codePoints()
        Description copied from class: UnicodeString
        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
      • hashCode

        public int hashCode()
        Compute a hashCode. All implementations of UnicodeString use compatible hash codes and the hashing algorithm is therefore identical to that for java.lang.String. This means that for strings containing Astral characters, the hash code needs to be computed by decomposing an Astral character into a surrogate pair.
        Overrides:
        hashCode in class UnicodeString
        Returns:
        the hash code
      • toString

        public java.lang.String toString()
        Convert to a string.
        Overrides:
        toString in class java.lang.Object