Class IndentWhitespace

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

    public class IndentWhitespace
    extends WhitespaceString
    This class provides a compressed representation of a string used to represent indentation: specifically, an integer number of newlines followed by an integer number of spaces. It's a little cheaper than the CompressedWhitespace class, and is specifically used for constructing indentation and passing it to a UTF8Writer, which recognizes it specially. Unlike CompressedWhitespace, it can't handle arbitrary whitespace strings, only those consisting of newlines followed by spaces.
    • Method Detail

      • of

        public static IndentWhitespace of​(int newlines,
                                          int spaces)
        Create an IndentWhitespace object
        Parameters:
        newlines - the number of newlines at the start
        spaces - the number of spaces following the newlines
        Returns:
        the constructed (or potentially cached) IndentWhitespace object
      • 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
      • length32

        public int length32()
        Description copied from class: UnicodeString
        Get the length of the string, provided it is less than 2^31 characters
        Overrides:
        length32 in class UnicodeString
        Returns:
        the length of the string if it fits within a Java int
      • getNewlines

        public int getNewlines()
        Get the number of newlines at the start
        Returns:
        the number of newline characters
      • getSpaces

        public int getSpaces()
        Get the number of spaces following the newlines
        Returns:
        the number of space characters
      • codePointAt

        public int codePointAt​(long index)
        Returns the codepoint value at the specified index. An index ranges from zero to length() - 1. The first codepoint value of the sequence is at index zero, the next at index one, and so on, as for array indexing.
        Specified by:
        codePointAt in class UnicodeString
        Parameters:
        index - the index of the codepoint value to be returned
        Returns:
        the specified codepoint value
        Throws:
        java.lang.IndexOutOfBoundsException - if the index argument is negative or not less than length()
      • 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
      • toString

        public java.lang.String toString()
        Returns a string representation of the object.
        Overrides:
        toString in class WhitespaceString
      • write

        public void write​(UnicodeWriter writer)
                   throws java.io.IOException
        Write the value to a UnicodeWriter
        Specified by:
        write in class WhitespaceString
        Parameters:
        writer - the writer to write to
        Throws:
        java.io.IOException - if an error occurs downstream
      • writeEscape

        public void writeEscape​(boolean[] specialChars,
                                UnicodeWriter writer)
                         throws java.io.IOException
        Write the value to a Writer with escaping of special characters
        Specified by:
        writeEscape in class WhitespaceString
        Parameters:
        specialChars - identifies which characters are considered special
        writer - the writer to write to
        Throws:
        java.io.IOException - if an error occurs downstream